|
@@ -30,6 +30,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
#include "maths.h"
|
|
#include "maths.h"
|
|
|
|
+#include <cfloat>
|
|
|
|
|
|
namespace squish {
|
|
namespace squish {
|
|
|
|
|
|
@@ -85,11 +86,11 @@ static Vec3 GetMultiplicity1Evector( Sym3x3 const& matrix, float evalue )
|
|
u[5] = m[0]*m[3] - m[1]*m[1];
|
|
u[5] = m[0]*m[3] - m[1]*m[1];
|
|
|
|
|
|
// find the largest component
|
|
// find the largest component
|
|
- float mc = SquishMath::fabs( u[0] );
|
|
|
|
|
|
+ float mc = std::fabs( u[0] );
|
|
int mi = 0;
|
|
int mi = 0;
|
|
for( int i = 1; i < 6; ++i )
|
|
for( int i = 1; i < 6; ++i )
|
|
{
|
|
{
|
|
- float c = SquishMath::fabs( u[i] );
|
|
|
|
|
|
+ float c = std::fabs( u[i] );
|
|
if( c > mc )
|
|
if( c > mc )
|
|
{
|
|
{
|
|
mc = c;
|
|
mc = c;
|
|
@@ -124,11 +125,11 @@ static Vec3 GetMultiplicity2Evector( Sym3x3 const& matrix, float evalue )
|
|
m[5] = matrix[5] - evalue;
|
|
m[5] = matrix[5] - evalue;
|
|
|
|
|
|
// find the largest component
|
|
// find the largest component
|
|
- float mc = SquishMath::fabs( m[0] );
|
|
|
|
|
|
+ float mc = std::fabs( m[0] );
|
|
int mi = 0;
|
|
int mi = 0;
|
|
for( int i = 1; i < 6; ++i )
|
|
for( int i = 1; i < 6; ++i )
|
|
{
|
|
{
|
|
- float c = SquishMath::fabs( m[i] );
|
|
|
|
|
|
+ float c = std::fabs( m[i] );
|
|
if( c > mc )
|
|
if( c > mc )
|
|
{
|
|
{
|
|
mc = c;
|
|
mc = c;
|
|
@@ -183,21 +184,21 @@ Vec3 ComputePrincipleComponent( Sym3x3 const& matrix )
|
|
else if( Q < -FLT_EPSILON )
|
|
else if( Q < -FLT_EPSILON )
|
|
{
|
|
{
|
|
// three distinct roots
|
|
// three distinct roots
|
|
- float theta = SquishMath::atan2( SquishMath::sqrt( -Q ), -0.5f*b );
|
|
|
|
- float rho = SquishMath::sqrt( 0.25f*b*b - Q );
|
|
|
|
|
|
+ float theta = std::atan2( std::sqrt( -Q ), -0.5f*b );
|
|
|
|
+ float rho = std::sqrt( 0.25f*b*b - Q );
|
|
|
|
|
|
- float rt = SquishMath::pow( rho, 1.0f/3.0f );
|
|
|
|
- float ct = SquishMath::cos( theta/3.0f );
|
|
|
|
- float st = SquishMath::sin( theta/3.0f );
|
|
|
|
|
|
+ float rt = std::pow( rho, 1.0f/3.0f );
|
|
|
|
+ float ct = std::cos( theta/3.0f );
|
|
|
|
+ float st = std::sin( theta/3.0f );
|
|
|
|
|
|
float l1 = ( 1.0f/3.0f )*c2 + 2.0f*rt*ct;
|
|
float l1 = ( 1.0f/3.0f )*c2 + 2.0f*rt*ct;
|
|
- float l2 = ( 1.0f/3.0f )*c2 - rt*( ct + ( float )SquishMath::sqrt( 3.0f )*st );
|
|
|
|
- float l3 = ( 1.0f/3.0f )*c2 - rt*( ct - ( float )SquishMath::sqrt( 3.0f )*st );
|
|
|
|
|
|
+ float l2 = ( 1.0f/3.0f )*c2 - rt*( ct + ( float )sqrt( 3.0f )*st );
|
|
|
|
+ float l3 = ( 1.0f/3.0f )*c2 - rt*( ct - ( float )sqrt( 3.0f )*st );
|
|
|
|
|
|
// pick the larger
|
|
// pick the larger
|
|
- if( SquishMath::fabs( l2 ) > SquishMath::fabs( l1 ) )
|
|
|
|
|
|
+ if( std::fabs( l2 ) > std::fabs( l1 ) )
|
|
l1 = l2;
|
|
l1 = l2;
|
|
- if( SquishMath::fabs( l3 ) > SquishMath::fabs( l1 ) )
|
|
|
|
|
|
+ if( std::fabs( l3 ) > std::fabs( l1 ) )
|
|
l1 = l3;
|
|
l1 = l3;
|
|
|
|
|
|
// get the eigenvector
|
|
// get the eigenvector
|
|
@@ -208,15 +209,15 @@ Vec3 ComputePrincipleComponent( Sym3x3 const& matrix )
|
|
// two roots
|
|
// two roots
|
|
float rt;
|
|
float rt;
|
|
if( b < 0.0f )
|
|
if( b < 0.0f )
|
|
- rt = -SquishMath::pow( -0.5f*b, 1.0f/3.0f );
|
|
|
|
|
|
+ rt = -std::pow( -0.5f*b, 1.0f/3.0f );
|
|
else
|
|
else
|
|
- rt = SquishMath::pow( 0.5f*b, 1.0f/3.0f );
|
|
|
|
|
|
+ rt = std::pow( 0.5f*b, 1.0f/3.0f );
|
|
|
|
|
|
float l1 = ( 1.0f/3.0f )*c2 + rt; // repeated
|
|
float l1 = ( 1.0f/3.0f )*c2 + rt; // repeated
|
|
float l2 = ( 1.0f/3.0f )*c2 - 2.0f*rt;
|
|
float l2 = ( 1.0f/3.0f )*c2 - 2.0f*rt;
|
|
|
|
|
|
// get the eigenvector
|
|
// get the eigenvector
|
|
- if( SquishMath::fabs( l1 ) > SquishMath::fabs( l2 ) )
|
|
|
|
|
|
+ if( std::fabs( l1 ) > std::fabs( l2 ) )
|
|
return GetMultiplicity2Evector( matrix, l1 );
|
|
return GetMultiplicity2Evector( matrix, l1 );
|
|
else
|
|
else
|
|
return GetMultiplicity1Evector( matrix, l2 );
|
|
return GetMultiplicity1Evector( matrix, l2 );
|