Skip to content

Add FirstPerson::look_at #56

Description

@bvssvni

Currently, there is no built-in method for FirstPerson to look at a particular point.

Here is some code I've been using (might require testing):

/// Calculates the yaw and pitch to look at something for first person camera.
pub fn yaw_pitch(
    pos: Vec3,
    look_at: Vec3
) -> (f64, f64) {
    use vecmath::*;
    use vecmath::traits::Radians;

    let d = vec3_normalized(vec3_sub(look_at, pos));
    let yaw_z = d[2].atan2(-d[0]);
    let yaw = yaw_z - f64::_90();
    let p = [-yaw_z.cos(), 0.0, yaw_z.sin()];
    let pitch = vec3_dot(d, p);
    (yaw, pitch.acos())
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions