私は3D空間内を移動する複数のオブジェクトを持っており、ボタンを押したときにカメラをスナップして選択したオブジェクトに従う方法を探しています。DirectXカメラは、3Dモデルの世界のマトリックスに基づいてフォローしますか?
各オブジェクトの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;
私は本当にこれが起こる作るのエレガントな方法を見つけようとしている(以下は、1つのオブジェクトの例である。この1つは&軌道を回る惑星である)ので、任意の提案をいただければ幸いです。
おかげ
私のためにマトリックスを分解してくれてありがとう、これはおそらく私がそれについて行く方法です。 –