Adjusting the direction

Started by
2 comments, last by codpp 9 years, 1 month ago

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.

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.

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).

My blog about games, AI...

http://totologic.blogspot.com/

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.

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?

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..

This topic is closed to new replies.

Advertisement