Airplane Dynamics in Directx

Started by
0 comments, last by TylerCarvinSmith 12 years, 11 months ago
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?
Advertisement
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);
}

This topic is closed to new replies.

Advertisement