Jump to content
  • Advertisement
Sign in to follow this  
Bokiemon

Flight Sim With Quaternions

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to rotate my plane model with quaternions and I somehow manage to do it by accident. My code is as follow
void D3DAdapter::MoveObjectQ(int direction)
{
	
	float fRoll, fYaw, fPitch;
	fRoll = fYaw = fPitch = 0.0f;

	switch(direction)
	{
		case D3DAdapter::ROLL_LEFT:
			fRoll -= m_speed;
		break;

		case D3DAdapter::ROLL_RIGHT:
			fRoll += m_speed;
		break;

		case D3DAdapter::YAW_LEFT:
			fYaw -= m_speed;
		break;

		case D3DAdapter::YAW_RIGHT:
			fYaw += m_speed;
		break;

		case D3DAdapter::PITCH_DOWN:
			fPitch -= m_speed;
		break;

		case D3DAdapter::PITCH_UP:
			fPitch += m_speed;
		break;
	}

	D3DXMATRIX matAdd, matTrans;
	
	D3DXMatrixIdentity(&matTrans);

	D3DXVECTOR3 lookAtVt(0.0f, 0.0f, -1.0f);
	D3DXQUATERNION additionalQ;
	
	D3DXQuaternionRotationYawPitchRoll(&additionalQ, fYaw, fPitch, fRoll);

	aeroplane.rotQuaternion *= additionalQ;
	D3DXMatrixRotationQuaternion(&matAdd, &aeroplane.rotQuaternion);
	D3DXMatrixInverse(&matAdd, NULL, &matAdd);
	D3DXVec3TransformCoord(&lookAtVt, &lookAtVt, &matAdd);
	
	//matLocal = matAdd;
	
	//D3DXVECTOR3 lookVt(matLocal._21, matLocal._22, matLocal._23);
	
	if(direction == D3DAdapter::FORWARD)
	{
		aeroplane.pos.x += m_speed * lookAtVt.x;
		aeroplane.pos.y += m_speed * lookAtVt.y;
		aeroplane.pos.z += m_speed * lookAtVt.z;
	}
	else if(direction == D3DAdapter::BACKWARD)
	{
		aeroplane.pos.x -= m_speed * lookAtVt.x;
		aeroplane.pos.y -= m_speed * lookAtVt.y;
		aeroplane.pos.z -= m_speed * lookAtVt.z;
	}
	
	D3DXMatrixTranslation(&matTrans, aeroplane.pos.x, aeroplane.pos.y, aeroplane.pos.z);

	matAdd *= matTrans;
	matLocal = matAdd;
}

The question I have is when I didn't inverse the rotation matrix generated from using the quaternion, the rotation didn't work. Anyone knows why?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!