erebus
diff liberebus/src/camera.cc @ 46:c4d48a21bc4a
in the middle of the vmath->gph-math port
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 24 Feb 2016 00:26:50 +0200 |
parents | d15ee526daa6 |
children |
line diff
1.1 --- a/liberebus/src/camera.cc Tue Dec 29 12:19:53 2015 +0200 1.2 +++ b/liberebus/src/camera.cc Wed Feb 24 00:26:50 2016 +0200 1.3 @@ -12,7 +12,7 @@ 1.4 cached_matrix_valid = false; 1.5 } 1.6 1.7 -Camera::Camera(const Vector3 &p) 1.8 +Camera::Camera(const Vec3 &p) 1.9 : pos(p) 1.10 { 1.11 vfov = DEFAULT_FOV; 1.12 @@ -33,18 +33,18 @@ 1.13 return vfov; 1.14 } 1.15 1.16 -void Camera::set_position(const Vector3 &pos) 1.17 +void Camera::set_position(const Vec3 &pos) 1.18 { 1.19 this->pos = pos; 1.20 cached_matrix_valid = false; // invalidate the cached matrix 1.21 } 1.22 1.23 -const Vector3 &Camera::get_position() const 1.24 +const Vec3 &Camera::get_position() const 1.25 { 1.26 return pos; 1.27 } 1.28 1.29 -const Matrix4x4 &Camera::get_matrix() const 1.30 +const Mat4x4 &Camera::get_matrix() const 1.31 { 1.32 if(!cached_matrix_valid) { 1.33 calc_matrix(&cached_matrix); 1.34 @@ -53,7 +53,7 @@ 1.35 return cached_matrix; 1.36 } 1.37 1.38 -Vector2 Camera::calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const 1.39 +Vec2 Camera::calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const 1.40 { 1.41 float ppos[2]; 1.42 float aspect = (float)xsz / (float)ysz; 1.43 @@ -65,12 +65,12 @@ 1.44 ppos[1] = 1.0 - (float)y * pheight; 1.45 1.46 calc_sample_pos_rec(sample, pwidth, pheight, ppos); 1.47 - return Vector2(ppos[0], ppos[1]); 1.48 + return Vec2(ppos[0], ppos[1]); 1.49 } 1.50 1.51 Ray Camera::get_primary_ray(int x, int y, int xsz, int ysz, int sample) const 1.52 { 1.53 - Vector2 ppos = calc_sample_pos(x, y, xsz, ysz, sample); 1.54 + Vec2 ppos = calc_sample_pos(x, y, xsz, ysz, sample); 1.55 1.56 Ray ray; 1.57 ray.origin = pos; 1.58 @@ -80,7 +80,7 @@ 1.59 ray.dir.normalize(); 1.60 1.61 // transform the ray direction with the camera matrix 1.62 - Matrix4x4 mat = get_matrix(); 1.63 + Mat4x4 mat = get_matrix(); 1.64 mat.m[0][3] = mat.m[1][3] = mat.m[2][3] = mat.m[3][0] = mat.m[3][1] = mat.m[3][2] = 0.0; 1.65 mat.m[3][3] = 1.0; 1.66 1.67 @@ -90,35 +90,35 @@ 1.68 1.69 TargetCamera::TargetCamera() {} 1.70 1.71 -TargetCamera::TargetCamera(const Vector3 &pos, const Vector3 &targ) 1.72 +TargetCamera::TargetCamera(const Vec3 &pos, const Vec3 &targ) 1.73 : Camera(pos), target(targ) 1.74 { 1.75 } 1.76 1.77 -void TargetCamera::set_target(const Vector3 &targ) 1.78 +void TargetCamera::set_target(const Vec3 &targ) 1.79 { 1.80 target = targ; 1.81 cached_matrix_valid = false; // invalidate the cached matrix 1.82 } 1.83 1.84 -const Vector3 &TargetCamera::get_target() const 1.85 +const Vec3 &TargetCamera::get_target() const 1.86 { 1.87 return target; 1.88 } 1.89 1.90 -void TargetCamera::calc_matrix(Matrix4x4 *mat) const 1.91 +void TargetCamera::calc_matrix(Mat4x4 *mat) const 1.92 { 1.93 - Vector3 up{0, 1, 0}; 1.94 - Vector3 dir = (target - pos).normalized(); 1.95 + Vec3 up{0, 1, 0}; 1.96 + Vec3 dir = (target - pos).normalized(); 1.97 1.98 if(1.0 - fabs(dot_product(dir, up)) < 1e-4) { 1.99 - up = Vector3(0, 0, 1); 1.100 + up = Vec3(0, 0, 1); 1.101 } 1.102 1.103 - Vector3 right = cross_product(up, dir).normalized(); 1.104 + Vec3 right = cross_product(up, dir).normalized(); 1.105 up = cross_product(dir, right); 1.106 1.107 - *mat = Matrix4x4( 1.108 + *mat = Mat4x4( 1.109 right.x, up.x, dir.x, pos.x, 1.110 right.y, up.y, dir.y, pos.y, 1.111 right.z, up.z, dir.z, pos.z, 1.112 @@ -127,11 +127,11 @@ 1.113 1.114 void FlyCamera::input_move(float x, float y, float z) 1.115 { 1.116 - static const Vector3 vfwd(0, 0, 1), vright(1, 0, 0); 1.117 + static const Vec3 vfwd(0, 0, 1), vright(1, 0, 0); 1.118 1.119 - Vector3 k = vfwd.transformed(rot); 1.120 - Vector3 i = vright.transformed(rot); 1.121 - Vector3 j = cross_product(k, i); 1.122 + Vec3 k = vfwd.transformed(rot); 1.123 + Vec3 i = vright.transformed(rot); 1.124 + Vec3 j = cross_product(k, i); 1.125 1.126 pos += i * x + j * y + k * z; 1.127 cached_matrix_valid = false; 1.128 @@ -139,7 +139,7 @@ 1.129 1.130 void FlyCamera::input_rotate(float x, float y, float z) 1.131 { 1.132 - Vector3 axis(x, y, z); 1.133 + Vec3 axis(x, y, z); 1.134 float axis_len = axis.length(); 1.135 if(fabs(axis_len) < 1e-5) { 1.136 return; 1.137 @@ -150,14 +150,14 @@ 1.138 cached_matrix_valid = false; 1.139 } 1.140 1.141 -void FlyCamera::calc_matrix(Matrix4x4 *mat) const 1.142 +void FlyCamera::calc_matrix(Mat4x4 *mat) const 1.143 { 1.144 - Matrix4x4 tmat; 1.145 + Mat4x4 tmat; 1.146 tmat.set_translation(pos); 1.147 1.148 - Matrix3x3 rmat = rot.get_rotation_matrix(); 1.149 + Mat3x3 rmat = rot.get_rotation_matrix(); 1.150 1.151 - *mat = tmat * Matrix4x4(rmat); 1.152 + *mat = tmat * Mat4x4(rmat); 1.153 } 1.154 1.155 /* generates a sample position for sample number sidx, in the unit square