Jump to content
  • Advertisement

Archived

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

promo

3D math problem

This topic is 6235 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 people. I have the following problem: Imagine a starship looking straight ahead. straight is into the Z axis, up is the Y. If I wanted to turn the ship left or right I would rotate it around the Y axis. OK. Now if this ship would be facing up towards the Y axis, turning left/right would mean rotating along the Z. And if it was in between.... I know I can find the vector to rotate around using simple transformation matrices, but does anyone know how I get the new angles I need? All my 3D objects have absolute (to the axes) angles. How do I know which angles to change when I want the ship "up 3 degrees" or "left 5 degrees"? Thanx in advance! -------------------- so, what you''''re saying is, that the mushroom spores were brought in from outer space by - who?? -cosmosis

Share this post


Link to post
Share on other sites
Advertisement
I''ve been confronted to the same problem
You should have a look to C Hecker Tutorials
My Math knowledge doesn''t permitt me to explain you, but
there you should find what you need :
http://www.d6.com/users/checker/dynamics.htm
I Hope you''re motivated cause it''s kinda pretty hard stuff

Share this post


Link to post
Share on other sites
Another usefull info
You should read the whole 4 tutz on rigid body dynamics, but
the tutorial you need is the 4th

Share this post


Link to post
Share on other sites
This might help...

Keep track of the current up, look, and right vectors of the ship. When you need to pitch up rotate by these axis.

Be sure to normalize and true these axises by each other after rotating them, by doing something like this:

// cross product of Up and Look vectors
m_vRight = GVector3CrossProduct(m_vUp, m_vLook);
m_vRight = GVector3Normalize(m_vRight);

// cross product of Look and Right vectors
m_vUp = GVector3CrossProduct(m_vLook, m_vRight);
m_vUp = GVector3Normalize(m_vUp);



You can get the full transform to align the ships vectors with the world space by the following:

// Right to x axis
matTransform._11 = m_vRight.x;
matTransform._21 = m_vRight.y;
matTransform._31 = m_vRight.z;
matTransform._41 = 0;

// Up to y axis
matTransform._12 = m_vUp.x;
matTransform._22 = m_vUp.y;
matTransform._32 = m_vUp.z;
matTransform._42 = 0;

// Look to z axis
matTransform._13 = m_vLook.x;
matTransform._23 = m_vLook.y;
matTransform._33 = m_vLook.z;
matTransform._43 = 0;

// complete the matrix
matTransform._14 = 0;
matTransform._24 = 0;
matTransform._34 = 0;
matTransform._44 = 1;


So the whole thing would go like this:
1. Do the above transform to the axises to temporally align the ship with the world axises.
2. Rotate the axises as you would normally do.
3. Use the transpose matrix of the first matrix transform to get back to actual world coordinates for the axises.
4. Do this for each axis. Then normalize and true the axises.

To display the ship or view from the ship apply the transpose of the above transform (using the current ship’s vectors to calculate the transform).


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!