Ejemplo n.º 1
0
	matrix4x4 perspective_proj_matrix_rh_gl(real const& l, real const& r, real const& b, real const& t, real const& n, real const& f)
	{
		return matrix4x4(2*n/(r-l), 0, 0, 0,
			0, 2*n/(t-b), 0, 0,
			(r + l)/(r - l), (t + b)/(t - b), -(f + n)/(f - n), -1,
			0, 0, -2*f*n/(f - n), 0);
	}
Ejemplo n.º 2
0
	matrix4x4 rotation_matrix_z(real const& ang)
	{
		return matrix4x4(cos(ang), sin(ang), 0, 0,
			-sin(ang), cos(ang), 0, 0,
			0, 0, 1, 0,
			0, 0, 0, 1);
	}
Ejemplo n.º 3
0
	matrix4x4 perspective_proj_matrix_lh_dx(real const& l, real const& r, real const& b, real const& t, real const& n, real const& f)
	{
		return matrix4x4(2*n/(r-l), 0, 0, 0, 
			0, 2*n/(t-b), 0, 0,
			-(r + l)/(r - l), -(t + b)/(t - b), f/(f - n), 1,
			0, 0, -f*n/(f - n), 0);  
	}
Ejemplo n.º 4
0
	matrix4x4 translation_matrix(vector3 const& v)
	{
		return matrix4x4 (1, 0, 0, 0, 
			0, 1, 0, 0, 
			0, 0, 1, 0, 
			v.x(), v.y(), v.z(), 1);
	}
Ejemplo n.º 5
0
	matrix4x4 lookat_matrix_lh_dx( vector3 const& pos, vector3 const& at, vector3 const& up)
	{
		vector3 v = normalize(at - pos);
		vector3 r = cross(normalize(up), v);
		vector3 u = cross(v,r);
		vector3 ip = vector3(-dot(r,pos), -dot(u,pos), -dot(v,pos));
		
		return matrix4x4(r.x(), u.x(), v.x(), 0,
						 r.y(), u.y(), v.y(), 0,
						 r.z(), u.z(), v.z(), 0,
						 ip.x(), ip.y(), ip.z(), 1);
	}
Ejemplo n.º 6
0
void CRotDoor :: OnClearParent( void )
{
	matrix4x4 parent = GetParentToWorldTransform();
	matrix4x4 angle1 = parent.ConcatTransforms( matrix4x4( g_vecZero, m_vecAngle1 ));

	angle1.GetAngles( m_vecAngle1 );

	// just recalc angle2 without transforms
	m_vecAngle2 = m_vecAngle1 + pev->movedir * m_flMoveDistance;

	// update angles if needed
	if( GetState() == STATE_ON )
		SetAbsAngles( m_vecAngle2 );
	else if( GetState() == STATE_OFF )
		SetAbsAngles( m_vecAngle1 );
}
Ejemplo n.º 7
0
        quaternion(vector3 vDir)
        {
            vector3 vUp (vDir);
            vector3 vDirection (1, 0, 0);
            vector3 vRight = vUp.crossProduct(vDirection);


            // Step 2. Put the three vectors into the matrix to bulid a basis rotation matrix
            // This step isnt necessary, but im adding it because often you would want to convert from matricies to quaternions instead of vectors to quaternions
            // If you want to skip this step, you can use the vector values directly in the quaternion setup below
            matrix4x4 mBasis= matrix4x4(vRight.x, vRight.y, vRight.z, 0.0f,
                                        vUp.x, vUp.y, vUp.z, 0.0f,
                                        vDirection.x, vDirection.y, vDirection.z, 0.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f);

            // Step 3. Build a quaternion from the matrix
            w = (float)Ogre::Math::Sqrt(1.0f + mBasis[0][0] + mBasis[1][1] + mBasis[2][2]) / 2.0f;
            double dfWScale = w * 4.0;
            x = (float)((mBasis[2][1] - mBasis[1][2]) / dfWScale);
            y = (float)((mBasis[0][2] - mBasis[2][0]) / dfWScale);
            z = (float)((mBasis[1][0] - mBasis[0][1]) / dfWScale);
        }
