Sign in to follow this  
TylerCarvinSmith

Airplane Dynamics in Directx

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++):

[code]


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);

[/code]

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

[code]

//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;

[/code]

What do I need to do to account for roll?

Share this post


Link to post
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:

[code]

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);
}
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this