diff options
Diffstat (limited to 'src/vec3.cpp')
| -rw-r--r-- | src/vec3.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/vec3.cpp b/src/vec3.cpp index 94b3432..b1e73f8 100644 --- a/src/vec3.cpp +++ b/src/vec3.cpp @@ -3,7 +3,7 @@ vec3::vec3(): x(0.0), y(0.0), z(0.0) {} -vec3::vec3(double x, double y, double z): x(x), y(y), z(z) {} +vec3::vec3(float x, float y, float z): x(x), y(y), z(z) {} vec3 vec3::operator-() const { return vec3 { @@ -21,7 +21,7 @@ vec3& vec3::operator+=(vec3 vec) { return *this; } -vec3& vec3::operator*=(double scale) { +vec3& vec3::operator*=(float scale) { x *= scale; y *= scale; z *= scale; @@ -29,7 +29,7 @@ vec3& vec3::operator*=(double scale) { return *this; } -vec3& vec3::operator/=(double numerator) { +vec3& vec3::operator/=(float numerator) { x /= numerator; y /= numerator; z /= numerator; @@ -37,15 +37,15 @@ vec3& vec3::operator/=(double numerator) { return *this; } -double vec3::length() const { +float vec3::length() const { return sqrt(length_sq()); } -double vec3::length_sq() const { +float vec3::length_sq() const { return x * x + y * y + z * z; } -double vec3::dot(const vec3& vec) const { +float vec3::dot(const vec3& vec) const { return x * vec.x + y * vec.y + z * vec.z; } @@ -71,11 +71,11 @@ vec3 vec3::random() { return vec3 { randd(), randd(), randd() }; } -vec3 vec3::random(double min, double max) { +vec3 vec3::random(float min, float max) { return vec3 { randd(min, max), randd(min, max), randd(min, max) }; } -vec3 lerp(vec3 u, vec3 v, double t) { +vec3 lerp(vec3 u, vec3 v, float t) { return (1.0 - t) * u + t * v; } @@ -91,7 +91,7 @@ vec3 operator*(vec3 u, vec3 v) { return vec3(u.x * v.x, u.y * v.y, u.z * v.z); } -vec3 operator*(vec3 u, double scale) { +vec3 operator*(vec3 u, float scale) { return vec3( u.x * scale, u.y * scale, @@ -99,11 +99,11 @@ vec3 operator*(vec3 u, double scale) { ); } -vec3 operator*(double scale, vec3 u) { +vec3 operator*(float scale, vec3 u) { return u * scale; } -vec3 operator/(vec3 u, double scale) { +vec3 operator/(vec3 u, float scale) { return (1.0 / scale) * u; } @@ -111,7 +111,7 @@ vec3 reflect(vec3 v, vec3 n) { return v - 2 * v.dot(n) * n; } -vec3 refract(const vec3& uv, const vec3& n, double etai_over_etat) { +vec3 refract(const vec3& uv, const vec3& n, float etai_over_etat) { auto cos_theta = fmin(n.dot(-uv), 1.0); vec3 r_out_perp = etai_over_etat * (uv + cos_theta*n); vec3 r_out_parallel = -sqrt(fabs(1.0 - r_out_perp.length_sq())) * n; |
