Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions utils/common/mathlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ float Atan2Fast( float y, float x )
return res;
}

/*
=================
TriangleArea
=================
*/
vec_t TriangleArea( const vec3_t a, const vec3_t b, const vec3_t c )
{
vec3_t ba, ca, cro;
VectorSubtract( b, a, ba );
VectorSubtract( c, a, ca );
CrossProduct( ba, ca, cro );
return 0.5f * VectorLength( cro );
}

/*
=================
TriangleIncenter
Expand Down Expand Up @@ -284,6 +298,25 @@ void TangentToWorld( const vec3_t v, const vec3_t t, const vec3_t b, const vec3_
out[2] = v[0] * t[2] + v[1] * b[2] + v[2] * n[2];
}

/*
=================
Halton
=================
*/
float Halton(int base, int index)
{
float result = 0.0f;
float f = 1.0f;
while (index > 0)
{
f = f / float(base);
result += f * float(index % base);
index = index / base;
}
return result;
}


/*
==============
ColorNormalize
Expand Down
2 changes: 2 additions & 0 deletions utils/common/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,11 @@ float HalfToFloat( unsigned short h );

float AcosFast( float x );
float Atan2Fast( float y, float x );
vec_t TriangleArea( const vec3_t a, const vec3_t b, const vec3_t c );
void TriangleIncenter( const vec3_t a, const vec3_t b, const vec3_t c, vec3_t out );
void WorldToTangent( const vec3_t v, const vec3_t t, const vec3_t b, const vec3_t n, vec3_t out );
void TangentToWorld( const vec3_t v, const vec3_t t, const vec3_t b, const vec3_t n, vec3_t out );
float Halton(int base, int index);

//
// Bounding Box operations
Expand Down
Loading