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;
};
Vehicle following terrain
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.
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...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement