LookAt() functionality for FPS (Euler Angle) Camera

Started by
0 comments, last by jpetrie 14 years, 1 month ago
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?
==============================
A Developers Blog | Dark Rock Studios - My Site
Advertisement
Crossposted.

This topic is closed to new replies.

Advertisement