aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-07-12 22:16:26 +0200
committerladevieq <ladevie.quentin@gmail.com>2022-07-12 22:16:40 +0200
commit715ab680e68f62a3a00777e81b18f8e64110058d (patch)
tree66f825e75c84cd28ceb3a8aba3ff715036ceb362 /src
parent13acb0321b5f2ed392c94e1f7c64069d4242971a (diff)
Fix BVH & vec3 API
Diffstat (limited to 'src')
-rw-r--r--src/camera.cpp4
-rw-r--r--src/vec3.cpp18
2 files changed, 11 insertions, 11 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index e9e5f60..6950fec 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -47,6 +47,10 @@ void camera::rotate_y(float theta) {
auto h = tan(deg_to_rad(fov) / 2.f);
auto viewport_height = 2.f * h;
+ auto viewport_width = viewport_height * aspect_ratio;
+
+ horizontal = focus_distance * viewport_width * right;
+ vertical = focus_distance * viewport_height * up;
vertical = focus_distance * viewport_height * up;
first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward;
diff --git a/src/vec3.cpp b/src/vec3.cpp
index 096dde0..43431fc 100644
--- a/src/vec3.cpp
+++ b/src/vec3.cpp
@@ -16,7 +16,7 @@ vec3::vec3(const vec3 &vec) { v = _mm_load_ps((float *)&vec.v); }
vec3::vec3(const vec3 &&vec) { v = _mm_load_ps((float *)&vec.v); }
-vec3 vec3::operator-() const { return vec3(_mm_xor_ps(v, _mm_set1_ps(-0.0f))); }
+vec3 vec3::operator-() const { return { _mm_xor_ps(v, _mm_set1_ps(-0.0f)) }; }
vec3 &vec3::operator=(const vec3 &vec) {
v = _mm_load_ps((float *)&vec.v);
@@ -68,16 +68,12 @@ vec3 vec3::cross(const vec3 &vec) const {
return _mm_sub_ps(tmp3, tmp4);
}
-vec3 &vec3::min(const vec3 &vec) {
- v = _mm_min_ps(v, vec.v);
-
- return *this;
+vec3 vec3::min(const vec3 &vec) const {
+ return { _mm_min_ps(v, vec.v) };
}
-vec3 &vec3::max(const vec3 &vec) {
- v = _mm_max_ps(v, vec.v);
-
- return *this;
+vec3 vec3::max(const vec3 &vec) const {
+ return { _mm_max_ps(v, vec.v) };
}
vec3 &vec3::normalize() {
@@ -96,9 +92,9 @@ void vec3::print() const {
printf("%f %f %f\n", v[0], v[1], v[2]);
}
-vec3 vec3::random() { return vec3{randd(), randd(), randd()}; }
+vec3 vec3::random() { return { randd(), randd(), randd() }; }
-vec3 vec3::random(float min, float max) { return vec3{randd(min, max), randd(min, max), randd(min, max)}; }
+vec3 vec3::random(float min, float max) { return { randd(min, max), randd(min, max), randd(min, max) }; }
// TODO: Use simd instructions