View Full Version : Trying to implement an FPS-like camera.

01-30-2013, 07:14 PM
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?



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

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;
Vector<3> left = up^front;

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;

02-03-2013, 05:31 PM
= = personally I think gluLookAt() is easier.

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