aboutsummaryrefslogtreecommitdiffstats
path: root/src/camera.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2021-08-20 22:53:57 +0200
committerladevieq <ladevie.quentin@gmail.com>2021-08-20 22:53:57 +0200
commit4ea8d2d92af80d64a16b3d20f899b22921aa42d0 (patch)
treeff561d6597b32b988bb953b4c9982087aff5bb06 /src/camera.cpp
parent63369e10715f4525917bef82b4a6f1074776795f (diff)
Use simd for vec3 computations
Diffstat (limited to 'src/camera.cpp')
-rw-r--r--src/camera.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index 917cb4e..908ba09 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -12,9 +12,9 @@ camera::camera(
float focus_dist
) : position(position), lens_radius(aperture / 2.0), fov(v_fov), focus_distance(focus_dist), aspect_ratio(aspect_ratio) {
- forward = (target - position).unit();
- right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit();
- up = right.cross(forward).unit();
+ forward = (target - position).normalize();
+ right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).normalize();
+ up = right.cross(forward).normalize();
auto h = tan(deg_to_rad(fov) / 2.0);
auto viewport_height = 2.0 * h;
@@ -45,11 +45,12 @@ void camera::move(vec3 v) {
}
void camera::rotate_y(float theta) {
- forward.x = forward.x * cos(theta) - forward.z * sin(theta);
- forward.z = forward.x * sin(theta) + forward.z * cos(theta);
+ forward.v[0] = forward.v[0] * cos(theta) - forward.v[2] * sin(theta);
+ forward.v[2] = forward.v[0] * sin(theta) + forward.v[2] * cos(theta);
+ forward.normalize();
- right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit();
- up = right.cross(forward).unit();
+ right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).normalize();
+ up = right.cross(forward).normalize();
auto h = tan(deg_to_rad(fov) / 2.0);
auto viewport_height = 2.0 * h;