Archived

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

yet another quaternion question

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

Recommended Posts

I have struggled with quaternions for quiet som time now, using quaternions for rotating my "camera". My problem is that after some time the camera goes faster and faster. Can you point out where my fail is?
   vector mult(vector A, vector B)
{
vector C;

C.x = A.w*B.x + A.x*B.w + A.y*B.z - A.z*B.y;
C.y = A.w*B.y - A.x*B.z + A.y*B.w + A.z*B.x;
C.z = A.w*B.z + A.x*B.y - A.y*B.x + A.z*B.w;
C.w = A.w*B.w - A.x*B.x - A.y*B.y - A.z*B.z;
return C;
}

vector conjugate(vector A){

A.x = -A.x;
A.y = -A.y;
A.z = -A.z;

return A;
}

glMatrixMode( GL_MODELVIEW );     // Select modelview matrix

gluLookAt(                        // Set camera position and orientation

position.x, position.y, position.z,               // Camera position (x,y,z)

view.x, view.y, view.z,                // View point (x,y,z)

0.0, 1.0, 0.0                 // Up-vector (x,y,z)

);

if(glfwGetKey( 'W' )){
summa.z = view.z - position.z;
summa.x = view.x - position.x;

position.z += summa.z * velo;
position.x += summa.x * velo;

view.z += summa.z * velo;
view.x += summa.x * velo;
}
if(glfwGetKey( 'S' )){
summa.z = view.z - position.z;
summa.x = view.x - position.x;

position.z -= summa.z * velo;
position.x -= summa.x * velo;

view.z -= summa.z * velo;
view.x -= summa.x * velo;
}

if(glfwGetKey( 'D' )){
rotate.x = 0.0 * sin(-angle/2);
rotate.y = 1.0 * sin(-angle/2);
rotate.z = 0.0 * sin(-angle/2);
rotate.w = cos(-angle/2);

view.w = 0;
view = mult(mult(rotate, view), conjugate(rotate));
}
if(glfwGetKey( 'A' )){
rotate.x = 0.0 * sin(angle/2);
rotate.y = 1.0 * sin(angle/2);
rotate.z = 0.0 * sin(angle/2);
rotate.w = cos(angle/2);

view.w = 0;
view = mult(mult(rotate, view), conjugate(rotate));
}

And another question which for me is more important then the first is if this equation just transforms quaternions to axis/angle rotations or has it a deeper meaning? rotate.x = x * sin(angle/2); rotate.y = y * sin(angle/2); rotate.z = z * sin(angle/2); rotate.w = cos(angle/2); [edited by - 1mol on March 26, 2004 2:41:03 PM]

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 9
• 9
• 14
• Forum Statistics

• Total Topics
633314
• Total Posts
3011325
• Who's Online (See full list)

There are no registered users currently online

×