Commit 14a4a07e authored by cutealien's avatar cutealien

Add documentation and some compile-tests for matrix.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4231 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 238f3b7b
......@@ -67,7 +67,7 @@ namespace core
//! Simple operator for directly accessing every element of the matrix.
T& operator()(const s32 row, const s32 col)
{
{
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
......@@ -79,9 +79,9 @@ namespace core
//! Simple operator for linearly accessing every element of the matrix.
T& operator[](u32 index)
{
{
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
definitelyIdentityMatrix=false;
#endif
return M[index];
}
......@@ -97,8 +97,8 @@ namespace core
//! Returns pointer to internal array
const T* pointer() const { return M; }
T* pointer()
{
T* pointer()
{
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
......@@ -225,6 +225,8 @@ namespace core
//! An alternate transform vector method, writing into an array of 4 floats
void transformVect(T *out,const core::vector3df &in) const;
//! An alternate transform vector method, reading from and writing to an array of 3 floats
void transformVec3(T *out, const T * in) const;
//! Translate a vector by the translation part of this matrix.
......@@ -953,25 +955,25 @@ namespace core
const f64 c = cos( angle );
const f64 s = sin( angle );
const f64 t = 1.0 - c;
const f64 tx = t * axis.X;
M[0] = tx * axis.X + c;
M[1] = tx * axis.Y - s * axis.Z;
M[2] = tx * axis.Z + s * axis.Y;
const f64 ty = t * axis.Y;
M[4] = ty * axis.X + s * axis.Z;
M[5] = ty * axis.Y + c;
M[6] = ty * axis.Z - s * axis.X;
const f64 tz = t * axis.Z;
M[8] = tz * axis.X - s * axis.Y;
M[9] = tz * axis.Z + s * axis.X;
M[10] = tz * axis.Z + c;
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
......@@ -987,25 +989,25 @@ namespace core
const f64 c = cos(angle);
const f64 s = sin(angle);
const f64 t = 1.0 - c;
const f64 tx = t * axis.X;
M[0] = tx * axis.X + c;
M[1] = tx * axis.Y + s * axis.Z;
M[2] = tx * axis.Z - s * axis.Y;
const f64 ty = t * axis.Y;
M[4] = ty * axis.X - s * axis.Z;
M[5] = ty * axis.Y + c;
M[6] = ty * axis.Z + s * axis.X;
const f64 tz = t * axis.Z;
M[8] = tz * axis.X + s * axis.Y;
M[9] = tz * axis.Z - s * axis.X;
M[10] = tz * axis.Z + c;
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
......@@ -1982,7 +1984,7 @@ namespace core
v.normalize();
// cosinus angle
T ca = f.dotProduct(t);
T ca = f.dotProduct(t);
core::vector3df vt(v * (1 - ca));
......@@ -2043,7 +2045,7 @@ namespace core
const core::vector3df vs = look.crossProduct(from);
// cosinus angle
const f32 ca = from.dotProduct(look);
const f32 ca = from.dotProduct(look);
core::vector3df vt(up * (1.f - ca));
......
......@@ -236,11 +236,108 @@ bool isOrthogonal(void)
return true;
}
// just calling each function once to find compile problems
void calltest()
{
matrix4 mat;
matrix4 mat2(mat);
f32& f1 = mat(0,0);
const f32& f2 = mat(0,0);
f32& f3 = mat[0];
const f32& f4 = mat[0];
mat = mat;
mat = 1.f;
const f32 * pf1 = mat.pointer();
f32 * pf2 = mat.pointer();
bool b = mat == mat2;
b = mat != mat2;
mat = mat + mat2;
mat += mat2;
mat = mat - mat2;
mat -= mat2;
mat.setbyproduct(mat, mat2);
mat.setbyproduct_nocheck(mat, mat2);
mat = mat * mat2;
mat *= mat2;
mat = mat * 10.f;
mat *= 10.f;
mat.makeIdentity();
b = mat.isIdentity();
b = mat.isOrthogonal();
b = mat.isIdentity_integer_base ();
mat.setTranslation(vector3df(1.f, 1.f, 1.f) );
vector3df v1 = mat.getTranslation();
mat.setInverseTranslation(vector3df(1.f, 1.f, 1.f) );
mat.setRotationRadians(vector3df(1.f, 1.f, 1.f) );
mat.setRotationDegrees(vector3df(1.f, 1.f, 1.f) );
vector3df v2 = mat.getRotationDegrees();
mat.setInverseRotationRadians(vector3df(1.f, 1.f, 1.f) );
mat.setInverseRotationDegrees(vector3df(1.f, 1.f, 1.f) );
mat.setRotationAxisRadiansLH(1.f, vector3df(1.f, 1.f, 1.f) );
mat.setRotationAxisRadiansRH(1.f, vector3df(1.f, 1.f, 1.f) );
mat.setScale(vector3df(1.f, 1.f, 1.f) );
mat.setScale(1.f);
vector3df v3 = mat.getScale();
mat.inverseTranslateVect(v1);
mat.inverseRotateVect(v1);
mat.rotateVect(v1);
mat.rotateVect(v1, v2);
f32 fv3[3];
mat.rotateVect(fv3, v1);
mat.transformVect(v1);
mat.transformVect(v1, v1);
f32 fv4[4];
mat.transformVect(fv4, v1);
mat.transformVec3(fv3, fv3);
mat.translateVect(v1);
plane3df p1;
mat.transformPlane(p1);
mat.transformPlane(p1, p1);
aabbox3df bb1;
mat.transformBox(bb1);
mat.transformBoxEx(bb1);
mat.multiplyWith1x4Matrix(fv4);
mat.makeInverse();
b = mat.getInversePrimitive(mat2);
b = mat.getInverse(mat2);
mat.buildProjectionMatrixPerspectiveFovRH(1.f, 1.f, 1.f, 1000.f);
mat.buildProjectionMatrixPerspectiveFovLH(1.f, 1.f, 1.f, 1000.f);
mat.buildProjectionMatrixPerspectiveFovInfinityLH(1.f, 1.f, 1.f);
mat.buildProjectionMatrixPerspectiveRH(100.f, 100.f, 1.f, 1000.f);
mat.buildProjectionMatrixPerspectiveLH(10000.f, 10000.f, 1.f, 1000.f);
mat.buildProjectionMatrixOrthoLH(10000.f, 10000.f, 1.f, 1000.f);
mat.buildProjectionMatrixOrthoRH(10000.f, 10000.f, 1.f, 1000.f);
mat.buildCameraLookAtMatrixLH(vector3df(1.f, 1.f, 1.f), vector3df(0.f, 0.f, 0.f), vector3df(0.f, 1.f, 0.f) );
mat.buildCameraLookAtMatrixRH(vector3df(1.f, 1.f, 1.f), vector3df(0.f, 0.f, 0.f), vector3df(0.f, 1.f, 0.f) );
mat.buildShadowMatrix(vector3df(1.f, 1.f, 1.f), p1);
core::rect<s32> a1(0,0,100,100);
mat.buildNDCToDCMatrix(a1, 1.f);
mat.interpolate(mat2, 1.f);
mat = mat.getTransposed();
mat.getTransposed(mat2);
mat.buildRotateFromTo(vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f));
mat.setRotationCenter(vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f));
mat.buildAxisAlignedBillboard(vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f), vector3df(1.f, 1.f, 1.f));
mat.buildTextureTransform( 1.f,vector2df(1.f, 1.f), vector2df(1.f, 1.f), vector2df(1.f, 1.f));
mat.setTextureRotationCenter( 1.f );
mat.setTextureTranslate( 1.f, 1.f );
mat.setTextureTranslateTransposed(1.f, 1.f);
mat.setTextureScale( 1.f, 1.f );
mat.setTextureScaleCenter( 1.f, 1.f );
f32 fv16[16];
mat.setM(fv16);
mat.setDefinitelyIdentityMatrix(false);
b = mat.getDefinitelyIdentityMatrix();
b = mat.equals(mat2);
f1 = f1+f2+f3+f4+*pf1+*pf2; // getting rid of unused variable warnings.
}
}
bool matrixOps(void)
{
bool result = true;
calltest();
result &= identity();
result &= rotations();
result &= isOrthogonal();
......
Tests finished. 1 test of 1 passed.
Compiled as DEBUG
Test suite pass at GMT Sat Jul 7 09:09:13 2012
Test suite pass at GMT Sat Jul 7 10:28:50 2012
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment