Proksima

01-30-2013, 08: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?

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;

}

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;

}