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 2 of 2

Thread: Implement Unity Transform.LookAt function.

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    27

    Implement Unity Transform.LookAt function.

    Hi!

    I'm trying to implement the Transform.LookAt function that can be found here: http://docs.unity3d.com/ScriptRefere...rm.LookAt.html

    This function calculates Yaw, Pitch and Roll and updates the rotation of the object.

    Example(Update position and rotation of the sun):

    sun.localPosition = Vector3(?, ?, ?);
    sun.LookAt(targetPos, upVector) //this should be the same as glm::lookAt(sunPos, targetPos, upVector) I think?


    I found another guy who tried to implement the whole Transform class: http://gamedev.stackexchange.com/que...ransform-class

    And I found his implementation of LookAt:
    Code :
    void Transform::LookAt(glm::vec3 targetPosition)
    {
            if((targetPosition - m_Position) == glm::vec3(0,0,0)) return;
            glm::vec3 direction = glm::normalize(targetPosition - m_Position);
            m_Rotation.x = asinf(-direction.y)* RadToDeg;
            m_Rotation.y = -atan2f(-direction.x, -direction.z)*RadToDeg;
     
            NormalizeAngles();
            m_NeedUpdate = true;
    }

    But "m_Rotation" does only contain Pitch and Yaw, not Roll. How did they(Unity) calculate Roll?


    Thanks in advance.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2010
    Location
    Oakville, ON, CA
    Posts
    165
    Why don't you just simply copy the algorithm used in gluLookAt function?

Posting Permissions

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