True Axis Physics SDK 1.2.0.1 Beta Documentation
www.trueaxis.com

CarTemplateExample.cpp

Example of how to create a new car template.

//---------------------------------------------------------------------------------
// Car Template Example
//---------------------------------------------------------------------------------

TA::CarTemplate* pCarTemplate = TA::CarTemplate::CreateNew();

// We need to call BeginInitialise before we start setting the car templates properties.
pCarTemplate->BeginInitialise();

// Add an collision object ot the car template.
TA::CollisionObjectConvex* pCollisionObjectConvex = TA::CollisionObjectConvex::CreateNew();
pCollisionObjectConvex->InitialiseAsABox(TA::AABB(Vec3(0.0f, 0.0f, 0.0f), TA::Vec3(1.2f, 0.6f, 2.0f))); 
pCarTemplate->AddCollisionObject(pCollisionObjectConvex);
pCollisionObjectConvex->Release();

// Add wheels to the car template.
const float k_fWheelRadius = 0.3f;
const float k_fWheelWidth = 1.1f;
const float k_fWheelTop = 0.0f;
const float k_fWheelBottom = -1.0f;
const float k_fWheelFront = 1.5f;
const float k_fWheelBack = -1.5f;
CarTemplate::Wheel wheel;

// Front wheels
wheel.SetSuspensionTop(Vec3(k_fWheelWidth, k_fWheelTop, k_fWheelFront));
wheel.SetSuspensionBottom(Vec3(k_fWheelWidth, k_fWheelBottom, k_fWheelFront));
wheel.SetRadius(k_fWheelRadius);
wheel.SetSteeringFlag(true);
wheel.SetDrivingFlag(false);
wheel.SetHandBrakeFlag(false);
// Set the slip curves for the wheel. 
// These are actually the same as the default values so the following 2 lines are unnecessary.
wheel.SetSlipAngleToLateralForceCallBack(SlipAngleToLateralForce);
wheel.SetSlipRatioToNormalisedTractionCallBack(SlipRatioToNormalisedTraction);
pCarTemplate->AddWheel(wheel);

wheel.SetSuspensionTop(Vec3(-k_fWheelWidth, k_fWheelTop, k_fWheelFront));
wheel.SetSuspensionBottom(Vec3(-k_fWheelWidth, k_fWheelBottom, k_fWheelFront));
wheel.SetRadius(k_fWheelRadius);
wheel.SetSteeringFlag(true);
wheel.SetDrivingFlag(false);
wheel.SetHandBrakeFlag(false);
pCarTemplate->AddWheel(wheel);

// Rear wheels
wheel.SetSuspensionTop(Vec3(k_fWheelWidth, k_fWheelTop, k_fWheelBack));
wheel.SetSuspensionBottom(Vec3(k_fWheelWidth, k_fWheelBottom, k_fWheelBack));
wheel.SetRadius(k_fWheelRadius);
wheel.SetSteeringFlag(false);
wheel.SetDrivingFlag(true);
wheel.SetHandBrakeFlag(true);
pCarTemplate->AddWheel(wheel);

wheel.SetSuspensionTop(Vec3(-k_fWheelWidth, k_fWheelTop, k_fWheelBack));
wheel.SetSuspensionBottom(Vec3(-k_fWheelWidth, k_fWheelBottom, k_fWheelBack));
wheel.SetRadius(k_fWheelRadius);
wheel.SetSteeringFlag(false);
wheel.SetDrivingFlag(true);
wheel.SetHandBrakeFlag(true);
pCarTemplate->AddWheel(wheel);

// Other properties.
pCarTemplate->SetMass(1500.0f);
pCarTemplate->SetTorqueMultiplier(5.0f);
pCarTemplate->SetDownForce(4.0f);

// We need to call EndInitialise when we have finished setting the car template properties.
pCarTemplate->EndInitialise();


© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.