Beispiel #1
0
TEST(Skeleton, changingShapeBindMatrix)
{
   Skeleton testSkeleton;

   Matrix testInvMtx;
   testInvMtx.setTranslation( Vector( 5, 0, 0 ) );
   testSkeleton.setTransformation( "bone", testInvMtx );

   COMPARE_MTX( testInvMtx, testSkeleton.getInvBindPoseMtx( "bone" ) );

   // first change 
   Matrix changedShapeBindMtx;
   changedShapeBindMtx.setTranslation( Vector( 0, 5, 0 ) );
   testSkeleton.setShapeBindMatrix( changedShapeBindMtx );

   testInvMtx.setTranslation( Vector( 5, 5, 0 ) );
   COMPARE_MTX( testInvMtx, testSkeleton.getInvBindPoseMtx( "bone" ) );

   // second change
   changedShapeBindMtx.setTranslation( Vector( 0, 0, 5 ) );
   testSkeleton.setShapeBindMatrix( changedShapeBindMtx );

   testInvMtx.setTranslation( Vector( 5, 0, 5 ) );
   COMPARE_MTX( testInvMtx, testSkeleton.getInvBindPoseMtx( "bone" ) );
}
Beispiel #2
0
TEST( Transform, matrixConversion )
{
   // construct a transformation matrix we'll use for testing
   Matrix templateTranslationMtx;
   Quaternion testRot;
   Vector testTrans;
   {
      testRot.setAxisAngle( Quad_1000, FastFloat::fromFloat( DEG2RAD( 90.0f ) ) );
      templateTranslationMtx.setRotation( testRot );

      Matrix translationMtx;
      testTrans.set( 10, 20, 30 );
      translationMtx.setTranslation( testTrans );
      templateTranslationMtx.mul( translationMtx );
   }

   // first create a transform from the matrix
   Transform transform;
   transform.set( templateTranslationMtx );

   COMPARE_QUAT( testRot, transform.m_rotation );
   COMPARE_VEC( testTrans, transform.m_translation );

   // and then convert that transform back to a matrix form
   Matrix recoveredMtx;
   transform.toMatrix( recoveredMtx );
   COMPARE_MTX( templateTranslationMtx, recoveredMtx );
}
TEST( MatrixInterpolator, translation )
{
   Matrix start;
   Matrix end;
   Matrix expectedResult;

   start.setTranslation( Vector( 0, 0, 10 ) );
   end.setTranslation( Vector( 0, 0, 20 ) );

   Matrix result;

   expectedResult.setTranslation( Vector( 0, 0, 10 ) );
   MatrixUtils::lerp( start, end, Float_0, result );
   COMPARE_MTX( expectedResult, result );

   expectedResult.setTranslation( Vector( 0, 0, 20 ) );
   MatrixUtils::lerp( start, end, Float_1, result );
   COMPARE_MTX( expectedResult, result );

   expectedResult.setTranslation( Vector( 0, 0, 15 ) );
   MatrixUtils::lerp( start, end, Float_Inv2, result );
   COMPARE_MTX( expectedResult, result );
}
TEST( MatrixUtils, generateOrthogonalProjection )
{
   Matrix tamyMtx;
   D3DXMATRIX dxMtx;

   float width = 2.0f;
   float height = 2.0f;
   float nearZ = 1.01f;
   float farZ = 5000.0f;

   D3DXMatrixOrthoLH( &dxMtx, width, height, nearZ, farZ );
   MatrixUtils::generateOrthogonalProjection( width, height, nearZ, farZ, tamyMtx );
   COMPARE_MTX( dxMtx, tamyMtx );
}
TEST( MatrixUtils, generatePrespectiveProjection )
{
   Matrix tamyMtx;
   D3DXMATRIX dxMtx;

   float fov = DEG2RAD( 60.0f );
   float aspectRatio = 1.3333f;
   float nearZ = 1.01f;
   float farZ = 5000.0f;

   D3DXMatrixPerspectiveFovLH( &dxMtx, fov, aspectRatio, nearZ, farZ );
   MatrixUtils::generatePrespectiveProjection( fov, aspectRatio, nearZ, farZ, tamyMtx );
   COMPARE_MTX( dxMtx, tamyMtx );
}
TEST( MatrixInterpolator, rotation )
{
   Matrix start;
   Matrix end;

   start.setIdentity();
   EulerAngles ea;
   ea.set( FastFloat::fromFloat( 90.0f ), Float_0, Float_0 );
   end.setRotation( ea );

   Matrix result;

   MatrixUtils::lerp( start, end, Float_0, result );
   COMPARE_MTX( start, result );

   MatrixUtils::lerp( start, end, Float_1, result );
   COMPARE_MTX( end, result );

   Matrix expectedResult;
   ea.set( FastFloat::fromFloat( 45.0f ), Float_0, Float_0 );
   expectedResult.setRotation( ea );
   MatrixUtils::lerp( start, end, Float_Inv2, result );
   COMPARE_MTX(expectedResult, result );
}
Beispiel #7
0
TEST( Transform, advancedInversion )
{
   Transform transform1;
   {
      transform1.m_rotation.setAxisAngle( Quad_1000, FastFloat::fromFloat( DEG2RAD( 70.0f ) ) );
      transform1.m_translation.set( 2, 5, -1 );
   }

   Transform transform2;
   {
      transform2.m_rotation.setAxisAngle( Quad_0100, FastFloat::fromFloat( DEG2RAD( -75.0f ) ) );
      transform2.m_translation.set( -4, 2, 4 );
   }

   Matrix mtx1, mtx2;
   transform1.toMatrix( mtx1 );
   transform2.toMatrix( mtx2 );

   // test 1
   {
      Transform invTransform1;
      invTransform1.setInverse( transform1 );

      Matrix invMtx1;
      invMtx1.setInverse( mtx1 );

      Matrix testMtx;
      invTransform1.toMatrix( testMtx );
      COMPARE_MTX( testMtx, invMtx1 );
   }

   // test 2
   {
      Transform invTransform1;
      invTransform1.setInverse( transform1 );

      Transform subTransform;
      subTransform.setMul( transform2, invTransform1 );

      Matrix invMtx1;
      invMtx1.setInverse( mtx1 );

      Matrix subMtx;
      subMtx.setMul( mtx2, invMtx1 );

      Matrix testMtx;
      subTransform.toMatrix( testMtx );
      COMPARE_MTX( testMtx, subMtx );
   }

   // test 3
   {
      Transform subTransform;
      subTransform.setMulInverse( transform2, transform1 );

      Matrix invMtx1;
      invMtx1.setInverse( mtx1 );

      Matrix subMtx;
      subMtx.setMul( mtx2, invMtx1 );

      Matrix testMtx;
      subTransform.toMatrix( testMtx );
      COMPARE_MTX( testMtx, subMtx );
   }
}
Beispiel #8
0
TEST( Transform, multiplication )
{
   // The test is gonna be based on the comparison of this unverified method against
   // some verified method.
   // We'll use matrix multiplication as the verified form, and then we'll turn
   // our concatenated transform into a matrix and compare the two.

   // construct the component transformations
   Transform transA;
   {
      transA.m_rotation.setAxisAngle( Quad_1000, FastFloat::fromFloat( DEG2RAD( 45.0f ) ) );
      transA.m_translation.set( 2, 0, 0 );
   }
   Transform transB;
   {
      transB.m_rotation.setAxisAngle( Quad_0100, FastFloat::fromFloat( DEG2RAD( 45.0f ) ) );
      transB.m_translation.set( 0, 0, 1 );
   }

   // create the component transformation matrices
   Matrix expectedTransformationMtx;
   {
      Matrix mtxA, mtxB;
      transA.toMatrix( mtxA );
      transB.toMatrix( mtxB );
      expectedTransformationMtx.setMul( mtxA, mtxB );
   }


   // test the two param multiplication
   {
      // multiply the transforms using
      Transform concatenatedTransform;
      concatenatedTransform.setMul( transA, transB );

      Matrix transformationMtx;
      concatenatedTransform.toMatrix( transformationMtx );
   
      COMPARE_MTX( expectedTransformationMtx, transformationMtx );
   }

   // test the in-place post-multiplication
   {
      // multiply the transforms using
      Transform concatenatedTransform = transA;
      concatenatedTransform.mul( transB );

      Matrix transformationMtx;
      concatenatedTransform.toMatrix( transformationMtx );

      COMPARE_MTX( expectedTransformationMtx, transformationMtx );
   }

   // test the in-place pre-multiplication
   {
      // multiply the transforms using
      Transform concatenatedTransform = transB;
      concatenatedTransform.preMul( transA );

      Matrix transformationMtx;
      concatenatedTransform.toMatrix( transformationMtx );

      COMPARE_MTX( expectedTransformationMtx, transformationMtx );
   }
}