Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 6016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to move a camera with a quaternion. Ive got the rotations down fine, 6DOF, looks great. My only problem is that I cant figure out how to move the camera based on the direction vector. It seems to move fine if I dont rotate the camera, it will move back and forth but when i rotate while moving it all goes to hell. here is some sudo code
Vector3 position;
Quaternion rotation;
Vector3 directionVector = getQuaternionDirectionVector(rotation);
position.x += directionVector.x * timeDelta * speed;
position.y += directionVector.y * timeDelta * speed;
position.z += directionVector.z * timeDelta * speed;
anyone know what Im doing wrong?

Share this post

Link to post
Share on other sites
first this is how i extrect the vied vector from the quaternion matrix

ViewDir[0]=matrix[2 ];
ViewDir[1]=matrix[6 ];

this will give you the idea of the row / column orientation ( i hope )

__forceinline void OBSERVER::Right( float speedx )
// translate x

__forceinline void OBSERVER::Up( float speedy )
// translate y

__forceinline void OBSERVER::Forward( float speedz )
// translate z

if you want to reverse the direction just give a negative value to the speed factor.


Share this post

Link to post
Share on other sites
I think the problem has to do with the way im rotating/translating the world. The objects seem to handle the rotating/translating just fine. But if I move the camera''s rotation but not the position it looks fine. Currently I have a CCamera which holds a Vector for the position and a Quaternion for the rotation. My world view is a CCamera and all the things I draw have CCamera''s.

So lets say I have a camera and 1 object. And I want the to see the view from inside the object.

Quaternion objectRotation;
Vector3 objectPosition;
Quaternion worldRotation= objectRotation;
Vector3 worldPosition = -objectPosition;
Matrix4 view;
view = worldView * worldRotation.getMatrix();
glMultMatrixf(view.m); // view.m is a float[16]

view = objectView * objectRotation.getMatrix();
glMultMatrixf(view.m); // view.m is a float[16]


Would this be correct?

Share this post

Link to post
Share on other sites
I didn''t understand your last post, but is it possible that you need the inverse rotation quaternion? Something like:
Vector3 directionVector = getQuaternionDirectionVector(getQuaternionInverse(rotation));
Inverting a quaternion is not that hard... if you don''t know, just search in google. I would give it a try, as you often store the inverse rotation in your camera quaternion (rotate head right == rotate world left).
Or do I mix up things here?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!