⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math_ops.cpp

📁 game programing code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::SetInvTranslation( float* fpVec )
{
	m_fMatrix[12]= -fpVec[0];
	m_fMatrix[13]= -fpVec[1];
	m_fMatrix[14]= -fpVec[2];
	m_fMatrix[15]= 1;
}

//--------------------------------------------------------------
// Name:		 CMATRIX::SetInvTranslation - public
// Description:	 Inversely translate the matrix based off of a
//				 vector
// Arguments:	 -vec: inverse translation vector
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::SetInvTranslation( CVECTOR vec )
{
	m_fMatrix[12]= -vec[0];
	m_fMatrix[13]= -vec[1];
	m_fMatrix[14]= -vec[2];
	m_fMatrix[15]= 1;
}

//--------------------------------------------------------------
// Name:		 CMATRIX::InvTranslateVec - public
// Description:	 Fill a vector with inverse translation info
// Arguments:	 -fpVec: 3 value array to fill
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::InvTranslateVec( float* fpVec )
{
	fpVec[0]= fpVec[0] - m_fMatrix[12];
	fpVec[1]= fpVec[1] - m_fMatrix[13];
	fpVec[2]= fpVec[2] - m_fMatrix[14];
}

//--------------------------------------------------------------
// Name:		 CMATRIX::InvTranslateVec - public
// Description:	 Inversely translate the matrix based off of a
//				 vector
// Arguments:	 -pVec: inverse translation vector
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::InvTranslateVec( CVECTOR* pVec )
{
	pVec[0]= pVec[0] - m_fMatrix[12];
	pVec[1]= pVec[1] - m_fMatrix[13];
	pVec[2]= pVec[2] - m_fMatrix[14];
}

//--------------------------------------------------------------
// Name:		 CMATRIX::SetRotation - public
// Description:	 Set the matrix's rotation based off of a
//				 3 value array
// Arguments:	 -fpVec: 3 value array with rotation info
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::SetRotation( float* fpVec )
{
	float CX= cosf( fpVec[0] );
	float SX= sinf( fpVec[0] );
	float CY= cosf( fpVec[1] );
	float SY= sinf( fpVec[1] );
	float CZ= cosf( fpVec[2] );
	float SZ= sinf( fpVec[2] );

	m_fMatrix[0] = CY * CZ;
	m_fMatrix[1] = CY * SZ;
	m_fMatrix[2] =-SY;

	m_fMatrix[4] = SX * SY * CZ - CX * SZ;
	m_fMatrix[5] = SX * SY * SZ + CX * CZ;
	m_fMatrix[6] = SX * CY;

	m_fMatrix[8] = CX * SY * CZ + SX * SZ;
	m_fMatrix[9] = CX * SY * SZ - SX * CZ;
	m_fMatrix[10]= CX * CY;

	m_fMatrix[15]= 1;
}

//--------------------------------------------------------------
// Name:		 CMATRIX::SetRotation - public
// Description:	 Set the matrix's rotation based off of 
//				 vector
// Arguments:	 -vec: rotation vector
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::SetRotation( CVECTOR vec )
{
	float CX= cosf( vec[0] );
	float SX= sinf( vec[0] );
	float CY= cosf( vec[1] );
	float SY= sinf( vec[1] );
	float CZ= cosf( vec[2] );
	float SZ= sinf( vec[2] );

	m_fMatrix[0] = CY * CZ;
	m_fMatrix[1] = CY * SZ;
	m_fMatrix[2] =-SY;

	m_fMatrix[4] = SX * SY * CZ - CX * SZ;
	m_fMatrix[5] = SX * SY * SZ + CX * CZ;
	m_fMatrix[6] = SX * CY;

	m_fMatrix[8] = CX * SY * CZ + SX * SZ;
	m_fMatrix[9] = CX * SY * SZ - SX * CZ;
	m_fMatrix[10]= CX * CY;

	m_fMatrix[15]= 1;
}

