|
|

楼主 |
发表于 2006-4-10 12:41:00
|
显示全部楼层
Re:[求助]立方体旋转问题(急急急!!!)
谢谢,这个初始化解决的,但是按下方向键去不会旋转,郁闷了。主要问题是类CCube中的函数UpdateMatrix()写不好。
class CCube
{
public:
D3DXVECTOR3 m_pos; // origin of object
FLOAT m_fRotX; // rotation of object around X axis
FLOAT m_fRotY; // rotation of object around Y axis
D3DXMATRIXA16 m_mat;
public:
VOID Init(VOID)
{
// Pick a random position and orientation
m_pos = D3DXVECTOR3( (FLOAT)(rand() % 50 - 25), // X is in (-25.0, 25.0)
(FLOAT)(rand() % 50 - 25), // Y is in (-25.0, 25.0)
(FLOAT)(rand() % 25) ); // Z is in ( 0.0, 25.0)
m_fRotX = D3DXToRadian(rand() % 360);
m_fRotY = D3DXToRadian(rand() % 360);
UpdateMatrix();
//m_cullstate = CS_UNKNOWN;
}
VOID UpdateMatrix(VOID)
{
// Recompute m_mat, m_vecBoundsWorld, and m_planeBoundsWorld
// when the thing's position, orientation, or bounding box has changed
D3DXMATRIXA16 matRotX, matRotY, matTrans;
D3DXMatrixRotationX( &matRotX, m_fRotX );
D3DXMatrixRotationY( &matRotY, m_fRotY );
D3DXMatrixTranslation( &matTrans, m_pos.x, m_pos.y, m_pos.z );
m_mat = matRotX * matRotY * matTrans;
}
};
这个UpdateMatrix()该怎么写?
请指教,不胜感激。 |
|