Game Development Reference
In-Depth Information
3.
If the main tank body is visible, it calculates and sets the turret's final
position, based on the position of the main tank body and the turret offset.
4.
Updates the tank's weapons and the active ammunition that has been fired
from those weapons.
Listing 8-62. Updating the Tank
void UpdateVehicle()
{
if (m_MainBody.IsVisible())
{
// Update AIPilot
m_Driver.Update();
// Update Right/Left and Up/Down Rotation of Vehicle based on AIPilot's Steering
ProcessSteering();
// Process Turret Steering
ProcessTurret();
}
// Update Vehicle Physics, Position, Rotation, and attached emitters and explosions
m_Heading = m_MainBody.m_Orientation.GetForwardWorldCoords();
m_MainBody.UpdateObject3dToHeading(m_Heading);
if (m_MainBody.IsVisible())
{
// Tie Turret to Main Body
Vector3 Pos = m_MainBody.m_Orientation.GetPosition();
Vector3 ZOffset = Vector3.Multiply(m_TurretOffset.z,
m_MainBody.m_Orientation.GetForwardWorldCoords());
Vector3 XOffset = Vector3.Multiply(m_TurretOffset.x,
m_MainBody.m_Orientation.GetRightWorldCoords());
Vector3 YOffset = Vector3.Multiply(m_TurretOffset.y,
m_MainBody.m_Orientation.GetUpWorldCoords());
Vector3 OffsetPos = new Vector3(Pos);
OffsetPos.Add(XOffset);
OffsetPos.Add(YOffset);
OffsetPos.Add(ZOffset);
m_Turret.m_Orientation.GetPosition().Set(OffsetPos.x, OffsetPos.y,OffsetPos.z);
}
// Update Weapons and Ammunition
for (int i = 0 ; i < m_NumberWeapons; i++)
{
m_Weapons[i].UpdateWeapon();
}
}
 
Search WWH ::




Custom Search