Ejemplo n.º 8
0
Matrix4x4 SceneGraph::local_pose(TransformInstance i) const
{
	Matrix4x4 tr = matrix4x4(rotation(_data.local[i.i].rotation), _data.local[i.i].position);
	set_scale(tr, _data.local[i.i].scale);
	return tr;
}
Ejemplo n.º 9
0
/**
 ****************************************************************************************************
	\fn			void UnitTest( void )
	\brief		The unit test of Matrix class
	\param		NONE
	\return		NONE
 ****************************************************************************************************
*/
void GameEngine::Math::Matrix::UnitTest( void )
{
	FUNCTION_START;

	Matrix matrix2x2( 2, 2 );

	// Check creation
	for( UINT8 i = 0; i < 2; ++i )
	{
		for( UINT8 j = 0; j < 2; ++j )
			assert( matrix2x2(i, j) == 0 );
	}

	// Check matrix identity
	matrix2x2(0, 0) = 1;
	matrix2x2(0, 1) = 2;
	matrix2x2(1, 0) = 3;
	matrix2x2(1, 1) = 4;
	Matrix identityMatrix( 2, 2 );
	identityMatrix(0, 0) = 1;
	identityMatrix(1, 1) = 1;
	Matrix m( 2, 2 );
	m = matrix2x2.Identity();
	assert( matrix2x2.Identity() == identityMatrix );

	// Check matrix transpose
	Matrix matrix2x3( 2, 3 );
	matrix2x3( 0, 0 ) = 1;
	matrix2x3( 0, 1 ) = 2;
	matrix2x3( 0, 2 ) = 3;
	matrix2x3( 1, 0 ) = 4;
	matrix2x3( 1, 1 ) = 5;
	matrix2x3( 1, 2 ) = 6;
	matrix2x3.Transpose();
	Matrix matrix3x2( 3, 2 );
	matrix3x2( 0, 0 ) = 1;
	matrix3x2( 0, 1 ) = 4;
	matrix3x2( 1, 0 ) = 2;
	matrix3x2( 1, 1 ) = 5;
	matrix3x2( 2, 0 ) = 3;
	matrix3x2( 2, 1 ) = 6;
	assert( matrix2x3 == matrix3x2 );

	// Check matrix 3x3 inverse
	Matrix matrix3x3( 3, 3 );
	matrix3x3( 0, 0 ) = 2;
	matrix3x3( 0, 1 ) = -1;
	matrix3x3( 0, 2 ) = 3;
	matrix3x3( 1, 0 ) = 1;
	matrix3x3( 1, 1 ) = 6;
	matrix3x3( 1, 2 ) = -4;
	matrix3x3( 2, 0 ) = 5;
	matrix3x3( 2, 1 ) = 0;
	matrix3x3( 2, 2 ) = 8;
	Matrix matrix3x3Inverse( 3, 3 );
	Matrix3Inverse( matrix3x3, matrix3x3Inverse );
	assert( (matrix3x3 * matrix3x3Inverse) == matrix3x3.Identity() );

	// Check matrix 4x4 inverse
	Matrix matrix4x4( 4, 4 );
	matrix4x4( 0, 0 ) = 2;
	matrix4x4( 0, 1 ) = 3;
	matrix4x4( 0, 2 ) = 4;
	matrix4x4( 0, 3 ) = 5;
	matrix4x4( 1, 0 ) = 5;
	matrix4x4( 1, 1 ) = 7;
	matrix4x4( 1, 2 ) = 9;
	matrix4x4( 1, 3 ) = 9;
	matrix4x4( 2, 0 ) = 5;
	matrix4x4( 2, 1 ) = 8;
	matrix4x4( 2, 2 ) = 7;
	matrix4x4( 2, 3 ) = 4;
	matrix4x4( 3, 0 ) = 4;
	matrix4x4( 3, 1 ) = 3;
	matrix4x4( 3, 2 ) = 3;
	matrix4x4( 3, 3 ) = 2;
	Matrix matrix4x4Inverse( 4, 4 );
	Matrix4Inverse( matrix4x4, matrix4x4Inverse );
	Matrix matrix4x4Result( 4, 4 );
	matrix4x4Result = matrix4x4 * matrix4x4Inverse;
	assert( (matrix4x4 * matrix4x4Inverse) == matrix4x4.Identity() );

	FUNCTION_FINISH;
}
Ejemplo n.º 10
0
	matrix4x4 scale_matrix(vector3 const& v)
	{
		return matrix4x4(v.x(), 0, 0, 0, 0, v.y(), 0, 0, 0, 0, v.z(), 0, 0, 0, 0, 1);
	}
Ejemplo n.º 11
0
	matrix4x4 rotation_matrix(vector3 const& axis, real const& ang)
	{
		// TODO: need to implement this
		assert(false);
		return matrix4x4();
	}