From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02851.html | 4409 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 4409 insertions(+) create mode 100644 docs/doxygen/nel/a02851.html (limited to 'docs/doxygen/nel/a02851.html') diff --git a/docs/doxygen/nel/a02851.html b/docs/doxygen/nel/a02851.html new file mode 100644 index 00000000..9e438d39 --- /dev/null +++ b/docs/doxygen/nel/a02851.html @@ -0,0 +1,4409 @@ + + +NeL: NLMISC::CMatrix class Reference + + + +
+

NLMISC::CMatrix Class Reference

#include <matrix.h> +

+


Detailed Description

+A 4*4 Homogenous Matrix. This is a column matrix, so operations like: v1=A*B*C*v0; applies C first , then B, then A to vector v0.
+ Since it is a column matrix, the first column is the I vector of the base, 2nd is J, 3th is K.
+ 4th column vector is T, the translation vector.

+Angle orientation are: Xaxis: YtoZ. Yaxis: ZtoX. Zaxis: XtoY.

+This matrix keep a matrix state to improve Matrix, vector and plane computing (matrix inversion, vector multiplication...). The internal matrix know if:

+

+An example of improvement is that CMatrix::operator*(const CVector &v) return v if the matrix is identity.

+By default, a matrix is identity. But for a performance view, this is just a StateBit=0...

Author:
Lionel Berenguier

+Nevrax France

+
Date:
2000
+ +

+ +

+Definition at line 66 of file matrix.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Types

enum  TRotOrder {
+  XYZ, +XZY, +YXZ, +YZX, +
+  ZXY, +ZYX +
+ }
 Rotation Order. More...


Public Member Functions

Object
 CMatrix (const CMatrix &)
 Copy Constructor.

 CMatrix ()
 Constructor which init to identity().

CMatrixoperator= (const CMatrix &)
 operator=.

Gets.
const float * get () const
void get (float m44[16]) const
CVector getI () const
 Get the I vector of the Rotation/Scale matrix (base).

CVector getJ () const
 Get the J vector of the Rotation/Scale matrix (base).

CVector getK () const
 Get the K vector of the Rotation/Scale matrix (base).

const CVectorgetPos () const
void getPos (CVector &v) const
void getProj (float proj[4]) const
CQuat getRot () const
void getRot (CQuat &quat) const
void getRot (float m33[9]) const
void getRot (CVector &i, CVector &j, CVector &k) const
Misc
float getScaleUniform () const
 return true the uniform scale. valid only if hasScaleUniform() is true, else 1 is returned.

bool hasProjectionPart () const
 return true if the matrix has a projection part (by setProj(), by multiplication etc...)

bool hasScalePart () const
 return true if the matrix has a scale part (by scale(), by multiplication etc...)

bool hasScaleUniform () const
 return true if hasScalePart() and if if this scale is uniform.

void serial (IStream &f)
 return true the uniform scale. valid only if hasScaleUniform() is true, else 1 is returned.

Sets
void identity ()
 Reset the matrix to identity.

void movePos (const CVector &v)
void resetProj ()
void set (const float m44[16])
void setPos (const CVector &v)
void setProj (const float proj[4])
void setRot (const CMatrix &matrix)
void setRot (const CQuat &quat)
void setRot (const CVector &v, TRotOrder ro)
void setRot (const float m33[9], bool hintNoScale=false)
void setRot (const CVector &i, const CVector &j, const CVector &k, bool hintNoScale=false)
void setScale (const CVector &v)
void setScale (float scale)
Matrix Operations.
void invert ()
CMatrix inverted () const
bool normalize (TRotOrder pref)
CMatrix operator * (const CMatrix &in) const
 Matrix multiplication.

CMatrixoperator *= (const CMatrix &in)
 equivalent to M=M*in

void setMulMatrix (const CMatrix &m1, const CMatrix &m2)
void setMulMatrixNoProj (const CMatrix &m1, const CMatrix &m2)
void transpose ()
void transpose3x3 ()
CVector mulPoint (const CVector &v) const
 Multiply a point. ie v.w=1 so the Translation component do affect result. Projection doesn't affect result.

CVector mulVector (const CVector &v) const
 Multiply a normal. ie v.w=0 so the Translation component doesn't affect result. Projection doesn't affect result.

CVectorH operator * (const CVectorH &v) const
 Multiply with an homogenous vector.

CVector operator * (const CVector &v) const
 Multiply a point. mulPoint.

3D Operations.
void rotate (const CQuat &quat)
void rotate (const CVector &v, TRotOrder ro)
void rotateX (float a)
void rotateY (float a)
void rotateZ (float a)
void scale (const CVector &scale)
 Apply a non-uniform scale to the matrix.

void scale (float f)
 Apply a uniform scale to the matrix.

void translate (const CVector &v)
 Apply a translation to the matrix. same as M=M*T.


Static Public Attributes

const CMatrix Identity
 The identity matrix. Same as CMatrix().


Private Member Functions

void fastInvert33 (CMatrix &ret) const
void getCofactIndex (sint i, sint &l1, sint &l2, sint &l3) const
bool hasAll () const
bool hasProj () const
bool hasRot () const
bool hasTrans () const
const float & mat (sint i, sint j) const
float & mat (sint i, sint j)
void setScaleUni (float scale)
bool slowInvert33 (CMatrix &ret) const
bool slowInvert44 (CMatrix &ret) const
void testExpandProj () const
void testExpandRot () const

Private Attributes

float M [16]
float Scale33
uint32 StateBit

Friends

CPlane operator * (const CPlane &p, const CMatrix &m)
 Plane (line vector) multiplication.

+


Member Enumeration Documentation

+

+ + + + +
+ + +
enum NLMISC::CMatrix::TRotOrder +
+
+ + + + + +
+   + + +

+Rotation Order. +

+

Enumeration values:
+ + + + + + + +
XYZ  +
XZY  +
YXZ  +
YZX  +
ZXY  +
ZYX  +
+
+ +

+Definition at line 70 of file matrix.h. +

+

00071         {
+00072                 XYZ,
+00073                 XZY,
+00074                 YXZ,
+00075                 YZX,
+00076                 ZXY,
+00077                 ZYX
+00078         };
+
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
NLMISC::CMatrix::CMatrix  )  [inline]
+
+ + + + + +
+   + + +

+Constructor which init to identity(). +

+ +

+Definition at line 88 of file matrix.h. +

+References StateBit. +

+

00089         {
+00090                 StateBit= 0;
+00091                 // Init just Pos because must always be valid for faster getPos()
+00092                 M[12]= M[13]= M[14]= 0;
+00093         }
+
+

+ + + + +
+ + + + + + + + + + +
NLMISC::CMatrix::CMatrix const CMatrix  ) 
+
+ + + + + +
+   + + +

+Copy Constructor. +

+ +

+Definition at line 163 of file matrix.cpp. +

+

00164 {
+00165         (*this)= m;
+00166 }
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::fastInvert33 CMatrix ret  )  const [private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 969 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, MAT_SCALEUNI, s, Scale33, and StateBit. +

+Referenced by inverted(). +

+

00970 {
+00971         // Fast invert of 3x3 rot matrix.
+00972         // Work if no scale and if MAT_SCALEUNI. doesn't work if MAT_SCALEANY.
+00973 
+00974         if(StateBit & MAT_SCALEUNI)
+00975         {
+00976                 double  s,S;    // important for precision.
+00977                 // Must divide the matrix by 1/Scale 2 times, to set unit, and to have a Scale=1/Scale.
+00978                 S=1.0/Scale33;
+00979                 ret.Scale33= (float)S;
+00980                 s=S*S;
+00981                 // The matrix is a base, so just transpose it.
+00982                 ret.a11= (float)(a11*s); ret.a12= (float)(a21*s); ret.a13= (float)(a31*s);
+00983                 ret.a21= (float)(a12*s); ret.a22= (float)(a22*s); ret.a23= (float)(a32*s);
+00984                 ret.a31= (float)(a13*s); ret.a32= (float)(a23*s); ret.a33= (float)(a33*s);
+00985         }
+00986         else
+00987         {
+00988                 ret.Scale33=1;
+00989                 // The matrix is a base, so just transpose it.
+00990                 ret.a11= a11; ret.a12= a21; ret.a13=a31;
+00991                 ret.a21= a12; ret.a22= a22; ret.a23=a32;
+00992                 ret.a31= a13; ret.a32= a23; ret.a33=a33;
+00993         }
+00994 
+00995         // 15 cycles if no scale.
+00996         // 35 cycles if scale.
+00997 }
+
+

+ + + + +
+ + + + + + + + + +
const float * NLMISC::CMatrix::get  )  const
+
+ + + + + +
+   + + +

+Get 4*4 matrix.

Returns:
the matrix's 4*4 column matrix (4x4 matrix stored in column-major order as 16 consecutive values)
+ +

+Definition at line 451 of file matrix.cpp. +

+References testExpandProj(), and testExpandRot(). +

+

00452 {
+00453         testExpandRot();
+00454         testExpandProj();
+00455         return M;
+00456 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::get float  m44[16]  )  const
+
+ + + + + +
+   + + +

+Get 4*4 matrix.

Parameters:
+ + +
m44 the matrix's 4*4 column matrix (4x4 matrix stored in column-major order as 16 consecutive values)
+
+ +

+Definition at line 443 of file matrix.cpp. +

+References testExpandProj(), and testExpandRot(). +

+Referenced by NL3D::CLodCharacterManager::addRenderCharacterKey(), NL3D::CDriverGL::cleanLightSetup(), NL3D::CDriverGL::doRefreshRenderSetup(), NL3D::CMatrix3x4::set(), NL3D::CDriverGL::setConstantMatrix(), NL3D::CDriverGL::setupSpecularBegin(), and NL3D::CDriverGL::setupUserTextureMatrix(). +

+

00444 {
+00445         // \todo yoyo: TODO_OPTIMIZE_it.
+00446         testExpandRot();
+00447         testExpandProj();
+00448         memcpy(m44, M, 16*sizeof(float));
+00449 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::getCofactIndex sint  i,
sint l1,
sint l2,
sint l3
const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 372 of file matrix.h. +

+References sint. +

+Referenced by slowInvert44(). +

+

00373         {
+00374                 switch(i)
+00375                 {
+00376                         case 0: l1=1; l2=2; l3=3; break;
+00377                         case 1: l1=0; l2=2; l3=3; break;
+00378                         case 2: l1=0; l2=1; l3=3; break;
+00379                         case 3: l1=0; l2=1; l3=2; break;
+00380                 }
+00381         }
+
+

+ + + + +
+ + + + + + + + + +
CVector NLMISC::CMatrix::getI  )  const
+
+ + + + + +
+   + + +

+Get the I vector of the Rotation/Scale matrix (base). +

+ +

+Definition at line 419 of file matrix.cpp. +

+References a11, a21, a31, and hasRot(). +

+Referenced by NLMISC::CBSphere::applyTransform(), NL3D::CShadowMap::buildCasterCameraMatrix(), NL3D::CShadowMap::buildClipInfoFromMatrix(), NL3D::CShadowMap::buildProjectionInfos(), NL3D::CPSLocated::computeI(), NL3D::CPlaneBasis::CPlaneBasis(), NL3D::CMaterial::decompUserTexMat(), NL3D::CPSUtil::displayBasis(), NL3D::CPSUtil::displayCylinder(), NL3D::CPSUtil::displayDisc(), NL3D::CBone::interpolateBoneSkinMatrix(), NL3D::CZoneLighter::light(), normalize(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CQuadTree< T >::selectSegment(), NL3D::CPSZoneRectangle::setMatrix(), NL3D::CPSZoneCylinder::setMatrix(), NL3D::CPSEmitterRectangle::setMatrix(), NL3D::CPSZonePlane::show(), slowInvert33(), NL3D::CWaterModel::traverseRender(), NL3D::CFlareModel::traverseRender(), NL3D::CWaterModel::updateDiffuseMapMatrix(), and NL3D::CSpinnerFunctor::updateSamples(). +

+

00420 {
+00421         if(hasRot())
+00422                 return CVector(a11, a21, a31);
+00423         else
+00424                 return CVector(1, 0, 0);
+00425 }
+
+

+ + + + +
+ + + + + + + + + +
CVector NLMISC::CMatrix::getJ  )  const
+
+ + + + + +
+   + + +

+Get the J vector of the Rotation/Scale matrix (base). +

+ +

+Definition at line 427 of file matrix.cpp. +

+References a12, a22, a32, and hasRot(). +

+Referenced by NLMISC::CBSphere::applyTransform(), NL3D::CShadowMap::buildCasterCameraMatrix(), NL3D::CShadowMap::buildClipInfoFromMatrix(), NL3D::CShadowMap::buildProjectionInfos(), NL3D::CPSLocated::computeJ(), NL3D::CPlaneBasis::CPlaneBasis(), NL3D::CVegetableQuadrant::CVegetableQuadrant(), NL3D::CMaterial::decompUserTexMat(), NL3D::CPSUtil::displayBasis(), NL3D::CPSUtil::displayCylinder(), NL3D::CPSUtil::displayDisc(), NL3D::CParticleSystem::getLOD(), NL3D::CParticleSystem::getLODVect(), NL3D::CTessFacePriorityList::init(), NL3D::CBone::interpolateBoneSkinMatrix(), NL3D::CZoneLighter::light(), normalize(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CQuadTree< T >::selectRay(), NL3D::CQuadTree< T >::selectSegment(), NL3D::CPSZoneRectangle::setMatrix(), NL3D::CPSZoneCylinder::setMatrix(), NL3D::CPSEmitterRectangle::setMatrix(), NL3D::CPSZonePlane::show(), slowInvert33(), NL3D::CPointLightModel::traverseLight(), NL3D::CWaterModel::traverseRender(), NL3D::CFlareModel::traverseRender(), NL3D::CWaterModel::updateDiffuseMapMatrix(), and NL3D::CSpinnerFunctor::updateSamples(). +

+

00428 {
+00429         if(hasRot())
+00430                 return CVector(a12, a22, a32);
+00431         else
+00432                 return CVector(0, 1, 0);
+00433 }
+
+

+ + + + +
+ + + + + + + + + +
CVector NLMISC::CMatrix::getK  )  const
+
+ + + + + +
+   + + +

+Get the K vector of the Rotation/Scale matrix (base). +

+ +

+Definition at line 435 of file matrix.cpp. +

+References a13, a23, a33, and hasRot(). +

+Referenced by NLMISC::CBSphere::applyTransform(), NL3D::CShadowMap::buildCasterCameraMatrix(), NL3D::CShadowMap::buildClipInfoFromMatrix(), NL3D::CShadowMap::buildProjectionInfos(), NL3D::CPSLocated::computeK(), NL3D::CMaterial::decompUserTexMat(), NL3D::CPSUtil::displayBasis(), NL3D::CPSUtil::displayCylinder(), NL3D::CBone::interpolateBoneSkinMatrix(), normalize(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CQuadTree< T >::selectRay(), NL3D::CQuadTree< T >::selectSegment(), NL3D::CPSZoneDisc::setMatrix(), NL3D::CPSZonePlane::setMatrix(), NL3D::CPSCylindricVortex::setMatrix(), slowInvert33(), NL3D::CWaterModel::traverseRender(), NL3D::CFlareModel::traverseRender(), and NL3D::CWaterModel::updateDiffuseMapMatrix(). +

+

00436 {
+00437         if(hasRot())
+00438                 return CVector(a13, a23, a33);
+00439         else
+00440                 return CVector(0, 0, 1);
+00441 }
+
+

+ + + + +
+ + + + + + + + + + +
const CVector& NLMISC::CMatrix::getPos void   )  const [inline]
+
+ + + + + +
+   + + +

+Get the Translation component. NB: a const & works because it is a column vector

Returns:
the matrix's translation vector.
+ +

+Definition at line 203 of file matrix.h. +

+

00203 {return *(CVector*)(M+12);}
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::getPos CVector v  )  const [inline]
+
+ + + + + +
+   + + +

+Get the Translation component.

Parameters:
+ + +
v the matrix's translation vector.
+
+ +

+Definition at line 198 of file matrix.h. +

+References v. +

+Referenced by NL3D::CLightingManager::addDynamicLight(), NL3D::CVegetableManager::addInstance(), NL3D::CLodCharacterManager::addRenderCharacterKey(), NL3D::CShadowMap::buildClipInfoFromMatrix(), NL3D::CShadowMap::buildProjectionInfos(), NL3D::CWaveMakerShape::clip(), NL3D::CTransformShape::clip(), NL3D::CFlareShape::clip(), NL3D::CClipTrav::clipSkeletonShadowMaps(), NL3D::CBone::compute(), NL3D::CSkeletonModel::computeDisplayLodCharacterPriority(), NL3D::CShadowMapManager::computeShadowDirection(), NL3D::CMaterial::decompUserTexMat(), NL3D::CPSUtil::displayBasis(), NL3D::CWaterModel::doSimpleRender(), NL3D::CVegetable::generateInstance(), NL3D::CSkeletonModel::generateShadowMap(), NL3D::CWaterModel::getAttenuatedHeight(), NL3D::CTransformShape::getLightHotSpotInWorld(), NL3D::CSkeletonModel::getLightHotSpotInWorld(), NL3D::CParticleSystem::getLOD(), NL3D::CParticleSystem::getLODVect(), NL3D::CViewport::getRayWithPoint(), NL3D::CEvent3dMouseListener::getViewMatrix(), H_AUTO_DECL(), NL3D::CLightingManager::insertStaticLightedModel(), NL3D::CBone::interpolateBoneSkinMatrix(), NL3D::CParticleSystem::interpolateFXPosDelta(), NL3D::CParticleSystem::interpolateUserPosDelta(), NL3D::ITransformable::lookAt(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CPSZoneSphere::performMotion(), NL3D::CParticleSystemModel::refreshRscDeletion(), NL3D::CSkeletonModel::renderCLod(), NL3D::CSkeletonModel::renderIntoSkeletonShadowMap(), NL3D::CMeshInstance::renderIntoSkeletonShadowMap(), NL3D::CShadowMapManager::renderProject(), NL3D::CShadowMapManager::selectShadowMapsToGenerate(), NL3D::CPSZoneRectangle::setMatrix(), NL3D::CPSZoneCylinder::setMatrix(), NL3D::CPSZoneDisc::setMatrix(), NL3D::CPSZoneSphere::setMatrix(), NL3D::CPSZonePlane::setMatrix(), NL3D::CPSCylindricVortex::setMatrix(), NL3D::CPSSphericalEmitter::setMatrix(), NL3D::CPSEmitterRectangle::setMatrix(), NL3D::CParticleSystem::setNumTris(), NL3D::CParticleSystem::setSysMat(), NL3D::CDriverGL::setupModelMatrix(), NL3D::CParticleSystem::setUserMatrix(), NL3D::CParticleSystem::step(), NL3D::CRenderTrav::traverse(), NL3D::CWaveMakerModel::traverseAnimDetail(), NL3D::CSkeletonModel::traverseAnimDetail(), NL3D::CParticleSystemModel::traverseClip(), NL3D::CTransformShape::traverseLoadBalancingPass0(), NL3D::CWaterModel::traverseRender(), NL3D::CFlareModel::traverseRender(), NL3D::CTravCameraScene::update(), NL3D::CWaterModel::updateDiffuseMapMatrix(), and NL3D::CParticleSystem::updateLODRatio(). +

+

00198 {v.x= M[12]; v.y= M[13]; v.z= M[14];}
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::getProj float  proj[4]  )  const
+
+ + + + + +
+   + + +

+Get the Projection component.

Parameters:
+ + +
proj the matrix's projection vector.
+
+ +

+Definition at line 401 of file matrix.cpp. +

+References a41, a42, a43, a44, and hasProj(). +

+

00402 {
+00403         if(hasProj())
+00404         {
+00405                 proj[0]= a41;
+00406                 proj[1]= a42;
+00407                 proj[2]= a43;
+00408                 proj[3]= a44;
+00409         }
+00410         else
+00411         {
+00412                 proj[0]= 0;
+00413                 proj[1]= 0;
+00414                 proj[2]= 0;
+00415                 proj[3]= 1;
+00416         }
+00417 }
+
+

+ + + + +
+ + + + + + + + + +
CQuat NLMISC::CMatrix::getRot  )  const [inline]
+
+ + + + + +
+   + + +

+Get the Rotation matrix (base).

Parameters:
+ + +
quat the return quaternion.
+
+ +

+Definition at line 194 of file matrix.h. +

+

00194 {CQuat  ret; getRot(ret); return ret;}
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::getRot CQuat quat  )  const
+
+ + + + + +
+   + + +

+Get the Rotation matrix (base).

Parameters:
+ + +
quat the return quaternion.
+
+ +

+Definition at line 1386 of file matrix.cpp. +

+References mat(), MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, normalize(), q, s, sint, StateBit, NLMISC::CQuatT< float >::w, NLMISC::CQuatT< float >::x, NLMISC::CQuatT< float >::y, NLMISC::CQuatT< float >::z, and ZYX. +

+

01387 {
+01388         const CMatrix   *pmat= this;
+01389         CMatrix                 MatNormed;
+01390 
+01391 
+01392         // Rot Indentity?
+01393         if(! (StateBit & MAT_ROT))
+01394         {
+01395                 quat= CQuat::Identity;
+01396                 return;
+01397         }
+01398 
+01399         // Must normalize the matrix??
+01400         if(StateBit & (MAT_SCALEUNI | MAT_SCALEANY) )
+01401         {
+01402                 MatNormed= *this;
+01403                 MatNormed.normalize(ZYX);
+01404                 pmat= &MatNormed;
+01405         }
+01406 
+01407         // Compute quaternion.
+01408         float  tr, s, q[4];
+01409 
+01410         tr = pmat->a11 + pmat->a22 + pmat->a33;
+01411 
+01412         // check the diagonal
+01413         if (tr > 0.0)
+01414         {
+01415                 s = (float)sqrt (tr + 1.0f);
+01416                 quat.w = s / 2.0f;
+01417                 s = 0.5f / s;
+01418                 quat.x = (pmat->a32 - pmat->a23) * s;
+01419                 quat.y = (pmat->a13 - pmat->a31) * s;
+01420                 quat.z = (pmat->a21 - pmat->a12) * s;
+01421         }
+01422         else
+01423         {               
+01424                 sint    i, j, k;
+01425                 sint    nxt[3] = {1, 2, 0};
+01426 
+01427                 // diagonal is negative
+01428                 i = 0;
+01429                 if (pmat->a22 > pmat->a11) i = 1;
+01430                 if (pmat->a33 > pmat->mat(i,i) ) i = 2;
+01431                 j = nxt[i];
+01432                 k = nxt[j];
+01433 
+01434                 s = (float) sqrt (  (pmat->mat(i,i) - (pmat->mat(j,j) + pmat->mat(k,k)) )   + 1.0);
+01435 
+01436                 q[i] = s * 0.5f;
+01437 
+01438                 if (s != 0.0f) s = 0.5f / s;
+01439 
+01440                 q[j] = (pmat->mat(j,i) + pmat->mat(i,j)) * s;
+01441                 q[k] = (pmat->mat(k,i) + pmat->mat(i,k)) * s;
+01442                 q[3] =   (pmat->mat(k,j) - pmat->mat(j,k)) * s;
+01443 
+01444                 quat.x = q[0];
+01445                 quat.y = q[1];
+01446                 quat.z = q[2];
+01447                 quat.w = q[3];
+01448         }
+01449 
+01450 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::getRot float  m33[9]  )  const
+
+ + + + + +
+   + + +

+Get the Rotation/Scale matrix (base).

Parameters:
+ + +
m33 the matrix's 3*3 column rotation matrix. (3x3 matrix stored in column-major order as 9 consecutive values)
+
+ +

+Definition at line 369 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, and hasRot(). +

+

00370 {
+00371         if(hasRot())
+00372         {
+00373                 m33[0]= a11;
+00374                 m33[1]= a21;
+00375                 m33[2]= a31;
+00376 
+00377                 m33[3]= a12;
+00378                 m33[4]= a22;
+00379                 m33[5]= a32;
+00380 
+00381                 m33[6]= a13;
+00382                 m33[7]= a23;
+00383                 m33[8]= a33;
+00384         }
+00385         else
+00386         {
+00387                 m33[0]= 1;
+00388                 m33[1]= 0;
+00389                 m33[2]= 0;
+00390 
+00391                 m33[3]= 0;
+00392                 m33[4]= 1;
+00393                 m33[5]= 0;
+00394 
+00395                 m33[6]= 0;
+00396                 m33[7]= 0;
+00397                 m33[8]= 1;
+00398         }
+00399 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::getRot CVector i,
CVector j,
CVector k
const
+
+ + + + + +
+   + + +

+Get the Rotation/Scale matrix (base).

Parameters:
+ + + + +
i The matrix's I vector of the cartesian base.
j The matrix's J vector of the cartesian base.
k The matrix's K vector of the cartesian base.
+
+ +

+Definition at line 353 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, hasRot(), and NLMISC::CVector::set(). +

+Referenced by NL3D::ComputeUpMatrix(), NL3D::CTargetAnimCtrl::execute(), NL3D::CTargetAnimCtrl::getCurrentLSRotationFromBone(), NL3D::ITransformable::lookAt(), and setRot(). +

+

00354 {
+00355         if(hasRot())
+00356         {
+00357                 i.set(a11, a21, a31);
+00358                 j.set(a12, a22, a32);
+00359                 k.set(a13, a23, a33);
+00360         }
+00361         else
+00362         {
+00363                 i.set(1, 0, 0);
+00364                 j.set(0, 1, 0);
+00365                 k.set(0, 0, 1);
+00366         }
+00367 }
+
+

+ + + + +
+ + + + + + + + + +
float NLMISC::CMatrix::getScaleUniform  )  const
+
+ + + + + +
+   + + +

+return true the uniform scale. valid only if hasScaleUniform() is true, else 1 is returned. +

+ +

+Definition at line 106 of file matrix.cpp. +

