[solved]freezePos got stuck in trigger
Hi, in my game i want to often use freezePos function, but it stops working after first call in reportTrigger function. I made example code based on '11 -Physics/01 - Physics' tutorial. It also often crash on exit.
Most important(imo ) parts of code.
Code:
Actor ground,
box ,
ball ;
---------
---------
bool Init()
{
---------
---------
Physics.reportTrigger(*TriggerReport);
---------
---------
box .create(Box (0.3 , Vec(0.1, -1, 0)), 0);
ball .create(Ball(0.3 , Vec(2.5, 0, 2.5)), 1);
box.trigger(true);
return true;
}
---------
---------
Flt timer, timer1=0;
void TriggerReport(ActorInfo &trigger, ActorInfo &actor)
{
timer=Time.curTime();
if(timer>=timer1+3) //every 3 secs
{
timer1=timer;
if(ball.freezePosX()) ball.freezePosX(false);
else ball.freezePosX(true); //works only on first triggering
}
}
and full code:
Code:
/******************************************************************************/
Actor ground,
box ,
ball ;
/******************************************************************************/
void InitPre()
{
EE_INIT();
App.flag=APP_MS_EXCLUSIVE;
}
bool Init()
{
Cam.dist=4;
// create physics
Physics.create(EE_PHYSX_DLL_PATH); // create physics by specifying the path to physx dll's
Physics.reportTrigger(*TriggerReport);
// create actors
ground.create(Box (15, 1, 15, Vec(0.0, -2, 0)), 0); // create ground actor from Box and density=0 (which means it's a static actor - will not move)
box .create(Box (0.3 , Vec(0.1, -1, 0)), 0);
ball .create(Ball(0.3 , Vec(2.5, 0, 2.5)), 1);
box.trigger(true);
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
if(Kb.bp(KB_ESC))return false;
CamHandle(0.1, 10, CAMH_ZOOM|CAMH_ROT);
// physics update
{
Physics.startSimulation(); // start frame simulation
// physics simulation takes some time, so you can do some calculations here
// important : you may not modify actors between Physics.startSimulation() and Physics.stopSimulation()
Physics.stopSimulation(); // get results of frame simulation
}
flt s=3;
// add forces to ball
if(Kb.b(KB_UP ))ball.addForce(Vec( 0, 0, 1)*s);
if(Kb.b(KB_DOWN ))ball.addForce(Vec( 0, 0, -1)*s);
if(Kb.b(KB_LEFT ))ball.addForce(Vec(-1, 0, 0)*s);
if(Kb.b(KB_RIGHT))ball.addForce(Vec( 1, 0, 0)*s);
// add forces to ball according to camera
if(Kb.b(KB_W))ball.addForce( !PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s);
if(Kb.b(KB_S))ball.addForce(-!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s);
if(Kb.b(KB_A))ball.addForce(-!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s);
if(Kb.b(KB_D))ball.addForce( !PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s);
// add velocity to ball
if(Kb.bp(KB_SPACE))ball.addVel(Vec(0, 3, 0));
return true;
}
/******************************************************************************/
void Draw()
{
D .clear();
Physics.draw (); // draw physical actors
D.text(0, 0.6, S+"time:"+timer1 );
}
/******************************************************************************/
Flt timer, timer1=0;
void TriggerReport(ActorInfo &trigger, ActorInfo &actor)
{
timer=Time.curTime();
if(timer>=timer1+3)
{
timer1=timer;
if(ball.freezePosX()) ball.freezePosX(false);
else ball.freezePosX(true);
}
}
Anyone can help with that?
and btw: can i make Actor from ActorInfo?
(This post was last modified: 08-07-2013 12:44 PM by dziablo.)
|