3 #include <gmath/gmath.h>
6 #include "state_manager.h"
11 void Camera::use() const
13 state_manager.set_state("st_view_matrix", get_view_matrix());
16 OrbitCamera::OrbitCamera()
18 phi = theta = distance = 0;
21 OrbitCamera::~OrbitCamera() {}
23 void OrbitCamera::set_orbit_params(float theta, float phi, float distance)
27 this->distance = distance;
30 Mat4 OrbitCamera::get_view_matrix() const
33 view_matrix.translation(-position);
34 view_matrix.rotate_y(theta * (float)M_PI / 180);
35 view_matrix.rotate_x(phi * (float)M_PI / 180);
36 view_matrix.translate(Vec3(0, 0, -distance));
41 Mat4 calc_projection_matrix(float fov_deg, float aspect, float n, float f)
43 float fov = fov_deg / 180 * M_PI;
46 tmp = 1 / tan(fov / 2.0);
48 /* near - far clipping planes */
54 0, 0, (f + n) / range, -1,
55 0, 0, 2 * n * f / range, 0
61 void OrbitCamera::set_position(float x, float y, float z)