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?
void Transform::left(float degrees, vec3& dir, vec3& up) {
vec3 axis;
axis = glm::normalize(up);
mat3 R = rotate(-degrees, axis);
dir = R*dir;
up = 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;
};
The rotate method creates a rotation matrix that rotates an an amount degrees around axis.
--
EDIT: I edited it to this (switching 'dir' to 'center', as well), but it still didn't work. When I try to rotate left/right, nothing happens. When I try to rotate up/down, the object disappears.
void Transform::left(float degrees, vec3& center, vec3& up) {
center = center*rotate(-degrees,glm::normalize(up));
}
void Transform::up(float degrees, vec3& center, vec3& up) {
vec3 axis = glm::normalize(glm::cross(center,up));
center = center*rotate(-degrees, axis);
}