我有多个对象在 3D 空间中移动,我正在寻找方法来按下按钮,让相机捕捉并跟随所选对象。
有没有办法利用每个对象的世界矩阵?(下面是一个物体的例子。这个是一个自转和轨道的行星)
//set up matrices for rendering
D3DXMATRIX worldMatrixMer, viewMatrixMer, projectionMatrixMer;
m_Camera->GetViewMatrix(viewMatrixMer);
m_D3D->GetWorldMatrix(worldMatrixMer);
m_D3D->GetProjectionMatrix(projectionMatrixMer);
D3DXMatrixRotationX( &matRotateX, rx/65.0f);
//Rotate about Y axis
D3DXMatrixRotationY( &matRotateY, rotation * 15.0f);
D3DXMatrixRotationZ( &matRotateZ, rz/65.0f);
//Collate Rot Matrices
D3DXMATRIX rotMatrixMer = matRotateX * matRotateY * matRotateZ;
D3DXVECTOR3 newVecDirMer;
D3DXVec3TransformCoord(&newVecDirMer, &initVecDirMer, &rotMatrixMer);
D3DXVec3Normalize( ¤tVecDirMer, &newVecDirMer );
//Create the size of the object
D3DXMATRIX matScaleMer;
D3DXMatrixScaling(&matScaleMer, 0.1f, 0.1f, 0.1f);
//Starting position of object
D3DXMatrixTranslation(&matTranslateMer, 0.0f, 0.0f, 3.5983f * 3);
//Rotate about it's own axis
D3DXMatrixRotationY(&worldMatrixMer, rotation);
worldMatrixMer *= rotMatrixMer * matScaleMer * matTranslateMer;
//'Orbit'
D3DXMatrixRotationY( &matOrbit, (-1000.0f * rotation) / 88);
worldMatrixMer *= matOrbit;
我真的想找到一种优雅的方式来实现这一点,所以任何建议都将不胜感激。
谢谢