-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
33 lines (28 loc) · 867 Bytes
/
Camera.cpp
File metadata and controls
33 lines (28 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "Camera.h"
// camera position in Cartesian coords from angles and r (y is up!!!)
void Camera::getViewMatrix(glm::mat4& outViewMatrix) {
float cx = glm::cos(angles.x);
float sx = glm::sin(angles.x);
float cy = glm::cos(angles.y);
float sy = glm::sin(angles.y);
glm::vec3 position = glm::vec3(
cx * cy,
sy,
sx * cy
) * std::exp(-zoom);
glm::mat4 viewMatrix = glm::lookAt(position, glm::vec3(0.0f), glm::vec3(0, 1, 0));
outViewMatrix = viewMatrix;
}
void Camera::getProjMatrix(glm::mat4& outModelMatrix) { outModelMatrix = projMatrix; }
glm::vec3 Camera::getPosition() {
float cx = glm::cos(angles.x);
float sx = glm::sin(angles.x);
float cy = glm::cos(angles.y);
float sy = glm::sin(angles.y);
glm::vec3 position = glm::vec3(
cx * cy,
sy,
sx * cy
) * std::exp(-zoom);
return position;
}