00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include "nvmath/Matnnf.h"
00018 #include "nvmath/Vec3f.h"
00019
00020 namespace nvmath
00021 {
00022 class Quatf;
00023
00025
00026 class Mat33f : public Matnnf<3>
00027 {
00028 public:
00030
00031 NVSG_API Mat33f( void );
00032
00034
00035 NVSG_API Mat33f( float a00, float a01, float a02
00036 , float a10, float a11, float a12
00037 , float a20, float a21, float a22 );
00038
00040
00041 NVSG_API Mat33f( const Vec3f &row0
00042 , const Vec3f &row1
00043 , const Vec3f &row2
00044 );
00045
00047
00048 NVSG_API Mat33f( const Vec3f &axis
00049 , float rad
00050 );
00051
00053
00054 NVSG_API Mat33f( const Quatf &quat
00055 );
00056
00058 NVSG_API Mat33f( const Matnnf<3> & m );
00059
00061 NVSG_API void set( const Vec3f &row0
00062 , const Vec3f &row1
00063 , const Vec3f &row2
00064 );
00065 };
00066
00067
00068
00069
00072 NVSG_API void decompose( const Mat33f &mat
00073 , Vec3f &scaling
00074 , Vec3f &shearing
00075 , Quatf &orientation
00076 );
00077
00081 inline float determinant( const Mat33f &mat
00082 )
00083 {
00084 return( mat[0][0] * ( mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1] )
00085 - mat[0][1] * ( mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0] )
00086 + mat[0][2] * ( mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0] ) );
00087 }
00088
00093 inline bool isRotation( const Mat33f &mat
00094 )
00095 {
00096 return( isNormalized( mat )
00097 && isOrthogonal( mat )
00098 && ( fabs( determinant( mat ) - 1.0f ) <= FLT_EPSILON ) );
00099 }
00100
00101
00102
00103
00104 inline Mat33f::Mat33f( void )
00105 {
00106 }
00107
00108 inline Mat33f::Mat33f( float a00, float a01, float a02
00109 , float a10, float a11, float a12
00110 , float a20, float a21, float a22 )
00111 {
00112 (*this)[0][0] = a00;
00113 (*this)[0][1] = a01;
00114 (*this)[0][2] = a02;
00115 (*this)[1][0] = a10;
00116 (*this)[1][1] = a11;
00117 (*this)[1][2] = a12;
00118 (*this)[2][0] = a20;
00119 (*this)[2][1] = a21;
00120 (*this)[2][2] = a22;
00121 }
00122
00123 inline Mat33f::Mat33f( const Vec3f &row0, const Vec3f &row1, const Vec3f &row2 )
00124 {
00125 set( row0, row1, row2 );
00126 }
00127
00128 inline Mat33f::Mat33f( const Vec3f &axis, float rad )
00129 {
00130 __ASSERT( isNormalized( axis ) );
00131 float c = cosf( rad );
00132 float s = sinf( rad );
00133 __ASSERT( fabs( s * s + c * c - 1.0f ) <= FLT_EPSILON );
00134 float t = 1 - c;
00135 float x = axis[0];
00136 float y = axis[1];
00137 float z = axis[2];
00138
00139 (*this)[0] = Vec3f( t * x * x + c, t * x * y - s * z, t * x * z + s * y );
00140 (*this)[1] = Vec3f( t * x * y + s * z, t * y * y + c, t * y * z - s * x );
00141 (*this)[2] = Vec3f( t * x * z - s * y, t * y * z + s * x, t * z * z + c );
00142
00143
00144 }
00145
00146 inline Mat33f::Mat33f( const Matnnf<3> &m )
00147 : Matnnf<3>( m )
00148 {
00149 }
00150
00151 inline void Mat33f::set( const Vec3f &row0, const Vec3f &row1, const Vec3f &row2 )
00152 {
00153 (*this)[0]=row0;
00154 (*this)[1]=row1;
00155 (*this)[2]=row2;
00156 }
00157
00158 }