//--------------------------------------------------------------
// Name:		 CMATRIX::SetInvRotation - public
// Description:	 Inversely rotate the matrix based off of a
//				 3 value array
// Arguments:	 -fpVec: 3 value array with inverse rotation info
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::SetInvRotation( float* fpVec )
{
	float CX= cosf( fpVec[0] );
	float SX= sinf( fpVec[0] );
	float CY= cosf( fpVec[1] );
	float SY= sinf( fpVec[1] );
	float CZ= cosf( fpVec[2] );
	float SZ= sinf( fpVec[2] );

	m_fMatrix[0] = CY * CZ;
	m_fMatrix[4] = CY * SZ;
	m_fMatrix[8] =-SY;

	m_fMatrix[1] = SX * SY * CZ - CX * SZ;
	m_fMatrix[5] = SX * SY * SZ + CX * CZ;
	m_fMatrix[9] = SX * CY;

	m_fMatrix[2] = CX * SY * CZ + SX * SZ;
	m_fMatrix[6] = CX * SY * SZ - SX * CZ;
	m_fMatrix[10]= CX * CY;

	m_fMatrix[15]= 1;
}

//--------------------------------------------------------------
// Name:		 CMATRIX::SetInvRotation - public
// Description:	 Inversely rotate the matrix based off of a
//				 vector
// Arguments:	 -vec: inverse rotation vector
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::SetInvRotation( CVECTOR vec )
{
	float CX= cosf( vec[0] );
	float SX= sinf( vec[0] );
	float CY= cosf( vec[1] );
	float SY= sinf( vec[1] );
	float CZ= cosf( vec[2] );
	float SZ= sinf( vec[2] );

	m_fMatrix[0] = CY * CZ;
	m_fMatrix[4] = CY * SZ;
	m_fMatrix[8] =-SY;

	m_fMatrix[1] = SX * SY * CZ - CX * SZ;
	m_fMatrix[5] = SX * SY * SZ + CX * CZ;
	m_fMatrix[9] = SX * CY;

	m_fMatrix[2] = CX * SY * CZ + SX * SZ;
	m_fMatrix[6] = CX * SY * SZ - SX * CZ;
	m_fMatrix[10]= CX * CY;

	m_fMatrix[15]= 1;
}

//--------------------------------------------------------------
// Name:		 CMATRIX::InvRotateVec - public
// Description:	 Fill a vector with inverse rotation info
// Arguments:	 -fpVec: 3 value array to fill
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::InvRotateVec( float* fpVec )
{
	float fVec[3];
	
	fVec[0]= fpVec[0]*m_fMatrix[0] +
			 fpVec[1]*m_fMatrix[1] +
			 fpVec[2]*m_fMatrix[2];

	fVec[1]= fpVec[0]*m_fMatrix[4] +
			 fpVec[1]*m_fMatrix[5] +
			 fpVec[2]*m_fMatrix[6];

	fVec[2]= fpVec[0]*m_fMatrix[8] +
			 fpVec[1]*m_fMatrix[9] +
			 fpVec[2]*m_fMatrix[10];

	//copy the results from the calculations
	memcpy( fpVec, fVec, sizeof( float[3] ) );
}

//--------------------------------------------------------------
// Name:		 CMATRIX::InvRotateVec - public
// Description:	 Inversely rotate the matrix based off of a
//				 vector
// Arguments:	 -pVec: inverse rotation vector
// Return Value: None
//--------------------------------------------------------------
void CMATRIX::InvRotateVec( CVECTOR* pVec )
{
	float* fpVec;
	float fVec[3];

	//copy the information from the vector into a local buffer
	fpVec= pVec->Get( );
	
	fVec[0]= fpVec[0]*m_fMatrix[0] +
			 fpVec[1]*m_fMatrix[1] +
			 fpVec[2]*m_fMatrix[2];

	fVec[1]= fpVec[0]*m_fMatrix[4] +
			 fpVec[1]*m_fMatrix[5] +
			 fpVec[2]*m_fMatrix[6];

	fVec[2]= fpVec[0]*m_fMatrix[8] +
			 fpVec[1]*m_fMatrix[9] +
			 fpVec[2]*m_fMatrix[10];

	//copy the results from the calculations
	pVec->Set( fVec );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -