diff --git a/src/util/vectors.cpp b/src/util/vectors.cpp index 4a25a0eb..564f75c2 100644 --- a/src/util/vectors.cpp +++ b/src/util/vectors.cpp @@ -179,9 +179,10 @@ void makeVectors(const vec3& angles, vec3& forward, vec3& right, vec3& up) vec3 vec3::normalize(float length) { - if (abs(x) < EPSILON && abs(y) < EPSILON && abs(z) < EPSILON) + if (abs(x) < EPSILON2 && abs(y) < EPSILON2 && abs(z) < EPSILON2) return vec3(); float d = length / sqrt((x * x) + (y * y) + (z * z)); + return vec3(x * d, y * d, z * d); } @@ -212,7 +213,7 @@ vec3 vec3::swap_xz() vec3 vec3::invert() { - return vec3(abs(x) >= EPSILON ? -x : x, abs(y) >= EPSILON ? -y : y, abs(z) >= EPSILON ? -z : z); + return vec3( -x , -y, -z ); } float vec3::length() @@ -266,12 +267,12 @@ vec3 vec3::flipUV() vec3 vec3::unflip() { - return vec3(x, -z, y); + return flipUV(); } vec3 vec3::unflipUV() { - return vec3(x, z, -y); + return flip(); } bool operator==(const vec2& v1, const vec2& v2) @@ -400,7 +401,7 @@ float vec2::length() vec2 vec2::normalize(float length) { - if (abs(x) < EPSILON && abs(y) < EPSILON) + if (abs(x) < EPSILON2 && abs(y) < EPSILON2) return vec2(); float d = length / sqrt((x * x) + (y * y)); return vec2(x * d, y * d); diff --git a/src/util/vectors.h b/src/util/vectors.h index 3a03cccc..c4e5bc7e 100644 --- a/src/util/vectors.h +++ b/src/util/vectors.h @@ -6,6 +6,8 @@ #define EPSILON 0.0001f // EPSILON from rad.h / 10 +#define EPSILON2 0.00001f // EPSILON from rad.h / 100 + #define ON_EPSILON 0.03125f @@ -13,36 +15,39 @@ struct vec3 { float x, y, z; - vec3() : x(+0.0f), y(+0.0f), z(+0.0f) + void Copy(const vec3& other) + { + x = other.x; + y = other.y; + z = other.z; + } + vec3& operator =(const vec3& other) { + Copy(other); + return *this; + } + vec3(const vec3& other) + { + Copy(other); } - vec3(const vec3& other) : x(other.x), y(other.y), z(other.z) + + vec3() : x(+0.0f), y(+0.0f), z(+0.0f) { - if (abs(x) < EPSILON) - { - x = +0.0f; - } - if (abs(y) < EPSILON) - { - y = +0.0f; - } - if (abs(z) < EPSILON) - { - z = +0.0f; - } + } + vec3(float x, float y, float z) : x(x), y(y), z(z) { - if (abs(x) < EPSILON) + if (abs(x) < EPSILON2) { x = +0.0f; } - if (abs(y) < EPSILON) + if (abs(y) < EPSILON2) { y = +0.0f; } - if (abs(z) < EPSILON) + if (abs(z) < EPSILON2) { z = +0.0f; }