+References hasScaleUniform(), and Scale33. +

+Referenced by NLMISC::CBSphere::applyTransform(). +

+

00107 {
+00108         if(hasScaleUniform())
+00109                 return Scale33;
+00110         else
+00111                 return 1;
+00112 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasAll  )  const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 129 of file matrix.cpp. +

+References hasProj(), hasRot(), and hasTrans(). +

+Referenced by operator=(). +

+

00130 {
+00131         return (hasRot() && hasTrans() && hasProj());
+00132 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasProj  )  const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 125 of file matrix.cpp. +

+References MAT_PROJ, and StateBit. +

+Referenced by getProj(), hasAll(), operator=(), rotateX(), rotateY(), rotateZ(), scale(), serial(), setMulMatrix(), testExpandProj(), translate(), and transpose(). +

+

00126 {
+00127         return (StateBit&MAT_PROJ)!=0;
+00128 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasProjectionPart  )  const
+
+ + + + + +
+   + + +

+return true if the matrix has a projection part (by setProj(), by multiplication etc...) +

+ +

+Definition at line 96 of file matrix.cpp. +

+References MAT_PROJ, and StateBit. +

+

00097 {
+00098         return (StateBit&MAT_PROJ)!=0;
+00099 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasRot  )  const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 117 of file matrix.cpp. +

+References MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, and StateBit. +

+Referenced by getI(), getJ(), getK(), getRot(), hasAll(), mulPoint(), mulVector(), operator=(), rotateX(), rotateY(), serial(), setMulMatrix(), setRot(), testExpandRot(), translate(), and transpose3x3(). +

+

00118 {
+00119         return (StateBit&(MAT_ROT|MAT_SCALEUNI|MAT_SCALEANY))!=0;
+00120 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasScalePart  )  const
+
+ + + + + +
+   + + +

+return true if the matrix has a scale part (by scale(), by multiplication etc...) +

+ +

+Definition at line 92 of file matrix.cpp. +

+References MAT_SCALEANY, MAT_SCALEUNI, and StateBit. +

+Referenced by NLMISC::CBSphere::applyTransform(), and NL3D::CDriverGL::doRefreshRenderSetup(). +

+

00093 {
+00094         return (StateBit&(MAT_SCALEUNI|MAT_SCALEANY))!=0;
+00095 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasScaleUniform  )  const
+
+ + + + + +
+   + + +

+return true if hasScalePart() and if if this scale is uniform. +

+ +

+Definition at line 102 of file matrix.cpp. +

+References MAT_SCALEANY, MAT_SCALEUNI, and StateBit. +

+Referenced by NLMISC::CBSphere::applyTransform(), getScaleUniform(), setMulMatrixNoProj(), and setRot(). +

+

00103 {
+00104         return (StateBit & (MAT_SCALEUNI|MAT_SCALEANY))== MAT_SCALEUNI;
+00105 }
+
+

+ + + + +
+ + + + + + + + + +
bool NLMISC::CMatrix::hasTrans  )  const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 121 of file matrix.cpp. +

+References MAT_TRANS, and StateBit. +

+Referenced by hasAll(), mulPoint(), serial(), setMulMatrix(), and transpose(). +

+

00122 {
+00123         return (StateBit&MAT_TRANS)!=0;
+00124 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::identity  ) 
+
+ + + + + +
+   + + +

+Reset the matrix to identity. +

+ +

+Definition at line 200 of file matrix.cpp. +

+References a14, a24, a34, MAT_IDENTITY, and StateBit. +

+Referenced by NLLIGO::CZoneEdge::buildMatrix(), NL3D::CCloud::calcBill(), NL3D::CCubeGrid< TCell >::CCubeGrid(), NL3D::CEvent3dMouseListener::CEvent3dMouseListener(), NL3D::CStaticQuadGrid< T >::clear(), NL3D::CLandscapeModel::clipAndRenderLandscape(), NLPACS::CQuadGrid< T >::CQuadGrid(), NL3D::CQuadGrid< T >::CQuadGrid(), NL3D::CQuadTree< T >::CQuadTree(), NL3D::CStaticQuadGrid< T >::CStaticQuadGrid(), NL3D::CTransform::CTransform(), NL3D::CTravCameraScene::CTravCameraScene(), NL3D::CCloud::disp(), NL3D::CDRU::drawBitmap(), NL3D::CDRU::drawLine(), NL3D::CPSConstraintMeshHelper::drawMeshs(), NL3D::CDRU::drawQuad(), NL3D::CDRU::drawTriangle(), NL3D::CCloud::genBill(), NL3D::CInstanceGroup::getInstanceMatrix(), NL3D::CPSZoneSphere::getMatrix(), NL3D::CPSSphericalEmitter::getMatrix(), NL3D::CWaterShape::getShapeInWorldSpace(), InitZBuffer(), inverted(), NL3D::ITransformable::lookAt(), NL3D::CPSConstraintMesh::makePrerotatedVb(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CVegetableManager::render(), rotate(), NL3D::CQuadTree< T >::selectRay(), NL3D::CQuadTree< T >::selectSegment(), serial(), NL3D::CDriverUser::setMatrixMode2D(), NL3D::CCloud::setMode2D(), setMulMatrix(), setRot(), NL3D::CDriverGL::setupViewMatrix(), NL3D::CDriverGL::setupViewMatrixEx(), NL3D::CPSGravity::show(), NL3D::ITransformable::updateMatrix(), and NL3D::CPSMesh::updatePos(). +

+

00201 {
+00202         StateBit= MAT_IDENTITY;
+00203         // Reset just Pos because must always be valid for faster getPos()
+00204         a14= a24= a34= 0;
+00205         // For optimisation it would be usefull to keep MAT_VALID states.
+00206         // But this slows identity(), and this may not be interesting...
+00207 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::invert  ) 
+
+ + + + + +
+   + + +

+Invert the matrix. if the matrix can't be inverted, it is set to identity. +

+Definition at line 914 of file matrix.cpp. +

+References inverted(). +

+Referenced by NL3D::CVegetableManager::addInstance(), NL3D::CCluster::applyMatrix(), NL3D::CCamera::buildCameraPyramid(), NL3D::CCloud::calcBill(), NL3D::CLodCharacterManager::CLodCharacterManager(), CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::compile(), NL3D::CMaterial::decompUserTexMat(), NL3D::CCloud::genBill(), InitZBuffer(), NL3D::CZoneLighter::light(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CCloudScape::render(), NL3D::CShadowMapManager::renderProject(), NL3D::CDriverGL::setConstantMatrix(), NL3D::CDriverUser::setMatrixMode3D(), NL3D::CLodCharacterManager::setupNormalCorrectionMatrix(), NL3D::CMeshVPWindTree::setupPerInstanceConstants(), NL3D::CDriverGL::setupViewMatrix(), NL3D::CDriverGL::setupViewMatrixEx(), NL3D::CCluster::setWorldMatrix(), and NLMISC::CPolygon::toConvexPolygonsLocalAndBSP(). +

+

00915 {
+00916 
+00917         *this= inverted();
+00918 }
+
+

+ + + + +
+ + + + + + + + + +
CMatrix NLMISC::CMatrix::inverted  )  const
+
+ + + + + +
+   + + +

+Return the matrix inverted. if the matrix can't be inverted, identity is returned. +

+Definition at line 1090 of file matrix.cpp. +

+References a14, a24, a34, fastInvert33(), identity(), MAT_PROJ, MAT_ROT, MAT_SCALEANY, MAT_TRANS, slowInvert33(), slowInvert44(), StateBit, testExpandProj(), and testExpandRot(). +

+Referenced by NL3D::CMeshGeom::activeInstance(), NL3D::CStaticQuadGrid< T >::build(), NL3D::CShadowMap::buildCasterCameraMatrix(), NL3D::CInstanceLighter::computeSunContribution(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CSkeletonModel::generateShadowMap(), NL3D::CMeshInstance::generateShadowMap(), invert(), NL3D::CZoneLighter::lightWater(), NL3D::CHeatHaze::performHeatHaze(), NL3D::CMeshMRMGeom::render(), NL3D::CMeshGeom::render(), NL3D::CMeshMRMGeom::renderSkin(), NL3D::CMeshGeom::renderSkin(), NL3D::CParticleSystem::setSysMat(), NL3D::CParticleSystem::setUserMatrix(), NL3D::CParticleSystem::setViewMat(), NL3D::CWaterModel::traverseRender(), NL3D::CTravCameraScene::update(), and NL3D::CWaterModel::updateDiffuseMapMatrix(). +

+

01091 {
+01092 
+01093         CMatrix ret;
+01094 
+01095         // \todo yoyo: TODO_OPTIMIZE it...
+01096         testExpandRot();
+01097         testExpandProj();
+01098 
+01099         // Do a conventionnal 44 inversion.
+01100         //=================================
+01101         if(StateBit & MAT_PROJ)
+01102         {
+01103                 if(!slowInvert44(ret))
+01104                 {
+01105                         ret.identity();
+01106                         return ret;
+01107                 }
+01108 
+01109                 // Well, don't know what happens to matrix, so set all StateBit :).
+01110                 ret.StateBit= MAT_TRANS|MAT_ROT|MAT_SCALEANY|MAT_PROJ;
+01111 
+01112                 // Check Trans state.
+01113                 if(ret.a14!=0 || ret.a24!=0 || ret.a34!=0)
+01114                         ret.StateBit|= MAT_TRANS;
+01115                 else
+01116                         ret.StateBit&= ~MAT_TRANS;
+01117 
+01118                 // Check Proj state.
+01119                 if(ret.a41!=0 || ret.a42!=0 || ret.a43!=0 || ret.a44!=1)
+01120                         ret.StateBit|= MAT_PROJ;
+01121                 else
+01122                         ret.StateBit&= ~MAT_PROJ;
+01123         }
+01124 
+01125         // Do a speed 34 inversion.
+01126         //=========================
+01127         else
+01128         {
+01129                 // Invert the rotation part.
+01130                 if(StateBit & MAT_SCALEANY)
+01131                 {
+01132                         if(!slowInvert33(ret))
+01133                         {
+01134                                 ret.identity();
+01135                                 return ret;
+01136                         }
+01137                 }
+01138                 else
+01139                         fastInvert33(ret);
+01140                 // Scale33 is updated in fastInvert33().
+01141 
+01142                 // Invert the translation part.
+01143                 if(StateBit & MAT_TRANS)
+01144                 {
+01145                         // Invert the translation part.
+01146                         // This can only work if 4th line is 0 0 0 1.
+01147                         // formula: InvVp= InvVi*(-Vp.x) + InvVj*(-Vp.y) + InvVk*(-Vp.z)
+01148                         ret.a14= ret.a11*(-a14) + ret.a12*(-a24) + ret.a13*(-a34);
+01149                         ret.a24= ret.a21*(-a14) + ret.a22*(-a24) + ret.a23*(-a34);
+01150                         ret.a34= ret.a31*(-a14) + ret.a32*(-a24) + ret.a33*(-a34);
+01151                 }
+01152                 else
+01153                 {
+01154                         ret.a14= 0;
+01155                         ret.a24= 0;
+01156                         ret.a34= 0;
+01157                 }
+01158 
+01159                 // The projection part is unmodified.
+01160                 ret.a41= 0; ret.a42= 0; ret.a43= 0; ret.a44= 1;
+01161 
+01162                 // The matrix inverted keep the same state bits.
+01163                 ret.StateBit= StateBit;
+01164         }
+01165         
+01166         
+01167         return ret;
+01168 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
const float& NLMISC::CMatrix::mat sint  i,
sint  j
const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 367 of file matrix.h. +

+References sint. +

+

00368         {
+00369                 return M[ (j<<2) + i];
+00370         }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
float& NLMISC::CMatrix::mat sint  i,
sint  j
[inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 362 of file matrix.h. +

+References sint. +

+Referenced by getRot(), and slowInvert44(). +

+

00363         {
+00364                 return M[ (j<<2) + i];
+00365         }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::movePos const CVector v  ) 
+
+ + + + + +
+   + + +

+Explicit move the Translation component.

Parameters:
+ + +
v a vector to move the translation vector.
+
+ +

+Definition at line 279 of file matrix.cpp. +

+References a14, a24, a34, MAT_TRANS, StateBit, and v. +

+Referenced by NL3D::CWaterModel::traverseRender(). +

+

00280 {
+00281         a14+= v.x;
+00282         a24+= v.y;
+00283         a34+= v.z;
+00284         if(a14!=0 || a24!=0 || a34!=0)
+00285                 StateBit|= MAT_TRANS;
+00286         else
+00287                 // The trans is identity
+00288                 StateBit&= ~MAT_TRANS;
+00289 }
+
+

+ + + + +
+ + + + + + + + + + +
CVector NLMISC::CMatrix::mulPoint const CVector v  )  const
+
+ + + + + +
+   + + +

+Multiply a point. ie v.w=1 so the Translation component do affect result. Projection doesn't affect result. +

+ +

+Definition at line 1261 of file matrix.cpp. +

+References a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, hasRot(), hasTrans(), v, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. +

+Referenced by NL3D::CCloud::calcBill(), operator *(), and NL3D::CPortal::setWorldMatrix(). +

+

01262 {
+01263 
+01264         CVector ret;
+01265 
+01266         if( hasRot() )
+01267         {
+01268                 ret.x= a11*v.x + a12*v.y + a13*v.z;
+01269                 ret.y= a21*v.x + a22*v.y + a23*v.z;
+01270                 ret.z= a31*v.x + a32*v.y + a33*v.z;
+01271         }
+01272         else
+01273         {
+01274                 ret= v;
+01275         }
+01276         if( hasTrans() )
+01277         {
+01278                 ret.x+= a14;
+01279                 ret.y+= a24;
+01280                 ret.z+= a34;
+01281         }
+01282 
+01283         return ret;
+01284 }
+
+

+ + + + +
+ + + + + + + + + + +
CVector NLMISC::CMatrix::mulVector const CVector v  )  const
+
+ + + + + +
+   + + +

+Multiply a normal. ie v.w=0 so the Translation component doesn't affect result. Projection doesn't affect result. +

+ +

+Definition at line 1244 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, hasRot(), v, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. +

+Referenced by NL3D::CVegetableManager::addInstance(), NL3D::CLodCharacterManager::addRenderCharacterKey(), NL3D::CMeshVPPerPixelLight::begin(), NL3D::CRenderTrav::beginVPLightSetup(), NL3D::CPSLocated::computeI(), NL3D::CPSLocated::computeJ(), NL3D::CPSLocated::computeK(), NL3D::CParticleSystem::getLODVect(), NL3D::CEvent3dMouseListener::getViewMatrix(), H_AUTO_DECL(), NL3D::CPSConstraintMesh::makePrerotatedVb(), NL3D::CPSLocated::newElement(), NL3D::CPSCylindricVortex::performDynamic(), NL3D::CPSZoneRectangle::performMotion(), NL3D::CPSZoneCylinder::performMotion(), NL3D::CPSZoneDisc::performMotion(), NL3D::CPSZonePlane::performMotion(), NL3D::CMeshVPWindTree::setupPerInstanceConstants(), NL3D::CPSSound::step(), NL3D::CTravCameraScene::update(), NL3D::CAnimatedMaterial::update(), and NL3D::CVegetableManager::updateInstanceLighting(). +

+

01245 {
+01246 
+01247         CVector ret;
+01248 
+01249         if( hasRot() )
+01250         {
+01251                 ret.x= a11*v.x + a12*v.y + a13*v.z;
+01252                 ret.y= a21*v.x + a22*v.y + a23*v.z;
+01253                 ret.z= a31*v.x + a32*v.y + a33*v.z;
+01254                 return ret;
+01255         }
+01256         else
+01257                 return v;
+01258 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CMatrix::normalize TRotOrder  pref  ) 
+
+ + + + + +
+   + + +

+Normalize the matrix so that the rotation part is now an orthonormal basis, ie a rotation with no scale. NB: projection part and translation part are not modified.

Parameters:
+ + +
pref the preference axis order to normalize. ZYX means that K direction will be kept, and the plane JK will be used to lead the I vector.
+
+
Returns:
false if One of the vector basis is null. true otherwise.
+ +

+Definition at line 1170 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, getI(), getJ(), getK(), NLMISC::CVector::isNull(), MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, NLMISC::CVector::normalize(), Scale33, StateBit, testExpandRot(), NLMISC::CVector::x, XYZ, XZY, NLMISC::CVector::y, YXZ, YZX, NLMISC::CVector::z, ZXY, and ZYX. +

+Referenced by NL3D::CCameraCol::build(), NL3D::CShadowMap::buildCasterCameraMatrix(), CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::compile(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CTargetAnimCtrl::execute(), NL3D::CPatch::generateTileVegetable(), getRot(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CQuadTree< T >::selectRay(), and NL3D::CQuadTree< T >::selectSegment(). +

+

01171 {
+01172 
+01173         CVector ti,tj,tk;
+01174         ti= getI();
+01175         tj= getJ();
+01176         tk= getK();
+01177 
+01178         // \todo yoyo: TODO_OPTIMIZE it...
+01179         testExpandRot();
+01180 
+01181         // Normalize with help of ro
+01182         switch(ro)
+01183         {
+01184                 case XYZ:
+01185                         ti.normalize();
+01186                         tk= ti^tj;
+01187                         tk.normalize();
+01188                         tj= tk^ti;
+01189                         break;
+01190                 case XZY:
+01191                         ti.normalize();
+01192                         tj= tk^ti;
+01193                         tj.normalize();
+01194                         tk= ti^tj;
+01195                         break;
+01196                 case YXZ:
+01197                         tj.normalize();
+01198                         tk= ti^tj;
+01199                         tk.normalize();
+01200                         ti= tj^tk;
+01201                         break;
+01202                 case YZX:
+01203                         tj.normalize();
+01204                         ti= tj^tk;
+01205                         ti.normalize();
+01206                         tk= ti^tj;
+01207                         break;
+01208                 case ZXY:
+01209                         tk.normalize();
+01210                         tj= tk^ti;
+01211                         tj.normalize();
+01212                         ti= tj^tk;
+01213                         break;
+01214                 case ZYX:
+01215                         tk.normalize();
+01216                         ti= tj^tk;
+01217                         ti.normalize();
+01218                         tj= tk^ti;
+01219                         break;
+01220         }
+01221 
+01222         // Check, and set result.
+01223         if( ti.isNull() || tj.isNull() || tk.isNull() )
+01224                 return false;
+01225         a11= ti.x; a12= tj.x; a13= tk.x; 
+01226         a21= ti.y; a22= tj.y; a23= tk.y; 
+01227         a31= ti.z; a32= tj.z; a33= tk.z; 
+01228         // Scale is reseted.
+01229         StateBit&= ~(MAT_SCALEUNI|MAT_SCALEANY);
+01230         // Rot is setup...
+01231         StateBit|= MAT_ROT;
+01232         Scale33=1;
+01233 
+01234         return true;
+01235 }
+
+

+ + + + +
+ + + + + + + + + + +
CVectorH NLMISC::CMatrix::operator * const CVectorH v  )  const
+
+ + + + + +
+   + + +

+Multiply with an homogenous vector. +

+ +

+Definition at line 1290 of file matrix.cpp. +

+References a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, a41, a42, a43, a44, testExpandProj(), testExpandRot(), v, NLMISC::CVectorH::w, NLMISC::CVectorH::x, NLMISC::CVectorH::y, and NLMISC::CVectorH::z. +

+

01291 {
+01292 
+01293         CVectorH ret;
+01294 
+01295         // \todo yoyo: TODO_OPTIMIZE it...
+01296         testExpandRot();
+01297         testExpandProj();
+01298 
+01299         ret.x= a11*v.x + a12*v.y + a13*v.z + a14*v.w;
+01300         ret.y= a21*v.x + a22*v.y + a23*v.z + a24*v.w;
+01301         ret.z= a31*v.x + a32*v.y + a33*v.z + a34*v.w;
+01302         ret.w= a41*v.x + a42*v.y + a43*v.z + a44*v.w;
+01303         return ret;
+01304 }
+
+

+ + + + +
+ + + + + + + + + + +
CVector NLMISC::CMatrix::operator * const CVector v  )  const [inline]
+
+ + + + + +
+   + + +

+Multiply a point. mulPoint. +

+ +

+Definition at line 325 of file matrix.h. +

+References mulPoint(), and v. +

+

00326         {
+00327                 return mulPoint(v);
+00328         }
+
+

+ + + + +
+ + + + + + + + + + +
CMatrix NLMISC::CMatrix::operator * const CMatrix in  )  const [inline]
+
+ + + + + +
+   + + +

