Rotation and translation in 3D instead of 2D
Hi,
I know that I can achive 2D Space movement with:
x_tra = x_tra - (value * ((float) sin(y_rot*(Pi/180))));
z_tra = z_tra + (value * ((float) cos(y_rot*(Pi/180))));
but what about 3D?
In my 3D (OpenGL) engine i can rotate X and Y Axis. Z Rotate will not be alowed for now.
PS: i need this for a spacesim like game.
Do i have to make what I want with Quaternions? I it able to make it with "normal" glRotate glTranslate?
This group is my last hope - I have not found anything useful on google and friends.
thanks
[edited by - Dominik_78 on November 16, 2002 7:36:16 PM]
Your best bet for doing full 3D rotations is using quaternions. You could use matrices with euler angles, but the nastyness that is gimbal lock will rear its head. Euler angles are much easier to understand on the other hand, quaternions are just a little bit abstract, and you have to watch out for things. These include quaternions representing orientations needing to be distinguished from ones representing relative rotations. A good doc to read can be found on David Eberly''s site under the documentation section:
Magic Software , the one on ''Quaternion Algebra and Calculus''. Depends what your happy with, although once you''ve encountered the problems with matrices quaternions are the way to go.
Magic Software , the one on ''Quaternion Algebra and Calculus''. Depends what your happy with, although once you''ve encountered the problems with matrices quaternions are the way to go.
Can quaternions help me with finding the new 3D point where the camera "stands"? this is the biggest question. I do have a quaternions tutorial and i am sure i am able to find out so much about it that i can implement it.
But the main question is about translation in 3D Space depending on 2 Axis (y- and x-axis) and not only one axis (y-axis) as i shown in the example i know how to tanslate the camera ich i press forward button depending on the Y-Axis but what if i add a x axis for lets say "flying" up with the camera. hot to change the y_tra (y-translation) value depending on which angle?
ps: can you explaine gimbal lock to me. always heard that but never seen any example.
thanks
But the main question is about translation in 3D Space depending on 2 Axis (y- and x-axis) and not only one axis (y-axis) as i shown in the example i know how to tanslate the camera ich i press forward button depending on the Y-Axis but what if i add a x axis for lets say "flying" up with the camera. hot to change the y_tra (y-translation) value depending on which angle?
ps: can you explaine gimbal lock to me. always heard that but never seen any example.
thanks
Gimbal lock refers to, as the result of a previous rotation, u lose one degree of freedom.
Example, say you rotated around the x axis by pi/2. Now if u wanted to rotate around the y axis by some angle, you would actually end up rotating around the z axis. The previous rotation around the x axis has effectively "replaced" the y axis with the z axis.
Example, say you rotated around the x axis by pi/2. Now if u wanted to rotate around the y axis by some angle, you would actually end up rotating around the z axis. The previous rotation around the x axis has effectively "replaced" the y axis with the z axis.
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
Thanks MelvinElvin. that was what i expected gimbal lock to be. I do not have to deal with that right now. I got a rotation that is not afected by gimbal lock.
So know I anyhow need to know how to move a camera along the view vector in 3D.
my first app was a "walkengine" and:
worked just fine to do my move along the camera vector.
now that i am able to rotate the x-axis too i need a more complex calculation that affects the x,y and z posotion of my camera acording to the viewangle of my camera.
thanks
[edited by - Dominik_78 on November 17, 2002 7:22:29 AM]
So know I anyhow need to know how to move a camera along the view vector in 3D.
my first app was a "walkengine" and:
x_tra = x_tra - (value * ((float) sin(y_rot*(Pi/180))));z_tra = z_tra + (value * ((float) cos(y_rot*(Pi/180))));
worked just fine to do my move along the camera vector.
now that i am able to rotate the x-axis too i need a more complex calculation that affects the x,y and z posotion of my camera acording to the viewangle of my camera.
thanks
[edited by - Dominik_78 on November 17, 2002 7:22:29 AM]
If you use a quaternion to store the current orientation of your camera, you can then convert this to a matrix. The matrix will be an ortho-normal basis, e.g. it is constructed from 3 vectors that are perpendicular to each other (depending on the handedness of your matrices they will either be vertcial or horizontal).
So you will have a matrix such like this:
[ X1 X2 X3 ]
[ Y1 Y2 Y3 ]
[ Z1 Z2 Z3 ]
where each of the x, y & z vectors are the right, up and forward direction for the camera. Adding multiples of these vectors to your camera position will allow you to move in 3D based on the orientation of the camera.
So you will have a matrix such like this:
[ X1 X2 X3 ]
[ Y1 Y2 Y3 ]
[ Z1 Z2 Z3 ]
where each of the x, y & z vectors are the right, up and forward direction for the camera. Adding multiples of these vectors to your camera position will allow you to move in 3D based on the orientation of the camera.
quote:
So you will have a matrix such like this:
[ X1 X2 X3 ]
[ Y1 Y2 Y3 ]
[ Z1 Z2 Z3 ]
where each of the x, y & z vectors are the right, up and forward direction for the camera. Adding multiples of these vectors to your camera position will allow you to move in 3D based on the orientation of the camera.
if I do this I get nearly the result I desire. But istead of moving forward I move down from my camera position.
float m[16];CSSMatrix tmpMatrix;cameraQuat.GetMatrix(tmpMatrix);tmpMatrix.GetValues(m);x_tra = x_tra + (value * m[0]) + (value * m[1]) + (value * m[2]);y_tra = y_tra + (value * m[4]) + (value * m[5]) + (value * m[6]);z_tra = z_tra + (value * m[8]) + (value * m[9]) + (value * m[10]);
or have I taken the wrong indexes of my matrix?
it should be a 4x4 matrix (16 floats)
can somebody please help?
thanks
Okay.
A little bit testing and I found out that I just had to:
to make the movement right.
Man that was a day of enlightments :-)
thank you guys for all the help.
and ignore the other thread started from me I had not seen that paulc pointed the move along camera Vector stuff out.
great thank to you paulc.
A little bit testing and I found out that I just had to:
float m[16];CSSMatrix tmpMatrix;cameraQuat.GetMatrix(tmpMatrix);tmpMatrix.GetValues(m);x_tra = x_tra + (value * m[2]);y_tra = y_tra + (value * m[6]);z_tra = z_tra + (value * m[10]);
to make the movement right.
Man that was a day of enlightments :-)
thank you guys for all the help.
and ignore the other thread started from me I had not seen that paulc pointed the move along camera Vector stuff out.
great thank to you paulc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement