gluLookAt vectors and FPS-style camera
Posted
by
Kevin Pamplona
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Pamplona
Published on 2012-10-27T22:25:24Z
Indexed on
2012/10/27
23:00 UTC
Read the original article
Hit count: 270
I am attempting to implemented an FPS-style camera by updating three vectors: EYE, DIR, UP. These vectors are the same that are used by gluLookAt (since gluLookAt is specified by the position of the camera, the direction it is looking at, and an up vector).
I have already implemented the left-right and up-down strafing movements, but I'm having a lot of trouble understanding the math behind making the camera look-around while remaining stationary. In this case, the EYE vector remains the same, while I must update DIR and UP.
Below is the code I tried, but it doesn't seem to work properly. Any suggestions? Thanks.
void Transform::left(float degrees, vec3& dir, vec3& up) {
vec3 axis;
axis = glm::normalize(up);
mat3 R = rotate(-degrees, axis);
dir = R*dir;
dir = R*up;
};
void Transform::up(float degrees, vec3& dir, vec3& up) {
vec3 axis;
axis=glm::normalize(glm::cross(dir,up));
mat3 R = rotate(-degrees, axis);
dir = R*dir-;
up = R*up;
};
© Stack Overflow or respective owner