+Matrix multiplication. +

+ +

+Definition at line 272 of file matrix.h. +

+References in, and setMulMatrix(). +

+

00273         {
+00274                 CMatrix         ret;
+00275                 ret.setMulMatrix(*this, in);
+00276                 return ret;
+00277         }
+
+

+ + + + +
+ + + + + + + + + + +
CMatrix& NLMISC::CMatrix::operator *= const CMatrix in  )  [inline]
+
+ + + + + +
+   + + +

+equivalent to M=M*in +

+ +

+Definition at line 279 of file matrix.h. +

+References in, and setMulMatrix(). +

+

00280         {
+00281                 CMatrix         ret;
+00282                 ret.setMulMatrix(*this, in);
+00283                 *this= ret;
+00284                 return *this;
+00285         }
+
+

+ + + + +
+ + + + + + + + + + +
CMatrix & NLMISC::CMatrix::operator= const CMatrix  ) 
+
+ + + + + +
+   + + +

+operator=. +

+ +

+Definition at line 168 of file matrix.cpp. +

+References a11, a12, a13, a14, a41, a42, a43, a44, hasAll(), hasProj(), hasRot(), M, MAT_VALIDALL, Scale33, and StateBit. +

+

00169 {
+00170         StateBit= m.StateBit & ~MAT_VALIDALL;
+00171         if(hasAll())
+00172         {
+00173                 memcpy(M, m.M, 16*sizeof(float));
+00174                 Scale33= m.Scale33;
+00175         }
+00176         else
+00177         {
+00178                 if(hasRot())
+00179                 {
+00180                         memcpy(&a11, &m.a11, 3*sizeof(float));
+00181                         memcpy(&a12, &m.a12, 3*sizeof(float));
+00182                         memcpy(&a13, &m.a13, 3*sizeof(float));
+00183                         Scale33= m.Scale33;
+00184                 }
+00185                 if(hasProj())
+00186                 {
+00187                         a41= m.a41;
+00188                         a42= m.a42;
+00189                         a43= m.a43;
+00190                         a44= m.a44;
+00191                 }
+00192                 // Must always copy Trans part.
+00193                 memcpy(&a14, &m.a14, 3*sizeof(float));
+00194         }
+00195         return *this;
+00196 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::resetProj  ) 
+
+ + + + + +
+   + + +

+Reset the Projection component to 0 0 0 1. +

+Definition at line 309 of file matrix.cpp. +

+References a41, a42, a43, a44, MAT_PROJ, MAT_VALIDPROJ, and StateBit. +

+

00310 {
+00311         a41= 0;
+00312         a42= 0;
+00313         a43= 0;
+00314         a44= 1;
+00315         // The proj is identity, and is correcly setup!
+00316         StateBit&= ~MAT_PROJ;
+00317         StateBit|= MAT_VALIDPROJ;
+00318 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::rotate const CQuat quat  ) 
+
+ + + + + +
+   + + +

+Apply a quaternion rotation. +

+Definition at line 636 of file matrix.cpp. +

+References setRot(). +

+

