Archived

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

Quaternion

This topic is 5646 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 ];
ViewDir[2]=matrix[10];

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

__forceinline void OBSERVER::Right( float speedx )
{
////////////////////////////////////////////////
// translate x
Pos[0]+=matrix[0]*speedx;
Pos[1]+=matrix[4]*speedx;
Pos[2]+=matrix[8]*speedx;
}

__forceinline void OBSERVER::Up( float speedy )
{
////////////////////////////////////////
// translate y
Pos[0]+=matrix[1]*speedy;
Pos[1]+=matrix[5]*speedy;
Pos[2]+=matrix[9]*speedy;
}

__forceinline void OBSERVER::Forward( float speedz )
{
///////////////////////////////////////
// translate z
Pos[0]+=matrix[2]*speedz;
Pos[1]+=matrix[6]*speedz;
Pos[2]+=matrix[10]*speedz;
}

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

byez



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.LoadIdentity();
view.Translate(worldPosition);
view = worldView * worldRotation.getMatrix();
glLoadIdentity();
glMultMatrixf(view.m); // view.m is a float[16]

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

drawObject();
glPopMatrix();


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