# Airplane Dynamics in Directx

This topic is 2613 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to make a jet game, and am having a difficult time with making the jet's forward vector change based on the roll. Basically, I can roll the aircraft however I want, but only the yaw will affect the angle at which it pitches. I suspect I need to use my up vector somehow (or possibly my right vector) to help rectify the situation.

I find my vectors with the code (in c++):

 float sinp = (float) sin(fPitch); float cosp = (float) cos(fPitch); float siny = (float) sin(fYaw); float cosy = (float) cos(fYaw); //apply the yaw and pitch to get the forward vector m_d3dForwardVector.x = -siny * cosp; m_d3dForwardVector.y = sinp; m_d3dForwardVector.z = -cosy * cosp; ////apply the yaw and pitch to get the right vector m_d3dRightVector.x = -cosy; m_d3dRightVector.y = -siny * cosp; m_d3dRightVector.z = siny; ////Use the cross product to get the up vector m_d3dUpVector = CrossProduct(m_d3dForwardVector, m_d3dRightVector); 

and change my jet's position based on the forward vector:

 //update plane position m_d3dPosition.x += m_d3dForwardVector.x * m_fSpeed * fDt; m_d3dPosition.y += m_d3dForwardVector.y * m_fSpeed * fDt; m_d3dPosition.z += m_d3dForwardVector.z * m_fSpeed * fDt; 

What do I need to do to account for roll?

##### Share on other sites
Ok, so I found a way to update my Up and Right Vectors properly, but it didn't fix the problem of the airplane not "pitching" correctly, I know I need to add the logic on how to rotate the forward vector towards the up vector of the airplane, but I am at a loss of how to do this.

Here is my updated find vector function:

 void CJet::FindForwardVector(float fYaw, float fPitch, float fRoll) { //apply yaw, pitch and rotation to a rotation matrix D3DXMATRIX matRot; D3DXMatrixRotationYawPitchRoll(&matRot, fYaw, fPitch, fRoll); //apply the yaw and pitch to get the forward vector m_d3dForwardVector.x = -matRot._31; m_d3dForwardVector.y = -matRot._32; m_d3dForwardVector.z = -matRot._33; //apply the yaw and pitch to get the right vector m_d3dRightVector.x = -matRot._11; m_d3dRightVector.y = -matRot._12; m_d3dRightVector.z = -matRot._13; //Use the cross product to get the up vector m_d3dUpVector = CrossProduct(m_d3dForwardVector, m_d3dRightVector); } 

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002292
×