我有多個物體在3D空間中移動,並且正在尋找方法,在按下按鈕時,讓相機捕捉並跟隨所選對象。基於3D模型的世界矩陣的DirectX相機?
有沒有辦法利用每個對象的worldMatrix? (下面是一個對象的例子,這一個是旋轉&軌道的行星)
//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;
我真的試圖找到使這種情況發生的一個優雅的方式,因此任何建議,將不勝感激。
感謝
謝謝你,這可能是我會去的方式。 – 2012-03-29 08:58:19