Jump to content
  • Advertisement
Sign in to follow this  
gramin

Adjusting the direction

This topic is 1334 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 a moving object which has a point and a velocity vector. What I want is rotating the object using glRotatef according to its velocity vector. I tried but couldn't find it. Doy ou have any ideas?

 

Thanks.

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Unless objects can only ever rotate on two axes, this is impossible -- you need at least two vectors.

 

Why? Well, because a single velocity vector only tells you in what direction your object looks, but not how it is rotated around that very axis. So there is an infinite number of possible solutions, each one being equally correct and incorrect.

 

So, in addition to your "forward" vector, you also need an "up" vector. If you are OK with objects having one degree of freedom less, you can simply use the world's "up" vector. Do a cross product on the two and you get a third vector. If you used the world "up" do the cross product backwards to orthogonalize the "up" vector, too (if your object has its own up vector, that's not necessary since it's already orthogonal). Normalize.

 

Now you have three unit vectors that are orthogonal to each other. There goes the upper left 3x3 portion of your 4x4 rotation matrix.

 

Translation goes into the right column.

Edited by samoth

Share this post


Link to post
Share on other sites

Rotations are always around origin.

 

You must first translate all the vertices in you object such that your point is at origin. So if P = (x, y, z), you translate all vertices by (-x, -y, -z). Then you perform your rotation around the velocity axis. Finaly you move back everything at the good place by translating by (x, y, z).

Share this post


Link to post
Share on other sites

Rotations are always around origin.

 

You must first translate all the vertices in you object such that your point is at origin. So if P = (x, y, z), you translate all vertices by (-x, -y, -z). Then you perform your rotation around the velocity axis. Finaly you move back everything at the good place by translating by (x, y, z).

 

How many degrees should I rotate?  Besides that, I guess it won't do what I want. My objects are tetrahedron so the up corner should show the velocity.

Edited by gramin

Share this post


Link to post
Share on other sites

Rotations are always around origin.

 

You must first translate all the vertices in you object such that your point is at origin. So if P = (x, y, z), you translate all vertices by (-x, -y, -z). Then you perform your rotation around the velocity axis. Finaly you move back everything at the good place by translating by (x, y, z).

Sorry, but if all vertices are translated by (-x,-y,-z), doesn't it mean all vertices become (0,0,0)? If so, does rotation still affect the vertices?

Share this post


Link to post
Share on other sites

 

Rotations are always around origin.

 

You must first translate all the vertices in you object such that your point is at origin. So if P = (x, y, z), you translate all vertices by (-x, -y, -z). Then you perform your rotation around the velocity axis. Finaly you move back everything at the good place by translating by (x, y, z).

Sorry, but if all vertices are translated by (-x,-y,-z), doesn't it mean all vertices become (0,0,0)? If so, does rotation still affect the vertices?

 

Here, (x,y,z) is the point you want to rotate around (if you want to rotate around a particular point somewhere, not the origin), the center of rotation.

 

The way you do a rotation around an arbitrary point is: first translate by (-x, -y, -z) so the object is centered on the origin, then rotate, and then translate by (x, y, z) again so the now rotated object gets its original position back..
 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!