This topic is 1334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites

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

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633003
• Total Posts
3009846
• ### Who's Online (See full list)

There are no registered users currently online

×