X-Git-Url: https://eleni.mutantstargoat.com/git/?p=vkrt;a=blobdiff_plain;f=src%2Fcamera.cc;fp=src%2Fcamera.cc;h=620bec4e518eb44b3341382d32d4e73b50a63843;hp=0000000000000000000000000000000000000000;hb=470723fe1cc3902759399a023a062051c460bd1f;hpb=6c8e0d1dcf1e08982b54a1b2d2e914e409e09386 diff --git a/src/camera.cc b/src/camera.cc new file mode 100644 index 0000000..620bec4 --- /dev/null +++ b/src/camera.cc @@ -0,0 +1,60 @@ +#include + +#include + +#include "camera.h" + +Camera::Camera() {} +Camera::~Camera() {} + +OrbitCamera::OrbitCamera() +{ + phi = theta = distance = 0; +} + +OrbitCamera::~OrbitCamera() {} + +void OrbitCamera::set_orbit_params(float theta, float phi, float distance) +{ + this->phi = phi; + this->theta = theta; + this->distance = distance; +} + +Mat4 OrbitCamera::get_view_matrix() const +{ + Mat4 view_matrix; + view_matrix.translation(-position); + view_matrix.rotate_y(theta * (float)M_PI / 180); + view_matrix.rotate_x(phi * (float)M_PI / 180); + view_matrix.translate(Vec3(0, 0, -distance)); + + return view_matrix; +} + +Mat4 calc_projection_matrix(float fov_deg, float aspect, float n, float f) +{ + float fov = fov_deg / 180 * M_PI; + + float tmp; + tmp = 1 / tan(fov / 2.0); + + /* near - far clipping planes */ + float range = n - f; + + Mat4 pmat = Mat4( + tmp/aspect, 0, 0, 0, + 0, tmp, 0, 0, + 0, 0, (f + n) / range, -1, + 0, 0, 2 * n * f / range, 0 + ); + + return pmat; +} + +void OrbitCamera::set_position(float x, float y, float z) +{ + position.x = x; + position.y = y; + position.z = z; +}