I'm trying to create a camera object for my 2D game engine, but I just can't seem to get the view matrix down right.
Here's the code I'm currently using:
glm::mat4 Camera::GetViewMatrix()
{
glm::mat4 view;
glm::vec3 camPos = glm::vec3(this->pos, CAM_Z);
GLfloat xup, yup;
xup = sin(this->rot);
yup = cos(this->rot);
view = glm::lookAt(camPos, camPos + glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(xup, yup, 0.0f));
return view;
}
The result I get from this is as follows
Before rotation:
After rotation:
As you can see, the camera is rotating around its top left corner. The top left corner is the origin point (0,0,0) and the camera's position is (0,0). Shouldn't the lookAt
function position the camera at (0,0,1) and point it at (0,0,0)? That's not what seems to be happening.
I'm just trying to get the camera to roll about it's set position. Any help would be greatly appreciated! Thanks in advance!