Make a mesh face the direction its moving towards

bitem2k

Newcomer
Joined
Jul 13, 2005
Messages
4
Hi !

Does any one know how I can make a mesh look in the direction im walking.

I want it to face a given Vector.

thanks !
 
If I'm not mistaken, you have to transform the world by way of rotations and translations to move your mesh and make it face.
First, you apply the rotation to make it face in a direction, and then you translate the world so that your mesh will be located in the proper location when you draw it.

If you want it to a face a given vector, then you have to define where the vector comes from.
 
thanks for your reply.

I have no problem with making my mesh face the direction by rotating it. I use the Matrix m31 m32 m33 values after applying the transform to retrieve the look at vector, however i dont know how to make it face just by giving a vector.

if you want it to a face a given vector, then you have to define where the vector comes from.

Sorry i dont know what you mean, could you elaborate on this at all?

cheers
 
By "face a vector", I assume that the vector is referring to a point in space.
This means you also need the location of what it will be looking at.

However, if you are using the vector for a direction only, then you use the arctangent function to get the angle of this vector:
ang = Math.Atan2(vec.y, vec.x)
then, you apply a rotation transform to the world matrix with this angle (or its negative, depending on your needs) and then draw the mesh (assuming the mesh untransformed faces the 0° direction... if not, you may have to negate the angle and add 90° or maybe subtract...) . :)
 
Iceplug said:
ang = Math.Atan2(vec.y, vec.x)
then, you apply a rotation transform to the world matrix with this angle (or its negative, depending on your needs) and then draw the mesh (assuming the mesh untransformed faces the 0° direction... if not, you may have to negate the angle and add 90° or maybe subtract...) . :)


Nice one! Ill give that a try. Thankyou very much for your help!
 
Back
Top