X-Git-Url: http://git.mutantstargoat.com?p=demo;a=blobdiff_plain;f=src%2Fcamera.cc;h=4db7286f24573fb8e9ee1518dba2b8362f6cf7e4;hp=d7839b57322f0419c0b7b97e193458b299d25382;hb=369d75c73bf926a6dbcf4d740c8664bbb401602a;hpb=0da7a98f74d00bfa6cf0d47fd7cf0f687eeba5f6 diff --git a/src/camera.cc b/src/camera.cc index d7839b5..4db7286 100644 --- a/src/camera.cc +++ b/src/camera.cc @@ -1,20 +1,53 @@ +#include + #include + #include "camera.h" +#include "state_manager.h" -Camera::Camera() +Camera::Camera() {} +Camera::~Camera() {} + +void Camera::use() const +{ + state_manager.set_state("st_view_matrix", get_view_matrix()); +} + +OrbitCamera::OrbitCamera() { phi = theta = distance = 0; - fov = 0; - m_projection = Mat4::identity; } -Camera::Camera(float phi, float theta, float distance, float fov) +OrbitCamera::~OrbitCamera() {} + +void OrbitCamera::set_orbit_params(float phi, float theta, float distance) { this->phi = phi; this->theta = theta; this->distance = distance; +} + +Mat4 OrbitCamera::get_view_matrix() const +{ + Mat4 view_matrix; + view_matrix.translate(Vec3(0, 0, -distance)); + view_matrix.rotate_x(phi * (float)M_PI / 180); + view_matrix.rotate_y(theta * (float)M_PI / 180); - this->fov = fov; + return view_matrix; } -Camera::~Camera() {} \ No newline at end of file +Mat4 calc_projection_matrix(float f, float n, float aspect, float fov) +{ + float tmp; + tmp = 1 / tan(fov / 2.0); + + Mat4 pmat = Mat4( + -tmp/aspect, 0, 0, 0, + 0, tmp, 0, 0, + 0, 0, (f + n) / (n - f), (2 * f * n) / (n - f), + 0, 0, -1, 0 + ); + + return pmat; +} \ No newline at end of file