Skip to content

Commit

Permalink
Some changes in vec
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 12, 2023
1 parent d94ae7b commit f39804d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/util/vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
39 changes: 22 additions & 17 deletions src/util/vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,48 @@

#define EPSILON 0.0001f // EPSILON from rad.h / 10

#define EPSILON2 0.00001f // EPSILON from rad.h / 100

#define ON_EPSILON 0.03125f


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;
}
Expand Down

0 comments on commit f39804d

Please sign in to comment.