TEST( Plane, normalize ) { Plane tamyPlane; D3DXPLANE dxPlane; tamyPlane.set( Float_1, Float_2, FastFloat::fromFloat( -3.0f ), FastFloat::fromFloat( 10.0f ) ); D3DXPlaneNormalize( &dxPlane, ( const D3DXPLANE* )&tamyPlane ); tamyPlane.normalize(); COMPARE_PLANE( dxPlane, tamyPlane ); tamyPlane.set( Float_Minus1, Float_Minus1, Float_0, Float_Minus1 ); D3DXPlaneNormalize( &dxPlane, ( const D3DXPLANE* )&tamyPlane ); tamyPlane.normalize(); COMPARE_PLANE( dxPlane, tamyPlane ); }
TEST( Transform, planeTransformation ) { // construct a transformation we'll use for testing Transform trans; Matrix transformMtx; { Matrix m1, m2; EulerAngles angles; angles.set( FastFloat::fromFloat( 45.0f ), FastFloat::fromFloat( 60.0f ), FastFloat::fromFloat( -10.0f ) ); m1.setTranslation( Vector( 1, 2, 3 ) ); m2.setRotation( angles ); transformMtx.setMul( m2, m1 ); trans.set( transformMtx ); } // create a test plane Plane testPlane; testPlane.set( Float_1, Float_0, Float_0, FastFloat::fromFloat( 10.0f ) ); // transform the plane Plane tamyTransformedPlane; trans.transform( testPlane, tamyTransformedPlane ); // let DX help us generate a transformed plane we can compare our results against D3DXPLANE dxTransformedPlane; D3DXMATRIX dxMtx = ( const D3DXMATRIX& )transformMtx; D3DXMatrixInverse( &dxMtx, NULL, &dxMtx ); D3DXMatrixTranspose( &dxMtx, &dxMtx ); D3DXPlaneTransform( &dxTransformedPlane, ( const D3DXPLANE* )&testPlane, &dxMtx ); COMPARE_PLANE( dxTransformedPlane, tamyTransformedPlane ); }
TEST( Plane, setFromPoints ) { Plane tamyPlane; D3DXPLANE dxPlane; Vector ptA, ptB, ptC; ptA.set( 0, 0, 0 ); ptB.set( 10, 0, 0 ); ptC.set( 0, 10, 0 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); ptA.set( 0, 0, 0 ); ptB.set( 10, 0, 0 ); ptC.set( 0, 0, 10 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); ptA.set( 0, 0, 0 ); ptB.set( 0, 10, 0 ); ptC.set( 0, 0, 10 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); ptA.set( 0, 0, 0 ); ptB.set( 3, 0, 0 ); ptC.set( 0, -4, 0 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); ptA.set( 0, 0, 0 ); ptB.set( -10, 0, 0 ); ptC.set( 0, 0, -5 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); ptA.set( 0, 0, 0 ); ptB.set( 0, -10, 0 ); ptC.set( 0, 0, -10 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); ptA.set( 20, 3, -4 ); ptB.set( 5, -10, 1 ); ptC.set( 2, -1, -10 ); D3DXPlaneFromPoints( &dxPlane, ( const D3DXVECTOR3* )&ptA, ( const D3DXVECTOR3* )&ptB, ( const D3DXVECTOR3* )&ptC ); tamyPlane.setFromPoints( ptA, ptB, ptC ); COMPARE_PLANE( dxPlane, tamyPlane ); }
TEST( Plane, setFromPointNormal ) { Plane tamyPlane; D3DXPLANE dxPlane; Vector point, normal; point.set( 10, 20, 30 ); normal.set( Quad_1000 ); D3DXPlaneFromPointNormal( &dxPlane, ( const D3DXVECTOR3* )&point, ( const D3DXVECTOR3* )&normal ); tamyPlane.setFromPointNormal( point, normal ); COMPARE_PLANE( dxPlane, tamyPlane ); point.set( -4, 0, 5.5f ); normal.set( Quad_0100 ); D3DXPlaneFromPointNormal( &dxPlane, ( const D3DXVECTOR3* )&point, ( const D3DXVECTOR3* )&normal ); tamyPlane.setFromPointNormal( point, normal ); COMPARE_PLANE( dxPlane, tamyPlane ); point.set( 0, 0, -20.0f ); normal.set( Quad_0010 ); D3DXPlaneFromPointNormal( &dxPlane, ( const D3DXVECTOR3* )&point, ( const D3DXVECTOR3* )&normal ); tamyPlane.setFromPointNormal( point, normal ); COMPARE_PLANE( dxPlane, tamyPlane ); point.set( 10, 20, 30 ); normal.set( Quad_Neg_1000 ); D3DXPlaneFromPointNormal( &dxPlane, ( const D3DXVECTOR3* )&point, ( const D3DXVECTOR3* )&normal ); tamyPlane.setFromPointNormal( point, normal ); COMPARE_PLANE( dxPlane, tamyPlane ); point.set( -4, 0, 5.5f ); normal.set( Quad_Neg_0100 ); D3DXPlaneFromPointNormal( &dxPlane, ( const D3DXVECTOR3* )&point, ( const D3DXVECTOR3* )&normal ); tamyPlane.setFromPointNormal( point, normal ); COMPARE_PLANE( dxPlane, tamyPlane ); point.set( 0, 0, -20.0f ); normal.set( Quad_Neg_0010 ); D3DXPlaneFromPointNormal( &dxPlane, ( const D3DXVECTOR3* )&point, ( const D3DXVECTOR3* )&normal ); tamyPlane.setFromPointNormal( point, normal ); COMPARE_PLANE( dxPlane, tamyPlane ); }