View Full Version : How can I make an object face a certain direction?

08-13-2013, 07:08 AM
I have an object at x,y,z and I want it to point toward another object in space at x2,y2,z2. Is there an easy way to do this in the vertex shader?

08-13-2013, 06:56 PM
Yes but you will probably need to pass either the rotation matrix or the object center and lookat point as uniforms to the shader (so you can calculate the rotation matrix). Then you multiple each vertex position by this matrix prior to the usually projection-viewmodel matrix multiply.

08-14-2013, 07:26 PM
How do I calculate the rotation matrix?

08-14-2013, 07:53 PM
How do I calculate the rotation matrix?

gluLookAt() is one option.