Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Cybird

Vehicle following terrain

This topic is 5542 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

I''ve implemented one of the techniques discuted in previous threads. But I dont know what is my problem right now, the vehicle do not follow the ground correctly. this is my Tank update method.
  
D3DXMATRIX CTank::Update(float fDeltaTime)
{
	//adjusting height of the tank with the heightmap

	m_vctPosition.y = m_pContourTerrain->GetHeight(m_vctPosition.x, m_vctPosition.z) + 40;
			
	fMinX += m_vctPosition.x;
	fMinY += m_vctPosition.y;
	fMinZ += m_vctPosition.z;

	fMaxX += m_vctPosition.x;
	fMaxY += m_vctPosition.y;
	fMaxZ += m_vctPosition.z;


	D3DXVECTOR3 roue1 = D3DXVECTOR3(fMinX, 0, fMaxZ);
	D3DXVECTOR3 roue2 = D3DXVECTOR3(fMaxX, 0, fMaxZ);
	D3DXVECTOR3 roue3 = D3DXVECTOR3(fMinX, 0, fMinZ);
	D3DXVECTOR3 roue4 = D3DXVECTOR3(fMaxX, 0, fMinZ);

	//Rotating the 4 points according to orientation of the tank

	if ( m_fYaw != 0.0f)
	{
		D3DXMATRIX matY;

		D3DXMatrixIdentity(&matY);
		D3DXMatrixRotationY(&matY,m_fYaw);		

		D3DXVec3TransformCoord(&roue1, &roue1, &matY);
		D3DXVec3TransformCoord(&roue2, &roue2, &matY);
		D3DXVec3TransformCoord(&roue3, &roue3, &matY);
		D3DXVec3TransformCoord(&roue4, &roue4, &matY);		
	}
    	

	//Adjusting height of each of the wheeks

	roue1.y = m_pContourTerrain->GetHeight(roue1.x, roue1.z);
	roue2.y = m_pContourTerrain->GetHeight(roue2.x, roue2.z);
	roue3.y = m_pContourTerrain->GetHeight(roue3.x, roue3.z);
	roue4.y = m_pContourTerrain->GetHeight(roue4.x, roue4.z);
	
		
	fMinX -= m_vctPosition.x;
	fMinY -= m_vctPosition.y;
	fMinZ -= m_vctPosition.z;

	fMaxX -= m_vctPosition.x;
	fMaxY -= m_vctPosition.y;
	fMaxZ -= m_vctPosition.z;

	//Extracting Dir and Right vectors

	D3DXVECTOR3 vDir = roue1 - roue3;
	D3DXVECTOR3 vRight = roue4 - roue3;

	D3DXVec3Normalize(&vDir, &vDir);
	D3DXVec3Normalize(&vRight, &vRight);

	D3DXVECTOR3 vUp;
	D3DXVec3Cross(&vUp, &vDir, &vRight);
	D3DXVec3Normalize(&vUp, &vUp);
	
	D3DXMatrixIdentity(&m_matTransformations);

	m_matTransformations._11 = vRight.x;
	m_matTransformations._12 = vRight.y;
	m_matTransformations._13 = vRight.z;
	m_matTransformations._14 = 0;

	m_matTransformations._21 = vUp.x;
	m_matTransformations._22 = vUp.y;
	m_matTransformations._23 = vUp.z;
	m_matTransformations._24 = 0;

	m_matTransformations._31 = vDir.x;
	m_matTransformations._32 = vDir.y;
	m_matTransformations._33 = vDir.z;
	m_matTransformations._34 = 0;
	
	m_matTransformations._41 = m_vctPosition.x;
	m_matTransformations._42 = m_vctPosition.y;
	m_matTransformations._43 = m_vctPosition.z;
	m_matTransformations._44 = 1.0f;

	return m_matTransformations;
};
  
The car do follow the ground correctly if i don''t modify my m_fYaw value. but I need to modify it, since I want the tank to freely move around, human controlled...

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!