30nfynuojjb4invho60ts6vs.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /******************************************************************************/
  2. Actor ground,
  3. ball,
  4. box;
  5. PhysMtrl bouncy;
  6. bool triggered;
  7. /******************************************************************************/
  8. void ReportTrigger(ActorInfo &trigger, ActorInfo &actor, PHYS_CONTACT contact)
  9. {
  10. triggered=true;
  11. }
  12. /******************************************************************************/
  13. void InitPre()
  14. {
  15. EE_INIT();
  16. Ms.hide();
  17. Ms.clip(null, 1);
  18. }
  19. bool Init()
  20. {
  21. Cam.dist=4;
  22. Physics.create(EE_PHYSX_DLL_PATH);
  23. bouncy.create().bounciness(1).bouncinessMode(PhysMtrl.MODE_MAX).damping(0);
  24. ground.create(Box(15, 1, 15, Vec(0, -3, 0)), 0);
  25. ball.create(Ball(0.5, Vec(0, 2, 0))).material(&bouncy); // adjust material to bouncy
  26. box.create(Box(0.5, Vec(0, 0, 0))).trigger(true).gravity(false); // set box as trigger
  27. Physics.reportTrigger(ReportTrigger); // set callback function
  28. return true;
  29. }
  30. /******************************************************************************/
  31. void Shut()
  32. {
  33. }
  34. /******************************************************************************/
  35. bool Update()
  36. {
  37. if(Kb.bp(KB_ESC))return false;
  38. Cam.transformByMouse(0.1, 10, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // move camera on right mouse button
  39. triggered=false; // set no trigger before the simulation
  40. Physics.startSimulation().stopSimulation();
  41. return true;
  42. }
  43. /******************************************************************************/
  44. void Draw()
  45. {
  46. D .clear();
  47. Physics.draw ();
  48. if(triggered)D.text(0, 0.9, "triggered");
  49. }
  50. /******************************************************************************/