Code:
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/
using namespace GAME; // use game namespace
FLT ang ; // car wheel angle
ACTR car , // car actor
ground; // ground actor
WHEEL whl[4]; // wheels
/******************************************************************************/
VOID InitPre()
{
App.name="GameWIP";
//App.flg =APP_DISP;
IOPath="../data/";
PakAdd("../data/engine.pak",NULL);
D.full(true).sync(true).shdSize(1024);
}
BOOL Init()
{
//Cam.dist=10;
Phys.crt(-1,60); // limit physics calculations to 60 frames per second, above that PhysX seems to have problems with wheels
//ground.crt(BOX_U(100,1,100),0);ground.pos(ground.pos()-VEC(0,3,0));
// create car
car.crt (BOX(2,1,4)); // create actor
car.mass(FLT(100.0));
car.massCntr(car.massCntr()-VEC(0,1.0,0)); // lower mass center
// create car wheels
WHEEL_PAR wp; // wheel parameters
whl[0].crt(car,VEC( 1,-0.5, 1.5),wp);
whl[1].crt(car,VEC(-1,-0.5, 1.5),wp);
whl[2].crt(car,VEC( 1,-0.5,-1.5),wp);
whl[3].crt(car,VEC(-1,-0.5,-1.5),wp);
car.pos(car.pos()+VEC(15,3,15));
Wrld.crt("wrld/sample","temp" ); // please note that here an additional "set" is called, this is used for enabling built-in character<->item relations such as picking up and dropping items
Cam.setSphr(VEC(16,0,16),-PI_4,-0.5,0,10).set(); // set initial camera
return true;
}
/******************************************************************************/
VOID Shut()
{
}
/******************************************************************************/
BOOL Main()
{
if(Kb.bp(KB_ESC))return false;
//CamHandle(0.1f,200,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
Phys.sim();
Phys.get();
if(Kb.bp(KB_ENTER))car.pos(VEC(0,3,0)); // reset car position on ENTER key
// adjust car controls
{
ang=LerpTime(ang,(Kb.b(KB_D)-Kb.b(KB_A))*PI_4,0.01); // adjust wheel angle
FLT acc=(Kb.b(KB_W)-Kb.b(KB_S))*1600, // acceleration
brk= Kb.b(KB_SPC) *3200; // brakes
whl[0].ang(ang); // set angle
whl[1].ang(ang); // set angle
whl[2].acc(acc).brk(brk); // set acceleration and brakes
whl[3].acc(acc).brk(brk); // set acceleration and brakes
}
// update wheels
REPAO(whl).upd();
Wrld.upd(Cam.at); // update world to given position
return true;
}
VOID Rndr()
{
Wrld.draw();
switch(R())
{
case RNDR_LGT:
LGT_DIR(1,!VEC(1,-1,1)).add();
break;
}
}
VOID Draw()
{
R(Rndr);
//D.clr();
Phys.draw();
(car.massCntr()*car.mtrx()).draw(RED); // draw mass center
}
/******************************************************************************
/