00637 {
+00638         CMatrix         rot;
+00639         rot.setRot(quat);
+00640         (*this)*= rot;
+00641 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::rotate const CVector v,
TRotOrder  ro
+
+ + + + + +
+   + + +

+Apply a euler rotation.

Parameters:
+ + + +
v a vector of 3 angle (in radian), giving rotation around each axis (x,y,z)
ro the order of transformation applied. if ro==XYZ, then the transform is M=M*Rx*Ry*Rz
+
+ +

+Definition at line 618 of file matrix.cpp. +

+References identity(), rotateX(), rotateY(), rotateZ(), v, XYZ, XZY, YXZ, YZX, ZXY, and ZYX. +

+Referenced by NL3D::CInstanceGroup::getInstanceMatrix(), NL3D::CWaterShape::getShapeInWorldSpace(), NL3D::CPSConstraintMesh::makePrerotatedVb(), NL3D::CEvent3dMouseListener::operator()(), setRot(), NL3D::CPSFace::step(), and NL3D::ITransformable::updateMatrix(). +

+

00619 {
+00620         CMatrix         rot;
+00621         rot.identity();
+00622         switch(ro)
+00623         {
+00624                 case XYZ: rot.rotateX(v.x); rot.rotateY(v.y); rot.rotateZ(v.z); break;
+00625                 case XZY: rot.rotateX(v.x); rot.rotateZ(v.z); rot.rotateY(v.y); break;
+00626                 case YXZ: rot.rotateY(v.y); rot.rotateX(v.x); rot.rotateZ(v.z); break;
+00627                 case YZX: rot.rotateY(v.y); rot.rotateZ(v.z); rot.rotateX(v.x); break;
+00628                 case ZXY: rot.rotateZ(v.z); rot.rotateX(v.x); rot.rotateY(v.y); break;
+00629                 case ZYX: rot.rotateZ(v.z); rot.rotateY(v.y); rot.rotateX(v.x); break;
+00630         }
+00631 
+00632         (*this)*= rot;
+00633 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::rotateX float  a  ) 
+
+ + + + + +
+   + + +

+Apply a rotation on axis X to the matrix. same as M=M*Rx

Parameters:
+ + +
a angle (in radian).
+
+ +

+Definition at line 498 of file matrix.cpp. +

+References a12, a13, a22, a23, a32, a33, a42, a43, hasProj(), hasRot(), MAT_ROT, StateBit, and testExpandRot(). +

+Referenced by NL3D::CEvent3dMouseListener::operator()(), and rotate(). +

+

00499 {
+00500 
+00501         if(a==0)
+00502                 return;
+00503         double  ca,sa;
+00504         ca=cos(a);
+00505         sa=sin(a);
+00506 
+00507         // SetRot.
+00508         if( hasRot() )
+00509         {
+00510                 float   b12=a12, b22=a22, b32=a32;
+00511                 float   b13=a13, b23=a23, b33=a33;
+00512                 a12= (float)(b12*ca + b13*sa);
+00513                 a22= (float)(b22*ca + b23*sa);
+00514                 a32= (float)(b32*ca + b33*sa);
+00515                 a13= (float)(b13*ca - b12*sa);
+00516                 a23= (float)(b23*ca - b22*sa);
+00517                 a33= (float)(b33*ca - b32*sa);
+00518         }
+00519         else
+00520         {
+00521                 testExpandRot();
+00522                 a12= 0.0f; a22= (float)ca; a32= (float)sa;
+00523                 a13= 0.0f; a23= (float)-sa; a33= (float)ca;
+00524         }
+00525 
+00526         // SetProj.
+00527         if( hasProj() )
+00528         {
+00529                 float   b42=a42, b43=a43;
+00530                 a42= (float)(b42*ca + b43*sa);
+00531                 a43= (float)(b43*ca - b42*sa);
+00532         }
+00533 
+00534         // set Rot.
+00535         StateBit|= MAT_ROT;
+00536 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::rotateY float  a  ) 
+
+ + + + + +
+   + + +

+Apply a rotation on axis Y to the matrix. same as M=M*Ry

Parameters:
+ + +
a angle (in radian).
+
+ +

+Definition at line 538 of file matrix.cpp. +

+References a11, a13, a21, a23, a31, a33, a41, a43, hasProj(), hasRot(), MAT_ROT, StateBit, and testExpandRot(). +

+Referenced by NL3D::ITransformable::lookAt(), and rotate(). +

+

00539 {
+00540 
+00541         if(a==0)
+00542                 return;
+00543         double  ca,sa;
+00544         ca=cos(a);
+00545         sa=sin(a);
+00546 
+00547         // SetRot.
+00548         if( hasRot() )
+00549         {
+00550                 float   b11=a11, b21=a21, b31=a31;
+00551                 float   b13=a13, b23=a23, b33=a33;
+00552                 a11= (float)(b11*ca - b13*sa);
+00553                 a21= (float)(b21*ca - b23*sa);
+00554                 a31= (float)(b31*ca - b33*sa);
+00555                 a13= (float)(b13*ca + b11*sa);
+00556                 a23= (float)(b23*ca + b21*sa);
+00557                 a33= (float)(b33*ca + b31*sa);
+00558         }
+00559         else
+00560         {
+00561                 testExpandRot();
+00562                 a11= (float)ca; a21=0.0f; a31= (float)-sa;
+00563                 a13= (float)sa; a23=0.0f; a33= (float)ca;
+00564         }
+00565 
+00566         // SetProj.
+00567         if( hasProj() )
+00568         {
+00569                 float   b41=a41, b43=a43;
+00570                 a41= (float)(b41*ca - b43*sa);
+00571                 a43= (float)(b43*ca + b41*sa);
+00572         }
+00573 
+00574         // set Rot.
+00575         StateBit|= MAT_ROT;
+00576 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::rotateZ float  a  ) 
+
+ + + + + +
+   + + +

+Apply a rotation on axis Z to the matrix. same as M=M*Rz

Parameters:
+ + +
a angle (in radian).
+
+ +

+Definition at line 578 of file matrix.cpp. +

+References a11, a12, a21, a22, a31, a32, a41, a42, hasProj(), MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, StateBit, and testExpandRot(). +

+Referenced by NLLIGO::CZoneEdge::buildMatrix(), NL3D::CLodCharacterManager::CLodCharacterManager(), NL3D::CVegetableQuadrant::CVegetableQuadrant(), NL3D::CTessFacePriorityList::init(), NL3D::CEvent3dMouseListener::operator()(), and rotate(). +

+

00579 {
+00580 
+00581         if(a==0)
+00582                 return;
+00583         double  ca,sa;
+00584         ca=cos(a);
+00585         sa=sin(a);
+00586 
+00587         // SetRot.
+00588         if( StateBit & (MAT_ROT|MAT_SCALEUNI|MAT_SCALEANY) )
+00589         {
+00590                 float   b11=a11, b21=a21, b31=a31;
+00591                 float   b12=a12, b22=a22, b32=a32;
+00592                 a11= (float)(b11*ca + b12*sa);
+00593                 a21= (float)(b21*ca + b22*sa);
+00594                 a31= (float)(b31*ca + b32*sa);
+00595                 a12= (float)(b12*ca - b11*sa);
+00596                 a22= (float)(b22*ca - b21*sa);
+00597                 a32= (float)(b32*ca - b31*sa);
+00598         }
+00599         else
+00600         {
+00601                 testExpandRot();
+00602                 a11= (float)ca; a21= (float)sa; a31=0.0f;
+00603                 a12= (float)-sa; a22= (float)ca; a32=0.0f;
+00604         }
+00605 
+00606         // SetProj.
+00607         if( hasProj() )
+00608         {
+00609                 float   b41=a41, b42=a42;
+00610                 a41= (float)(b41*ca + b42*sa);
+00611                 a42= (float)(b42*ca - b41*sa);
+00612         }
+00613 
+00614         // set Rot.
+00615         StateBit|= MAT_ROT;
+00616 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::scale const CVector scale  ) 
+
+ + + + + +
+   + + +

+Apply a non-uniform scale to the matrix. +

+ +

+Definition at line 669 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, a41, a42, a43, hasProj(), MAT_SCALEANY, scale(), StateBit, testExpandRot(), and v. +

+

00670 {
+00671 
+00672         if( v==CVector(1,1,1) ) return;
+00673         if( !(StateBit & MAT_SCALEANY) && v.x==v.y && v.x==v.z)
+00674         {
+00675                 scale(v.x);
+00676         }
+00677         else
+00678         {
+00679                 testExpandRot();
+00680                 StateBit|=MAT_SCALEANY;
+00681                 a11*= v.x; a12*=v.y; a13*=v.z;
+00682                 a21*= v.x; a22*=v.y; a23*=v.z;
+00683                 a31*= v.x; a32*=v.y; a33*=v.z;
+00684 
+00685                 // SetProj.
+00686                 if( hasProj() )
+00687                 {
+00688                         a41*=v.x;
+00689                         a42*=v.y;
+00690                         a43*=v.z;
+00691                 }
+00692         }
+00693 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::scale float  f  ) 
+
+ + + + + +
+   + + +

+Apply a uniform scale to the matrix. +

+ +

+Definition at line 644 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, a41, a42, a43, hasProj(), MAT_SCALEANY, MAT_SCALEUNI, Scale33, StateBit, and testExpandRot(). +

+Referenced by NL3D::ComputeTexturedRibbonMesh(), NL3D::ComputeUntexturedRibbonMesh(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CPSConstraintMeshHelper::drawMeshs(), NL3D::CVegetable::generateInstance(), NL3D::CInstanceGroup::getInstanceMatrix(), NL3D::CWaterShape::getShapeInWorldSpace(), NL3D::CInstanceLighter::light(), NL3D::CInstanceLighter::lightIgSimple(), NL3D::CPSUtil::print(), scale(), NL3D::ITransformable::updateMatrix(), and NL3D::CPSMesh::updatePos(). +

+

00645 {
+00646 
+00647         if(f==1.0f) return;
+00648         if(StateBit & MAT_SCALEANY)
+00649         {
+00650                 scale(CVector(f,f,f));
+00651         }
+00652         else
+00653         {
+00654                 testExpandRot();
+00655                 StateBit|= MAT_SCALEUNI;
+00656                 Scale33*=f;
+00657                 a11*= f; a12*=f; a13*=f;
+00658                 a21*= f; a22*=f; a23*=f;
+00659                 a31*= f; a32*=f; a33*=f;
+00660 
+00661                 // SetProj.
+00662                 if( hasProj() )
+00663                 {
+00664                         a41*=f; a42*=f; a43*=f;
+00665                 }
+00666         }
+00667 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::serial IStream f  ) 
+
+ + + + + +
+   + + +

+return true the uniform scale. valid only if hasScaleUniform() is true, else 1 is returned. +

+ +

+Definition at line 1500 of file matrix.cpp. +

+References a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, a41, a42, a43, a44, hasProj(), hasRot(), hasTrans(), identity(), NLMISC::IStream::isReading(), Scale33, NLMISC::IStream::serial(), NLMISC::IStream::serialVersion(), and StateBit. +

+

01501 {
+01502         // Use versionning, maybe for futur improvement.
+01503         (void)f.serialVersion(0);
+01504 
+01505         if(f.isReading())
+01506                 identity();
+01507         f.serial(StateBit);
+01508         f.serial(Scale33);
+01509         if( hasRot() )
+01510         {
+01511                 f.serial(a11, a12, a13);
+01512                 f.serial(a21, a22, a23);
+01513                 f.serial(a31, a32, a33);
+01514         }
+01515         if( hasTrans() )
+01516         {
+01517                 f.serial(a14, a24, a34);
+01518         }
+01519         else if(f.isReading())
+01520         {
+01521                 // must reset because Pos must always be valid
+01522                 a14= a24= a34= 0;
+01523         }
+01524         if( hasProj() )
+01525         {
+01526                 f.serial(a41, a42, a43, a44);
+01527         }
+01528 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::set const float  m44[16]  ) 
+
+ + + + + +
+   + + +

+Explicit setup the 4*4 matrix. Avoid it. It implies low compute since no check is done on rotation matrix to see what type of matrix it is (identity, rotation, scale, uniform scale). BUT check are made to see if it has translation or projection components.

Parameters:
+ + +
m44 the 4*4 column matrix (4x4 matrix stored in column-major order as 16 consecutive values)
+
+ +

+Definition at line 320 of file matrix.cpp. +

+References a14, a24, a34, a41, a42, a43, a44, MAT_IDENTITY, MAT_PROJ, MAT_ROT, MAT_SCALEANY, MAT_TRANS, MAT_VALIDPROJ, Scale33, and StateBit. +

+Referenced by NL3D::CDriverGL::refreshProjMatrixFromGL(). +

+

00321 {
+00322         StateBit= MAT_IDENTITY;
+00323 
+00324         StateBit|= MAT_ROT | MAT_SCALEANY;
+00325         memcpy(M, m44, 16*sizeof(float));
+00326         Scale33= 1.0f;
+00327 
+00328         // Check Trans state.
+00329         if(a14!=0 || a24!=0 || a34!=0)
+00330                 StateBit|= MAT_TRANS;
+00331         else
+00332                 // The trans is identity
+00333                 StateBit&= ~MAT_TRANS;
+00334 
+00335         // Check Proj state.
+00336         if(a41!=0 || a42!=0 || a43!=0 || a44!=1)
+00337                 StateBit|= MAT_PROJ;
+00338         else
+00339         {
+00340                 // The proj is identity, and is correcly setup!
+00341                 StateBit&= ~MAT_PROJ;
+00342                 StateBit|= MAT_VALIDPROJ;
+00343         }
+00344 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::setMulMatrix const CMatrix m1,
const CMatrix m2
+
+ + + + + +
+   + + +

+Matrix multiplication. Because of copy avoidance, this is the fastest method Equivalent to *this= m1 * m2

Warning:
*this MUST NOT be the same as m1 or m2, else it doesn't work (not checked/nlasserted)
+ +

+Definition at line 744 of file matrix.cpp. +

+References a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, a41, a42, a43, a44, hasProj(), hasRot(), hasTrans(), identity(), MAT_PROJ, MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, MAT_TRANS, MAT_VALIDALL, MAT_VALIDPROJ, MAT_VALIDROT, nlassert, Scale33, StateBit, testExpandProj(), and testExpandRot(). +

+Referenced by operator *(), operator *=(), and NL3D::CShadowMapManager::renderProject(). +

+

00745 {
+00746         // Do *this= m1*m2
+00747         identity();
+00748         StateBit= m1.StateBit | m2.StateBit;
+00749         StateBit&= ~MAT_VALIDALL;
+00750 
+00751         // Build Rot part.
+00752         //===============
+00753         bool    M1Identity= ! m1.hasRot();
+00754         bool    M2Identity= ! m2.hasRot();
+00755         bool    M1ScaleOnly= ! (m1.StateBit & MAT_ROT);
+00756         bool    M2ScaleOnly= ! (m2.StateBit & MAT_ROT);
+00757         bool    MGeneralCase= !M1Identity && !M2Identity && !M1ScaleOnly && !M2ScaleOnly;
+00758 
+00759 
+00760         // Manage the most common general case first (optim the if ): blending of two rotations.
+00761         if( MGeneralCase )
+00762         {
+00763                 a11= m1.a11*m2.a11 + m1.a12*m2.a21 + m1.a13*m2.a31;
+00764                 a12= m1.a11*m2.a12 + m1.a12*m2.a22 + m1.a13*m2.a32;
+00765                 a13= m1.a11*m2.a13 + m1.a12*m2.a23 + m1.a13*m2.a33;
+00766 
+00767                 a21= m1.a21*m2.a11 + m1.a22*m2.a21 + m1.a23*m2.a31;
+00768                 a22= m1.a21*m2.a12 + m1.a22*m2.a22 + m1.a23*m2.a32;
+00769                 a23= m1.a21*m2.a13 + m1.a22*m2.a23 + m1.a23*m2.a33;
+00770 
+00771                 a31= m1.a31*m2.a11 + m1.a32*m2.a21 + m1.a33*m2.a31;
+00772                 a32= m1.a31*m2.a12 + m1.a32*m2.a22 + m1.a33*m2.a32;
+00773                 a33= m1.a31*m2.a13 + m1.a32*m2.a23 + m1.a33*m2.a33;
+00774         }
+00775         // If one of the 3x3 matrix is an identity, just do a copy
+00776         else if( M1Identity || M2Identity )
+00777         {
+00778                 // If both identity, then me too.
+00779                 if( M1Identity && M2Identity )
+00780                 {
+00781                         // just expand me (important because validated below)
+00782                         testExpandRot();
+00783                 }
+00784                 else
+00785                 {
+00786                         // Copy the non identity matrix.
+00787                         const CMatrix   *c= M2Identity? &m1 : &m2;
+00788                         a11= c->a11; a12= c->a12; a13= c->a13;
+00789                         a21= c->a21; a22= c->a22; a23= c->a23;
+00790                         a31= c->a31; a32= c->a32; a33= c->a33;
+00791                 }
+00792         }
+00793         // If two 3x3 matrix are just scaleOnly matrix, do a scaleFact.
+00794         else if( M1ScaleOnly && M2ScaleOnly )
+00795         {
+00796                 // same process for scaleUni or scaleAny.
+00797                 a11= m1.a11*m2.a11; a12= 0; a13= 0; 
+00798                 a21= 0; a22= m1.a22*m2.a22; a23= 0; 
+00799                 a31= 0; a32= 0; a33= m1.a33*m2.a33;
+00800         }
+00801         // If one of the matrix is a scaleOnly matrix, do a scale*Rot.
+00802         else if( M1ScaleOnly && !M2ScaleOnly )
+00803         {
+00804                 a11= m1.a11*m2.a11; a12= m1.a11*m2.a12; a13= m1.a11*m2.a13;
+00805                 a21= m1.a22*m2.a21; a22= m1.a22*m2.a22; a23= m1.a22*m2.a23;
+00806                 a31= m1.a33*m2.a31; a32= m1.a33*m2.a32; a33= m1.a33*m2.a33;
+00807         }
+00808         else
+00809         {
+00810                 // This must be this case
+00811                 nlassert(!M1ScaleOnly && M2ScaleOnly);
+00812                 a11= m1.a11*m2.a11; a12= m1.a12*m2.a22; a13= m1.a13*m2.a33;
+00813                 a21= m1.a21*m2.a11; a22= m1.a22*m2.a22; a23= m1.a23*m2.a33;
+00814                 a31= m1.a31*m2.a11; a32= m1.a32*m2.a22; a33= m1.a33*m2.a33;
+00815         }
+00816 
+00817         // If M1 has translate and M2 has projective, rotation is modified.
+00818         if( m1.hasTrans() && m2.hasProj())
+00819         {
+00820                 StateBit|= MAT_ROT|MAT_SCALEANY;
+00821 
+00822                 a11+= m1.a14*m2.a41;
+00823                 a12+= m1.a14*m2.a42;
+00824                 a13+= m1.a14*m2.a43;
+00825 
+00826                 a21+= m1.a24*m2.a41;
+00827                 a22+= m1.a24*m2.a42;
+00828                 a23+= m1.a24*m2.a43;
+00829 
+00830                 a31+= m1.a34*m2.a41;
+00831                 a32+= m1.a34*m2.a42;
+00832                 a33+= m1.a34*m2.a43;
+00833         }
+00834 
+00835         // Modify Scale.
+00836         if( (StateBit & MAT_SCALEUNI) && !(StateBit & MAT_SCALEANY) )
+00837         {
+00838                 // Must have correct Scale33
+00839                 m1.testExpandRot();
+00840                 m2.testExpandRot();
+00841                 Scale33= m1.Scale33*m2.Scale33;
+00842         }
+00843         else
+00844                 Scale33=1;
+00845 
+00846         // In every case, I am valid now!
+00847         StateBit|=MAT_VALIDROT;
+00848 
+00849 
+00850         // Build Trans part.
+00851         //=================
+00852         if( StateBit & MAT_TRANS )
+00853         {
+00854                 // Compose M2 part.
+00855                 if( M1Identity )
+00856                 {
+00857                         a14= m2.a14;
+00858                         a24= m2.a24;
+00859                         a34= m2.a34;
+00860                 }
+00861                 else if (M1ScaleOnly )
+00862                 {
+00863                         a14= m1.a11*m2.a14;
+00864                         a24= m1.a22*m2.a24;
+00865                         a34= m1.a33*m2.a34;
+00866                 }
+00867                 else
+00868                 {
+00869                         a14= m1.a11*m2.a14 + m1.a12*m2.a24 + m1.a13*m2.a34;
+00870                         a24= m1.a21*m2.a14 + m1.a22*m2.a24 + m1.a23*m2.a34;
+00871                         a34= m1.a31*m2.a14 + m1.a32*m2.a24 + m1.a33*m2.a34;
+00872                 }
+00873                 // Compose M1 part.
+00874                 if(m1.StateBit & MAT_TRANS)
+00875                 {
+00876                         if(m2.StateBit & MAT_PROJ)
+00877                         {
+00878                                 a14+= m1.a14*m2.a44;
+00879                                 a24+= m1.a24*m2.a44;
+00880                                 a34+= m1.a34*m2.a44;
+00881                         }
+00882                         else
+00883                         {
+00884                                 a14+= m1.a14;
+00885                                 a24+= m1.a24;
+00886                                 a34+= m1.a34;
+00887                         }
+00888                 }
+00889         }
+00890 
+00891 
+00892         // Build Proj part.
+00893         //=================
+00894         if( StateBit & MAT_PROJ )
+00895         {
+00896                 // optimise nothing... (projection matrix are rare).
+00897                 m1.testExpandRot();
+00898                 m1.testExpandProj();
+00899                 m2.testExpandRot();
+00900                 m2.testExpandProj();
+00901                 a41= m1.a41*m2.a11 + m1.a42*m2.a21 + m1.a43*m2.a31 + m1.a44*m2.a41;
+00902                 a42= m1.a41*m2.a12 + m1.a42*m2.a22 + m1.a43*m2.a32 + m1.a44*m2.a42;
+00903                 a43= m1.a41*m2.a13 + m1.a42*m2.a23 + m1.a43*m2.a33 + m1.a44*m2.a43;
+00904                 a44= m1.a41*m2.a14 + m1.a42*m2.a24 + m1.a43*m2.a34 + m1.a44*m2.a44;
+00905                 // The proj is valid now
+00906                 StateBit|= MAT_VALIDPROJ;
+00907         }
+00908         else
+00909         {
+00910                 // Don't copy proj part, and leave MAT_VALIDPROJ not set
+00911         }
+00912 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::setMulMatrixNoProj const CMatrix m1,
const CMatrix m2
+
+ + + + + +
+   + + +

+Matrix multiplication assuming no projection at all in m1/m2 and Hence this. Even Faster than setMulMatrix() Equivalent to *this= m1 * m2 NB: Also always suppose m1 has a translation, for optim consideration

Warning:
*this MUST NOT be the same as m1 or m2, else it doesn't work (not checked/nlasserted)
+ +

+Definition at line 702 of file matrix.cpp. +

+References a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, hasScaleUniform(), MAT_PROJ, MAT_VALIDPROJ, MAT_VALIDROT, Scale33, StateBit, and testExpandRot(). +

+Referenced by NL3D::CBone::compute(). +

+

00703 {
+00704         /*
+00705         For a fast MulMatrix, it appears to be better to not take State bits into account (no test/if() overhead)
+00706         Just do heavy mul all the time (common case, and not so slow)
+00707         */
+00708 
+00709         // Ensure the src matrix have correct values in rot part
+00710         m1.testExpandRot();
+00711         m2.testExpandRot();
+00712 
+00713         // Rot Mul
+00714         a11= m1.a11*m2.a11 + m1.a12*m2.a21 + m1.a13*m2.a31;
+00715         a12= m1.a11*m2.a12 + m1.a12*m2.a22 + m1.a13*m2.a32;
+00716         a13= m1.a11*m2.a13 + m1.a12*m2.a23 + m1.a13*m2.a33;
+00717 
+00718         a21= m1.a21*m2.a11 + m1.a22*m2.a21 + m1.a23*m2.a31;
+00719         a22= m1.a21*m2.a12 + m1.a22*m2.a22 + m1.a23*m2.a32;
+00720         a23= m1.a21*m2.a13 + m1.a22*m2.a23 + m1.a23*m2.a33;
+00721 
+00722         a31= m1.a31*m2.a11 + m1.a32*m2.a21 + m1.a33*m2.a31;
+00723         a32= m1.a31*m2.a12 + m1.a32*m2.a22 + m1.a33*m2.a32;
+00724         a33= m1.a31*m2.a13 + m1.a32*m2.a23 + m1.a33*m2.a33;
+00725 
+00726         // Trans mul
+00727         a14= m1.a11*m2.a14 + m1.a12*m2.a24 + m1.a13*m2.a34 + m1.a14;
+00728         a24= m1.a21*m2.a14 + m1.a22*m2.a24 + m1.a23*m2.a34 + m1.a24;
+00729         a34= m1.a31*m2.a14 + m1.a32*m2.a24 + m1.a33*m2.a34 + m1.a34;
+00730 
+00731         // Setup no proj at all, and force valid rot (still may be identity, but 0/1 are filled)
+00732         StateBit= (m1.StateBit | m2.StateBit | MAT_VALIDROT) & ~(MAT_PROJ|MAT_VALIDPROJ);
+00733         
+00734         // Modify Scale. This test is important because Scale33 may be a #NAN if SCALEANY => avoid very slow mul.
+00735         if( hasScaleUniform() )
+00736                 Scale33= m1.Scale33*m2.Scale33;
+00737         else
+00738                 Scale33=1;
+00739         
+00740 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setPos const CVector v  ) 
+
+ + + + + +
+   + + +

+Explicit setup the Translation component. v==Null is tested to see if the matrix now have a translation component.

Parameters:
+ + +
v the translation vector.
+
+ +

+Definition at line 267 of file matrix.cpp. +

+References a14, a24, a34, MAT_TRANS, StateBit, and v. +

+Referenced by NL3D::CCameraCol::build(), NL3D::CPSZonePlane::buildBasis(), NLMISC::CPolygon::buildBasis(), NLLIGO::CZoneEdge::buildMatrix(), NL3D::CShadowMap::buildProjectionInfos(), NL3D::CCloud::calcBill(), NL3D::CLandscapeModel::clipAndRenderLandscape(), NL3D::CBone::compute(), NL3D::ComputeRibbonSlice(), NL3D::CMaterial::decompUserTexMat(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CLodCharacterManager::endRender(), NL3D::CCloud::genBill(), NL3D::CSkeletonModel::generateShadowMap(), NL3D::CMeshInstance::generateShadowMap(), NL3D::CPatch::generateTileVegetable(), NL3D::CPSZoneRectangle::getMatrix(), NL3D::CPSZoneCylinder::getMatrix(), NL3D::CPSCylindricVortex::getMatrix(), NL3D::CPSEmitterRectangle::getMatrix(), NL3D::CViewport::getRayWithPoint(), NL3D::CEvent3dMouseListener::getViewMatrix(), InitZBuffer(), NL3D::CBone::interpolateBoneSkinMatrix(), NL3D::CInstanceLighter::light(), NL3D::CInstanceLighter::lightIgSimple(), NL3D::CZoneLighter::lightWater(), NL3D::ITransformable::lookAt(), NL3D::CEvent3dMouseListener::operator()(), NL3D::CPSUtil::print(), NL3D::CVegetableManager::render(), NL3D::CShadowPolyReceiver::render(), NL3D::CSegRemanence::render(), NL3D::CCloudScape::render(), NL3D::CSkeletonModel::renderIntoSkeletonShadowMap(), NL3D::CMeshInstance::renderIntoSkeletonShadowMap(), NL3D::CShadowMapManager::renderProject(), NL3D::CDriverGL::setupModelMatrix(), NL3D::CLodCharacterManager::setupNormalCorrectionMatrix(), NL3D::CDriverGL::setupViewMatrix(), NL3D::CDriverGL::setupViewMatrixEx(), NL3D::CVegetableBlendLayerModel::setWorldPos(), NL3D::CPSZoneRectangle::show(), NL3D::CPSZoneCylinder::show(), NL3D::CPSZoneDisc::show(), NL3D::CPSEmitterRectangle::showTool(), NL3D::CWaterModel::traverseRender(), and NL3D::CAnimatedMaterial::update(). +

+

00268 {
+00269         a14= v.x;
+00270         a24= v.y;
+00271         a34= v.z;
+00272         if(a14!=0 || a24!=0 || a34!=0)
+00273                 StateBit|= MAT_TRANS;
+00274         else
+00275                 // The trans is identity
+00276                 StateBit&= ~MAT_TRANS;
+00277 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setProj const float  proj[4]  ) 
+
+ + + + + +
+   + + +

+Explicit setup the Projection component. Proj is tested to see if the matrix now have a projection component.

Parameters:
+ + +
proj the 4th line of the matrix. Set it to 0 0 0 1 to reset it to default.
+
+ +

+Definition at line 291 of file matrix.cpp. +

+References a41, a42, a43, a44, MAT_PROJ, MAT_VALIDPROJ, and StateBit. +

+

00292 {
+00293         a41= proj[0];
+00294         a42= proj[1];
+00295         a43= proj[2];
+00296         a44= proj[3];
+00297 
+00298         // Check Proj state.
+00299         if(a41!=0 || a42!=0 || a43!=0 || a44!=1)
+00300                 StateBit|= MAT_PROJ;
+00301         else
+00302         {
+00303                 // The proj is identity, and is correcly setup!
+00304                 StateBit&= ~MAT_PROJ;
+00305                 StateBit|= MAT_VALIDPROJ;
+00306         }
+00307 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setRot const CMatrix matrix  ) 
+
+ + + + + +
+   + + +

+Explicit setup the Rotation/Scale matrix (base) with the rotation part of an other matrix.

Parameters:
+ + +
matrix the matrix to copy rot part.
+
+ +

+Definition at line 243 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, hasRot(), hasScaleUniform(), MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, MAT_VALIDROT, matrix, Scale33, and StateBit. +

+

00244 {
+00245         // copy rotpart statebit from other.
+00246         StateBit&= ~(MAT_ROT | MAT_SCALEUNI | MAT_SCALEANY);
+00247         StateBit|= matrix.StateBit & (MAT_ROT | MAT_SCALEUNI | MAT_SCALEANY);
+00248         // copy values.
+00249         if(hasRot())
+00250         {
+00251                 a11= matrix.a11; a12= matrix.a12; a13= matrix.a13;
+00252                 a21= matrix.a21; a22= matrix.a22; a23= matrix.a23;
+00253                 a31= matrix.a31; a32= matrix.a32; a33= matrix.a33;
+00254                 // if has scale uniform, copy from matrix.
+00255                 if(hasScaleUniform())
+00256                         Scale33= matrix.Scale33;
+00257         }
+00258         else
+00259         {
+00260                 // we are rot identity, with undefined values.
+00261                 StateBit&= ~MAT_VALIDROT;
+00262         }
+00263 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setRot const CQuat quat  ) 
+
+ + + + + +
+   + + +

+Explicit setup the Rotation matrix (base) as a Quaternion rotation matrix.

Parameters:
+ + +
quat a UNIT qauternion
+
+ +

+Definition at line 1347 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, NLMISC::CQuatT< float >::isIdentity(), MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, Scale33, StateBit, NLMISC::CQuatT< float >::w, NLMISC::CQuatT< float >::x, NLMISC::CQuatT< float >::y, and NLMISC::CQuatT< float >::z. +

+

01348 {
+01349         // A quaternion do not have scale.
+01350         StateBit&= ~(MAT_ROT | MAT_SCALEANY|MAT_SCALEUNI);
+01351         Scale33= 1.0f;
+01352         if(quat.isIdentity())
+01353         {
+01354                 a11= 1; a12= 0; a13= 0; 
+01355                 a21= 0; a22= 1; a23= 0; 
+01356                 a31= 0; a32= 0; a33= 1; 
+01357         }
+01358         else
+01359         {
+01360                 StateBit|= MAT_ROT;
+01361                 float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
+01362 
+01363                 // calculate coefficients
+01364                 x2 = quat.x + quat.x; y2 = quat.y + quat.y; 
+01365                 z2 = quat.z + quat.z;
+01366                 xx = quat.x * x2;   xy = quat.x * y2;   xz = quat.x * z2;
+01367                 yy = quat.y * y2;   yz = quat.y * z2;   zz = quat.z * z2;
+01368                 wx = quat.w * x2;   wy = quat.w * y2;   wz = quat.w * z2;
+01369 
+01370                 a11 = 1.0f - (yy + zz);
+01371                 a12 = xy - wz;
+01372                 a13 = xz + wy;
+01373 
+01374                 a21 = xy + wz;
+01375                 a22 = 1.0f - (xx + zz);
+01376                 a23 = yz - wx;
+01377 
+01378                 a31 = xz - wy;
+01379                 a32 = yz + wx;
+01380                 a33 = 1.0f - (xx + yy);
+01381         }
+01382 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::setRot const CVector v,
TRotOrder  ro
+
+ + + + + +
+   + + +

+Explicit setup the Rotation matrix (base) as a Euler rotation matrix.

Parameters:
+ + + +
v a vector of 3 angle (in radian), giving rotation around each axis (x,y,z)
ro the order of transformation applied. if ro==XYZ, then the transform is M=M*Rx*Ry*Rz
+
+ +

+Definition at line 231 of file matrix.cpp. +

+References getRot(), identity(), rotate(), setRot(), and v. +

+

00232 {
+00233         CMatrix         rot;
+00234         rot.identity();
+00235         rot.rotate(v, ro);
+00236         float   m33[9];
+00237         rot.getRot(m33);
+00238         setRot(m33, true);
+00239 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::setRot const float  m33[9],
bool  hintNoScale = false
+
+ + + + + +
+   + + +

+Explicit setup the Rotation/Scale matrix (base). Avoid it. It implies low compute since no check is done on m33 to see what type of matrix it is (identity, raotation, scale, uniform scale)

Parameters:
+ + + +
m33 the 3*3 column rotation matrix. (3x3 matrix stored in column-major order as 9 consecutive values)
hintNoScale set it to true if you are sure that your rot matrix is a pure rot matrix with no scale. If set to true and your rotation is not an orthonormal basis, unpredictable result are excepted.
+
+ +

+Definition at line 220 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, Scale33, and StateBit. +

+

00221 {
+00222         StateBit|= MAT_ROT | MAT_SCALEANY;
+00223         if(hintNoScale)
+00224                 StateBit&= ~(MAT_SCALEANY|MAT_SCALEUNI);
+00225         a11= m33[0]; a12= m33[3]; a13= m33[6]; 
+00226         a21= m33[1]; a22= m33[4]; a23= m33[7]; 
+00227         a31= m33[2]; a32= m33[5]; a33= m33[8]; 
+00228         Scale33= 1.0f;
+00229 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void NLMISC::CMatrix::setRot const CVector i,
const CVector j,
const CVector k,
bool  hintNoScale = false
+
+ + + + + +
+   + + +

+Explicit setup the Rotation/Scale matrix (base). Avoid it. It implies low compute since no check is done on base to see what type of matrix it is (identity, rotation, scale, uniform scale...)

Parameters:
+ + + + + +
i The I vector of the cartesian base.
j The J vector of the cartesian base.
k The K vector of the cartesian base.
hintNoScale set it to true if you are sure that your rot matrix is a pure rot matrix with no scale. If set to true and your rotation is not an orthonormal basis, unpredictable result are excepted.
+
+ +

+Definition at line 209 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, Scale33, StateBit, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. +

+Referenced by NL3D::CVegetableManager::addInstance(), NL3D::CCameraCol::build(), NLMISC::CPolygon::buildBasis(), NL3D::CShadowMap::buildCasterCameraMatrix(), NL3D::CShadowMap::buildProjectionInfos(), NL3D::CPSUtil::buildSchmidtBasis(), NL3D::CCloud::calcBill(), NL3D::CCubeGrid< TCell >::CCubeGrid(), CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::compile(), NL3D::ComputeUpMatrix(), NL3D::CShadowMapManager::CShadowMapManager(), NL3D::CMaterial::decompUserTexMat(), NL3D::CCloud::disp(), NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CPSConstraintMeshHelper::drawMeshs(), NL3D::CTargetAnimCtrl::execute(), NL3D::CCloud::genBill(), NL3D::CVegetable::generateInstance(), NL3D::CPatch::generateTileVegetable(), NL3D::CPSZoneRectangle::getMatrix(), NL3D::CPSZoneCylinder::getMatrix(), NL3D::CPSEmitterRectangle::getMatrix(), NL3D::CBone::interpolateBoneSkinMatrix(), NL3D::CInstanceLighter::light(), NL3D::CInstanceLighter::lightIgSimple(), NL3D::CZoneLighter::lightWater(), NL3D::ITransformable::lookAt(), NL3D::CPSConstraintMesh::makePrerotatedVb(), NL3D::CSkeletonModel::renderIntoSkeletonShadowMap(), NL3D::CMeshInstance::renderIntoSkeletonShadowMap(), rotate(), NL3D::CQuadTree< T >::selectRay(), NL3D::CQuadTree< T >::selectSegment(), NL3D::CDriverUser::setMatrixMode2D(), NL3D::CCloud::setMode2D(), setRot(), NL3D::CMeshVPWindTree::setupPerInstanceConstants(), NL3D::CPSRibbon::setupTextureMatrix(), NL3D::CPSShockWave::setupUFactor(), NL3D::CDriverGL::setupViewMatrix(), NL3D::CDriverGL::setupViewMatrixEx(), NL3D::CPSZoneRectangle::show(), NL3D::CPSZoneCylinder::show(), NL3D::CPSLight::show(), NL3D::CPSEmitterRectangle::showTool(), NL3D::CAnimatedMaterial::update(), NL3D::CWaterModel::updateDiffuseMapMatrix(), and NL3D::CPSMesh::updatePos(). +

+

00210 {
+00211         StateBit|= MAT_ROT | MAT_SCALEANY;
+00212         if(hintNoScale)
+00213                 StateBit&= ~(MAT_SCALEANY|MAT_SCALEUNI);
+00214         a11= i.x; a12= j.x; a13= k.x; 
+00215         a21= i.y; a22= j.y; a23= k.y; 
+00216         a31= i.z; a32= j.z; a33= k.z; 
+00217         Scale33= 1.0f;
+00218 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setScale const CVector v  ) 
+
+ + + + + +
+   + + +

+Explicit setup the Rotation/Scale matrix (base) with a scale (=> matrix has no Rotation). case where v.x==v.y==v.z is tested to set a uniform scale

Parameters:
+ + +
scale the scale to set
+
+ +

+Definition at line 1478 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, MAT_VALIDROT, setScaleUni(), StateBit, and v. +

+

01479 {
+01480         // actually a scale uniform?
+01481         if(v.x==v.y && v.x==v.z)
+01482                 setScaleUni(v.x);
+01483 
+01484         // A Scale matrix do not have rotation.
+01485         StateBit&= ~(MAT_ROT | MAT_SCALEANY | MAT_SCALEUNI);
+01486         StateBit|= MAT_SCALEANY | MAT_VALIDROT;
+01487         a11= v.x; a12= 0; a13= 0; 
+01488         a21= 0; a22= v.y; a23= 0; 
+01489         a31= 0; a32= 0; a33= v.z; 
+01490         
+01491 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setScale float  scale  ) 
+
+ + + + + +
+   + + +

+Explicit setup the Rotation/Scale matrix (base) with a scale (=> matrix has no Rotation). 1 is tested to update bits accordingly

Parameters:
+ + +
scale the scale to set
+
+ +

+Definition at line 1471 of file matrix.cpp. +

+References setScaleUni(). +

+Referenced by NL3D::CBone::compute(). +

+

01472 {
+01473         setScaleUni(scale);
+01474 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::setScaleUni float  scale  )  [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1459 of file matrix.cpp. +

+References a11, a12, a13, a21, a22, a23, a31, a32, a33, MAT_ROT, MAT_SCALEANY, MAT_SCALEUNI, MAT_VALIDROT, Scale33, and StateBit. +

+Referenced by setScale(). +

+

01460 {
+01461         // A Scale matrix do not have rotation.
+01462         StateBit&= ~(MAT_ROT | MAT_SCALEANY | MAT_SCALEUNI);
+01463         StateBit|= MAT_SCALEUNI | MAT_VALIDROT;
+01464         Scale33= scale;
+01465         a11= scale; a12= 0; a13= 0; 
+01466         a21= 0; a22= scale; a23= 0; 
+01467         a31= 0; a32= 0; a33= scale; 
+01468 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CMatrix::slowInvert33 CMatrix ret  )  const [private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 999 of file matrix.cpp. +

+References getI(), getJ(), getK(), s, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. +

+Referenced by inverted(). +

+

01000 {
+01001         CVector invi,invj,invk;
+01002         CVector i,j,k;
+01003         double  s;
+01004 
+01005         i= getI();
+01006         j= getJ();
+01007         k= getK();
+01008         // Compute cofactors (minors *(-1)^(i+j)).
+01009         invi.x= j.y*k.z - k.y*j.z;
+01010         invi.y= j.z*k.x - k.z*j.x;
+01011         invi.z= j.x*k.y - k.x*j.y;
+01012         invj.x= k.y*i.z - i.y*k.z;
+01013         invj.y= k.z*i.x - i.z*k.x;
+01014         invj.z= k.x*i.y - i.x*k.y;
+01015         invk.x= i.y*j.z - j.y*i.z;
+01016         invk.y= i.z*j.x - j.z*i.x;
+01017         invk.z= i.x*j.y - j.x*i.y;
+01018         // compute determinant.
+01019         s= invi.x*i.x + invj.x*j.x + invk.x*k.x;
+01020         if(s==0)
+01021                 return false;
+01022         // Transpose the Comatrice, and divide by determinant.
+01023         s=1.0/s;
+01024         ret.a11= (float)(invi.x*s); ret.a12= (float)(invi.y*s); ret.a13= (float)(invi.z*s);
+01025         ret.a21= (float)(invj.x*s); ret.a22= (float)(invj.y*s); ret.a23= (float)(invj.z*s);
+01026         ret.a31= (float)(invk.x*s); ret.a32= (float)(invk.y*s); ret.a33= (float)(invk.z*s);
+01027 
+01028         return true;
+01029         // Roundly 82 cycles. (1Div=10 cycles).
+01030 }
+
+

+ + + + +
+ + + + + + + + + + +
bool NLMISC::CMatrix::slowInvert44 CMatrix ret  )  const [private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 1032 of file matrix.cpp. +

+References getCofactIndex(), mat(), s, and sint. +

+Referenced by inverted(). +

+

01033 {
+01034         sint    i,j;
+01035         double  s;
+01036 
+01037         // Compute Cofactors
+01038         //==================
+01039         for(i=0;i<=3;i++)
+01040         {
+01041                 for(j=0;j<=3;j++)
+01042                 {
+01043                         sint    l1,l2,l3;
+01044                         sint    c1,c2,c3;
+01045                         getCofactIndex(i,l1,l2,l3);
+01046                         getCofactIndex(j,c1,c2,c3);
+01047 
+01048                         ret.mat(i,j)= 0;
+01049                         ret.mat(i,j)+= mat(l1,c1) * mat(l2,c2) * mat(l3,c3);
+01050                         ret.mat(i,j)+= mat(l1,c2) * mat(l2,c3) * mat(l3,c1);
+01051                         ret.mat(i,j)+= mat(l1,c3) * mat(l2,c1) * mat(l3,c2);
+01052 
+01053                         ret.mat(i,j)-= mat(l1,c1) * mat(l2,c3) * mat(l3,c2);
+01054                         ret.mat(i,j)-= mat(l1,c2) * mat(l2,c1) * mat(l3,c3);
+01055                         ret.mat(i,j)-= mat(l1,c3) * mat(l2,c2) * mat(l3,c1);
+01056 
+01057                         if( (i+j)&1 )
+01058                                 ret.mat(i,j)=-ret.mat(i,j);
+01059                 }
+01060         }
+01061 
+01062         // Compute determinant.
+01063         //=====================
+01064         s= ret.mat(0,0) * mat(0,0) + ret.mat(0,1) * mat(0,1) + ret.mat(0,2) * mat(0,2) + ret.mat(0,3) * mat(0,3);
+01065         if(s==0)
+01066                 return false;
+01067 
+01068         // Divide by determinant.
+01069         //=======================
+01070         s=1.0/s;
+01071         for(i=0;i<=3;i++)
+01072         {
+01073                 for(j=0;j<=3;j++)
+01074                         ret.mat(i,j)= (float)(ret.mat(i,j)*s);
+01075         }
+01076 
+01077         // Transpose the comatrice.
+01078         //=========================
+01079         for(i=0;i<=3;i++)
+01080         {
+01081                 for(j=i+1;j<=3;j++)
+01082                 {
+01083                         swap(ret.mat(i,j), ret.mat(j,i));
+01084                 }
+01085         }
+01086 
+01087         return true;
+01088 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::testExpandProj  )  const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 149 of file matrix.cpp. +

+References hasProj(), MAT_VALIDPROJ, and StateBit. +

+Referenced by get(), inverted(), NLMISC::operator *(), operator *(), setMulMatrix(), and transpose(). +

+

00150 {
+00151         if(hasProj())
+00152                 return;
+00153         if(!(StateBit&MAT_VALIDPROJ))
+00154         {
+00155                 CMatrix *self= const_cast<CMatrix*>(this);
+00156                 self->StateBit|=MAT_VALIDPROJ;
+00157                 self->a41=0; self->a42=0; self->a43=0; self->a44=1; 
+00158         }
+00159 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::testExpandRot  )  const [inline, private]
+
+ + + + + +
+   + + +

+ +

+Definition at line 135 of file matrix.cpp. +

+References hasRot(), MAT_VALIDROT, Scale33, and StateBit. +

+Referenced by get(), inverted(), normalize(), NLMISC::operator *(), operator *(), rotateX(), rotateY(), rotateZ(), scale(), setMulMatrix(), and setMulMatrixNoProj(). +

+

00136 {
+00137         if(hasRot())
+00138                 return;
+00139         if(!(StateBit&MAT_VALIDROT))
+00140         {
+00141                 CMatrix *self= const_cast<CMatrix*>(this);
+00142                 self->StateBit|=MAT_VALIDROT;
+00143                 self->a11= 1; self->a12=0; self->a13=0;
+00144                 self->a21= 0; self->a22=1; self->a23=0;
+00145                 self->a31= 0; self->a32=0; self->a33=1;
+00146                 self->Scale33= 1;
+00147         }
+00148 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLMISC::CMatrix::translate const CVector v  ) 
+
+ + + + + +
+   + + +

+Apply a translation to the matrix. same as M=M*T. +

+Get Euler angles (in radians).

Parameters:
+ + +
ro the RotOrder which show how to get the euler.
+
+
Returns:
one solution of Euler angle. A rotate() with this value and the RotOrder ro will give the same matrix.
+
Todo:
yoyo: implement it.
+ +

+Definition at line 470 of file matrix.cpp. +

+References a11, a12, a13, a14, a21, a22, a23, a24, a31, a32, a33, a34, a41, a42, a43, a44, hasProj(), hasRot(), MAT_TRANS, StateBit, and v. +

+Referenced by NL3D::CShadowMap::buildCasterCameraMatrix(), NL3D::CInstanceGroup::getInstanceMatrix(), NL3D::CPSZoneDisc::getMatrix(), NL3D::CPSZoneSphere::getMatrix(), NL3D::CPSSphericalEmitter::getMatrix(), NL3D::CWaterShape::getShapeInWorldSpace(), NL3D::CPSGravity::show(), NL3D::ITransformable::updateMatrix(), and NL3D::CPSMesh::updatePos(). +

+

00471 {
+00472         // SetTrans.
+00473         if( hasRot() )
+00474         {
+00475                 a14+= a11*v.x + a12*v.y + a13*v.z;
+00476                 a24+= a21*v.x + a22*v.y + a23*v.z;
+00477                 a34+= a31*v.x + a32*v.y + a33*v.z;
+00478         }
+00479         else
+00480         {
+00481                 a14+= v.x;
+00482                 a24+= v.y;
+00483                 a34+= v.z;
+00484         }
+00485 
+00486         // SetProj.
+00487         if( hasProj() )
+00488                 a44+= a41*v.x + a42*v.y + a43*v.z;
+00489 
+00490         // Check Trans.
+00491         if(a14!=0 || a24!=0 || a34!=0)
+00492                 StateBit|= MAT_TRANS;
+00493         else
+00494                 // The trans is identity, and is correcly setup!
+00495                 StateBit&= ~MAT_TRANS;
+00496 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::transpose  ) 
+
+ + + + + +
+   + + +

+transpose the matrix (swap columns/lines). NB: this transpose the 4*4 matrix entirely (even proj/translate part). +

+Definition at line 935 of file matrix.cpp. +

+References a14, a24, a34, a41, a42, a43, hasProj(), hasTrans(), MAT_PROJ, MAT_TRANS, MAT_VALIDPROJ, StateBit, testExpandProj(), and transpose3x3(). +

+Referenced by NL3D::CVegetableManager::addInstance(), NL3D::CPSUtil::print(), and NL3D::CDriverGL::setConstantMatrix(). +

+

00936 {
+00937         transpose3x3();
+00938         if(hasTrans() || hasProj())
+00939         {
+00940                 // if necessary, Get valid 0 on proj part.
+00941                 testExpandProj();
+00942                 // swap values
+00943                 swap(a41, a14);
+00944                 swap(a42, a24);
+00945                 swap(a43, a34);
+00946                 // swap StateBit flags, if not both were sets...
+00947                 if(!hasTrans() || !hasProj())
+00948                 {
+00949                         // swap StateBit flags (swap trans with proj).
+00950                         if(hasTrans())
+00951                         {
+00952                                 StateBit&= ~MAT_TRANS;
+00953                                 StateBit|= MAT_PROJ;
+00954                         }
+00955                         else
+00956                         {
+00957                                 StateBit&= ~MAT_PROJ;
+00958                                 StateBit|= MAT_TRANS;
+00959                         }
+00960                 }
+00961                 // reset validity. NB, maybe not usefull, but simpler, and bugfree.
+00962                 StateBit&= ~(MAT_VALIDPROJ);
+00963         }
+00964         // NB: if no Trans or no Proj, do nothing, so don't need to modify VALIDTRANS and VALIDPROJ too.
+00965 }
+
+

+ + + + +
+ + + + + + + + + +
void NLMISC::CMatrix::transpose3x3  ) 
+
+ + + + + +
+   + + +

+transpose the rotation part only of the matrix (swap columns/lines). +

+Definition at line 922 of file matrix.cpp. +

+References a12, a13, a21, a23, a31, a32, and hasRot(). +

+Referenced by transpose(). +

+

00923 {
+00924         if(hasRot())
+00925         {
+00926                 // swap values.
+00927                 swap(a12, a21);
+00928                 swap(a13, a31);
+00929                 swap(a32, a23);
+00930                 // Scale mode (none, uni, or any) is conserved. Scale33 too...
+00931         }
+00932 }
+
+


Friends And Related Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
CPlane operator * const CPlane p,
const CMatrix m
[friend]
+
+ + + + + +
+   + + +

+Plane (line vector) multiplication. +

+ +

+Definition at line 1308 of file matrix.cpp. +

+

01309 {
+01310         // \todo yoyo: TODO_OPTIMIZE it...
+01311         m.testExpandRot();
+01312         m.testExpandProj();
+01313 
+01314 
+01315         CPlane  ret;
+01316 
+01317         if( m.StateBit & (MAT_ROT|MAT_SCALEUNI|MAT_SCALEANY|MAT_PROJ) )
+01318         {
+01319                 // Compose with translation too.
+01320                 ret.a= p.a*m.a11 + p.b*m.a21 + p.c*m.a31 + p.d*m.a41;
+01321                 ret.b= p.a*m.a12 + p.b*m.a22 + p.c*m.a32 + p.d*m.a42;
+01322                 ret.c= p.a*m.a13 + p.b*m.a23 + p.c*m.a33 + p.d*m.a43;
+01323                 ret.d= p.a*m.a14 + p.b*m.a24 + p.c*m.a34 + p.d*m.a44;
+01324                 return ret;
+01325         }
+01326         else if( m.StateBit & MAT_TRANS )
+01327         {
+01328 
+01329                 // Compose just with a translation.
+01330                 ret.a= p.a;
+01331                 ret.b= p.b;
+01332                 ret.c= p.c;
+01333                 ret.d= p.a*m.a14 + p.b*m.a24 + p.c*m.a34 + p.d*m.a44;
+01334                 return ret;
+01335         }
+01336         else    // Identity!!
+01337                 return p;
+01338 }
+
+


Field Documentation

+

+ + + + +
+ + +
const CMatrix NLMISC::CMatrix::Identity [static] +
+
+ + + + + +
+   + + +

+The identity matrix. Same as CMatrix(). +

+ +

+Definition at line 41 of file matrix.cpp.

+

+ + + + +
+ + +
float NLMISC::CMatrix::M[16] [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 353 of file matrix.h. +

+Referenced by operator=().

+

+ + + + +
+ + +
float NLMISC::CMatrix::Scale33 [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 354 of file matrix.h. +

+Referenced by fastInvert33(), getScaleUniform(), normalize(), operator=(), scale(), serial(), set(), setMulMatrix(), setMulMatrixNoProj(), setRot(), setScaleUni(), and testExpandRot().

+

+ + + + +
+ + +
uint32 NLMISC::CMatrix::StateBit [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 355 of file matrix.h. +

+Referenced by CMatrix(), fastInvert33(), getRot(), hasProj(), hasProjectionPart(), hasRot(), hasScalePart(), hasScaleUniform(), hasTrans(), identity(), inverted(), movePos(), normalize(), NLMISC::operator *(), operator=(), resetProj(), rotateX(), rotateY(), rotateZ(), scale(), serial(), set(), setMulMatrix(), setMulMatrixNoProj(), setPos(), setProj(), setRot(), setScale(), setScaleUni(), testExpandProj(), testExpandRot(), translate(), and transpose().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 13:21:55 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1