Rotating the UpVector - Custom free roaming camera

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
NovaCoder
Posts: 28
Joined: Wed May 26, 2004 11:36 am
Contact:

Rotating the UpVector - Custom free roaming camera

Post by NovaCoder »

I'm still having 'issues' with my custom camera class. So far I've found out that all you need to rotate your camera's view (no translation yet) is to rotate your target point around the camera's origin.

Code: Select all

 core::vector3df CameraPos; 
 CameraPos = this->getAbsolutePosition(); 

 nRotX = (MousePos.X) * -1.0f; 
 nRotY = (MousePos.Y) * -1.0f; 


 // Rotates around Y 
 Target.rotateYZBy(-nRotY, CameraPos);    

 // Rotates around X 
 Target.rotateXZBy(nRotX, CameraPos); 
So this code seems to work ok apart from when you rotate past the camera's straight up position, this is because I also need to rotate the Camera's UpVector. I tried something like following code but it's introducing 'roll'.

Code: Select all

UpVector.rotateYZBy(-nRotY, core::vector3df(0,0,0)); 
UpVector.rotateXZBy(nRotX,, core::vector3df(0,0,0)); 
UpVector.normalize();


Does anyone know how to correctly rotate the UpVector for my implementation?

This code is in the Maya sceneNode class but looks kinda nasty:

Code: Select all

if (nRotY >= 90.0f && nRotY <= 270.0f)
  UpVector.set(0, -1, 0);
else
 UpVector.set(0, 1, 0);
I had a look on the Net and found something that said I should generate a new 'Left' point using the crossproduct of the Target and the current Up and then rotate the Up around it...is that correct?


Also I've notice that with my code my target (target object added using 'addTestSceneNode' without a rotation value specified) not only rotates around the camera's origin but also rotates around its own Axis, is this just an Engine bug or am I doing something silly?

ThanX
- Nova
Post Reply