Sign in to follow this  

LookAt() functionality for FPS (Euler Angle) Camera

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a FPS style camera that accumulates Euler angles, and works well. But now I want to implement a lookAt( Vector ) method which will take in a vector, and then calculate an absolute rotation in Euler Angles to aim the camera at that point in space. This is what I have so far:
    void lookAt( float x1, float y1, float z1 )
    {
        VectorR3 v( x1, y1, z1 );
        v.x = m_position.x - v.x;
        v.y = m_position.y - v.y;
        v.z = m_position.z - v.z;

        float r = v.length();
        float yaw = acos( v.z / r );
        float pitch = atan2( v.y, v.x );

        setRotation( yaw, pitch, 0.0f, true ); // This just wraps the values to ensure they stay within range
    }


Bbuutt... things aren't working. This is Cartesian Coordinate to Spherical coordinate conversion, or at least it's suppose to be. Does anything jump out as majorly wrong here?

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this