Update squish library to 1.11

This commit is contained in:
thecelloman 2013-03-04 14:37:50 -05:00
parent 31036c4031
commit 8de0b7cbb1
14 changed files with 99 additions and 247 deletions

View file

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