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 phi, float theta, float distance)
27 this->distance = distance;
30 Mat4 OrbitCamera::get_view_matrix() const
33 view_matrix.rotate_y(theta * (float)M_PI / 180);
34 view_matrix.rotate_x(phi * (float)M_PI / 180);
35 view_matrix.translate(Vec3(0, 0, -distance));
40 Mat4 calc_projection_matrix(float fov_deg, float aspect, float n, float f)
42 float fov = fov_deg / 180 * M_PI;
45 tmp = 1 / tan(fov / 2.0);
47 /* near - far clipping planes */
53 0, 0, (f + n) / range, -1,
54 0, 0, 2 * n * f / range, 0