Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How can I make an object face a certain direction?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    22

    How can I make an object face a certain direction?

    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?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,098
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    22
    How do I calculate the rotation matrix?

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by Rakehell View Post
    How do I calculate the rotation matrix?
    gluLookAt() is one option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •