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: Trying to implement an FPS-like camera.

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    1

    Trying to implement an FPS-like camera.

    Hi everyone,

    I am trying to implement an FPS-like camera. [See code below.]
    It is an home made math librairy, but I think it should be easy to understand.

    The problem is that instead of having the camera pivoting, it is the model that looks like it is rotating around an arbitrary point in space (probably the origin...)
    My camera is stored as 3 vectors, target, eye and up.

    Does anyone would be able to help me solve this problem?

    Proksima

    /***/

    Matrix<4, 4> Camera::getViewMatrix(void) const {
    Vector<3> front = target - eye;
    front.normalize();
    Vector<3> left = up^front; // Denotes a cross product.
    left.normalize();

    Matrix<4, 4> view_matrix;
    view_matrix[0] = Vector<4>(left, 0.0);
    view_matrix[1] = Vector<4>(up, 0.0);
    view_matrix[2] = Vector<4>(front, 0.0);
    view_matrix[3] = Vector<4>(eye, 1.0);

    return view_matrix;
    }

    void Camera::rotate(float const delta_latitude, float const delta_longitude) {
    Vector<3> front = target - eye;
    front.normalize();
    Vector<3> left = up^front;
    left.normalize();

    Quaternion<> y_rotation(delta_longitude, up);
    Quaternion<> x_rotation(delta_latitude, left);

    front = x_rotation.matrix()*y_rotation.matrix()*front;
    target = eye + front;

    up = x_rotation.matrix()*up;
    }

    void Camera::move(Vector<3> const &displacement) {
    eye += displacement;
    target += displacement;
    }

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13
    = = personally I think gluLookAt() is easier.

    I usually use GLFrame to create a camera.GLFrame is a class discribed in OpenGLSuperBible (4th).

Posting Permissions

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