Jump to content
  • Advertisement

Archived

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

Ignorance

Relative Rotation Problem - PLEASE HELP!

This topic is 5736 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

Hi - I have asked about this before, but it is REALLY ticking me off, and I need help. My game engine at the moment can handle Quaternions or Eulers to do rotation, but no matter which system I use, I always run into a problem. I am trying to make an ship that you fly in space. To pilot this ship, I need to change the rotation of the ship RELATIVE TO IT''S CURRENT ROTATION. That means that when I roll the ship, I want it to roll relative to the direction it is already travelling in. So, if I am currently pointing (using Euler angles here) 90 degrees up on the X axis (eg. a Pitch of 90, looking straight up the Y axis) and then I try to roll/bank my ship by 20 degrees, I want it to roll AROUND THE CURRENT AXIS OF MY SHIP, not around the original X,Y & Z plane. If I simply added the euler or quaternion for 0,0,20 (20 degrees around the z axis) then I would spin the wrong way. To make this work, I need to translate the 0,0,20 into something that works using the standard coordinate system. Given that I''m pitched up 90 degrees, to make it roll 20 degrees around RELATIVE TO THE PILOT OF THE SHIP, I actually need to apply this on the ''Y'' axis, not the ''Z''. (eg. 0,20,0). Is there a way to translate my three angles by the rotation stored in the euler or quaternion? There MUST be a way - it would have to be required in almost every game in existance. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
opengl or d3d?

no matter what, you need the vectors of your ship. the forward vector to roll, the right vector to pitch, the up vector to yaw.

in d3d i think you have the matrix for your object anyway and reading one of the first three lines shouldnt be hard.

in opengl i still suggest you drop storing angles and then applying all at once with rotate and translate. it wont work, you need the order in which they were applied and that means: input wont change angles, input has to directly change the orientation. im not familiar with quaternions (and as long as i dont have to interpolate rotations i dont see any reason to.. *cough* hope i didnt start a holy war about that).

ill just copy a camera class.. drop the setView part and you will have the stuff you need to make a plane or spaceship fly...
changed my mind.. to many files and comments.. ill just upload it here:

http://festini.device-zero.de/downloads/camera.zip

Share this post


Link to post
Share on other sites
If you want to rotate around the relative X-axis, take the vector (1,0,0), transform it using the space ship''s worldspace matrix, then rotate around the resultant matrix.



~BenDilts( void );

Share this post


Link to post
Share on other sites
First of all, if you are doing a space-flight sim, then dump the Euler angles now. It is very difficult to avoid gimbal lock if you are using euler angles and the ship is able to have any orientation. Use quaternions or matrices for all computation and convert to euler angles for display only.

1. Decide on a base orientation -- for example, the Z axis is forward, the X axis is to the right, and the Y axis is up.
2. Represent your orientation as a rotation from the base orientation using a matrix or quaternion. The identity matrix or quat means the base orientation and no rotation.
3. To rotate your ship, you multiply the current orientation and the delta rotation to get the new orientation.
a. If you transform vertices like this (D3D notation): v'' = vM, then your new orientation is Mnew = M*D because v'' = (vM)*D = v(M*D).
b. If you transform vertices like this (OpenGL notation): v'' = Mv, then your new orientation is Mnew = D*M because v'' = D*(Mv) = (D*M)v.

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!