我目前正在使用 DirectX 在飞机上进行简单的汽车模拟。我在飞机上定位汽车时遇到问题。
我正在做的是这个……
D3DXMATRIX planeMat //matrix of the plane on which car is currently situated.
...
//calculating car rotation matrix (on XZ plane )
D3DXMATRIX carRot;
D3DXMatrixRotationY( &carRot , yaw );
//car up will same as plane
D3DXVECTOR3 carUp = D3DXVECTOR3( planeMat._12 , planeMat._22 , planeMat._32 );
//car lookat vector
D3DXVECTOR3 carLookat = D3DXVECTOR3( carRot._13 , carRot._23 , carRot._33 );
// calculating right vector
D3DXVec3Cross( &carRight , &carLookAt , &carUp );
D3DXVec3Normalize( &carRight , &carRight );
//calculating new lookat
D3DXVec3Cross( &carLookAt , &carRight , &carUp );
D3DXVec3Normalize( &carLookAt , &carLookAt );
//car matrix
D3DXMATRIX carMat; D3DXMatrixIdentity( &carMat );
carMat._11 = carRight.x ;carMat._21 = carRight.y ;carMat._31 = carRight.z ;
carMat._12 = carUp.x ;carMat._22 = carUp.y ;carMat._32 = carUp.z ;
carMat._13 = carLookAt.x ;carMat._23 = carLookAt.y ;carMat._33 = carLookAt.z ;
carMat._41 = carPos.x ;carMat._42 = carPos.y ;carMat._43 = carPos.z ;
我无法让汽车的旋转正确。
请帮我。