You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
998 B
29 lines
998 B
|
|
#include "camera.h" |
|
|
|
|
|
void |
|
cameraInitPerspective(camera& cam, glm::vec3 position, glm::vec3 target, glm::vec3 up) |
|
{ |
|
cam.position = position; |
|
cam.target = target; |
|
cam.up = up; |
|
cam.projection = glm::infinitePerspective(glm::radians(FOV), ASPECT_RATIO, NEAR_CLIP_PLANE); |
|
|
|
cam.hAngle = 0; |
|
cam.vAngle = glm::atan((cam.target.z - cam.position.z) / (cam.target.y - cam.position.y)); |
|
|
|
// FIXME: bug, camera always starts with forward pointing at positive 'z' axis |
|
// camera position also changes with change to window size |
|
cam.forward = glm::normalize(glm::vec3( |
|
glm::cos(cam.vAngle) * glm::sin(cam.hAngle), |
|
glm::cos(cam.vAngle) * glm::cos(cam.hAngle), |
|
glm::sin(cam.vAngle) |
|
)); |
|
cam.left = glm::normalize(glm::cross(cam.up, cam.forward)); |
|
cam.up = glm::normalize(glm::cross(cam.forward, cam.left)); // get better "up" vector |
|
|
|
cam.view = glm::lookAt(cam.position, cam.position + cam.forward, cam.up); |
|
cam.model = glm::mat4(1.0f); |
|
cam.MVP = cam.projection * cam.view * cam.model; |
|
}
|
|
|