testGeneral.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #define CAMERA_STEP 200
  2. #include "helper.h"
  3. TPE_Unit
  4. ramp1[6] = { 5000,0, 5000,5000, 0,0 },
  5. ramp2[6] = { 5000,0, 5000,3000, 0,0 },
  6. ramp3[6] = { 5000,0, 5000,1500, 0,0 },
  7. impale[6] = { 1500,0, 0,6000, -1500,0 };
  8. TPE_Vec3 environmentDistance(TPE_Vec3 p, TPE_Unit maxD)
  9. {
  10. TPE_ENV_START( TPE_envGround(p,0), p)
  11. TPE_ENV_NEXT ( TPE_envAATriPrism(p,TPE_vec3(1000,0,0),ramp1,5000,2), p)
  12. TPE_ENV_NEXT ( TPE_envAATriPrism(p,TPE_vec3(-4000,0,0),ramp2,3500,2), p)
  13. TPE_ENV_NEXT ( TPE_envAATriPrism(p,TPE_vec3(-7500,0,0),ramp3,3500,2), p)
  14. TPE_ENV_NEXT ( TPE_envAATriPrism(p,TPE_vec3(8000,0,-2400),impale,3500,2), p)
  15. TPE_ENV_END
  16. }
  17. uint8_t simulating = 0;
  18. TPE_Body *controlledBody;
  19. int main(void)
  20. {
  21. helper_init();
  22. puts("press P to start");
  23. helper_debugDrawOn = 1;
  24. tpe_world.environmentFunction = environmentDistance;
  25. s3l_scene.camera.transform.translation.z = -3000;
  26. s3l_scene.camera.transform.translation.y = 2000;
  27. s3l_scene.camera.transform.translation.x = 0;
  28. s3l_scene.camera.transform.rotation.y = TPE_FRACTIONS_PER_UNIT / 16;
  29. #define addBody(x,y,z,f) \
  30. helper_addBox(700,700,700,300,500); \
  31. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(x,y,z)); \
  32. helper_lastBody.elasticity = 255; \
  33. helper_lastBody.friction = f;
  34. // cubes on ramps:
  35. addBody(1800,5200,4000,0)
  36. addBody(400,5200,4000,128)
  37. addBody(-1100,5200,4000,511)
  38. addBody(-2800,3600,4000,300)
  39. addBody(-4300,3600,4000,10)
  40. addBody(-6700,2000,4000,300)
  41. addBody(-8400,2000,4000,10)
  42. addBody(7500,6200,-2400,10) // impaled cube
  43. #define addBody(x,y,z,e) \
  44. helper_addRect(700,700,300,500); \
  45. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(x,y,z)); \
  46. helper_lastBody.elasticity = e;
  47. // falling bodies
  48. addBody(7000,5000,0,511)
  49. addBody(8800,5000,0,255)
  50. addBody(10600,5000,0,0)
  51. helper_addBox(5000,5000,5000,2000,2000); // big box
  52. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(-20000,10000,8000));
  53. TPE_bodySpin(&helper_lastBody,TPE_vec3(100,200,-20));
  54. // two colliding spheres:
  55. helper_addBall(800,2000);
  56. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(200,4000,-4800));
  57. helper_lastBody.elasticity = 255;
  58. helper_lastBody.friction = 255;
  59. helper_lastBody.joints[0].velocity[0] = 10;
  60. helper_addBall(800,200);
  61. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(3200,3800,-4800));
  62. helper_lastBody.elasticity = 255;
  63. helper_lastBody.friction = 255;
  64. helper_lastBody.joints[0].velocity[0] = -300;
  65. helper_addBall(1000,1000);
  66. controlledBody = &helper_lastBody;
  67. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(200,2000,-3000));
  68. // two colliding bodies:
  69. helper_addCenterBox(700,700,700,300,500);
  70. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(-4000,5000,-3000));
  71. helper_lastBody.elasticity = 255;
  72. helper_lastBody.friction = 255;
  73. //helper_lastBody.flags |= TPE_BODY_FLAG_SOFT;
  74. TPE_bodyAccelerate(&helper_lastBody,TPE_vec3(-300,0,0));
  75. helper_addCenterBox(700,700,700,300,500);
  76. TPE_bodyMoveBy(&helper_lastBody,TPE_vec3(-8000,5000,-3000));
  77. helper_lastBody.elasticity = 255;
  78. helper_lastBody.friction = 255;
  79. helper_lastBody.flags |= TPE_BODY_FLAG_SOFT;
  80. TPE_bodyAccelerate(&helper_lastBody,TPE_vec3(300,0,0));
  81. while (helper_running)
  82. {
  83. helper_frameStart();
  84. helper_cameraFreeMovement();
  85. if (simulating)
  86. {
  87. TPE_worldStep(&tpe_world);
  88. for (int i = 0; i < 12; ++i)
  89. TPE_bodyApplyGravity(&tpe_world.bodies[i],5);
  90. }
  91. if (helper_debugDrawOn)
  92. helper_debugDraw(1);
  93. if (sdl_keyboard[SDL_SCANCODE_P])
  94. simulating = 1;
  95. TPE_bodyMultiplyNetSpeed(controlledBody,255);
  96. #define ACC 100
  97. if (sdl_keyboard[SDL_SCANCODE_W])
  98. TPE_bodyAccelerate(controlledBody,TPE_vec3(0,0,ACC));
  99. else if (sdl_keyboard[SDL_SCANCODE_S])
  100. TPE_bodyAccelerate(controlledBody,TPE_vec3(0,0,-1 * ACC));
  101. else if (sdl_keyboard[SDL_SCANCODE_D])
  102. TPE_bodyAccelerate(controlledBody,TPE_vec3(ACC,0,0));
  103. else if (sdl_keyboard[SDL_SCANCODE_A])
  104. TPE_bodyAccelerate(controlledBody,TPE_vec3(-1 * ACC,0,0));
  105. else if (sdl_keyboard[SDL_SCANCODE_C])
  106. TPE_bodyAccelerate(controlledBody,TPE_vec3(0,ACC,0));
  107. else if (sdl_keyboard[SDL_SCANCODE_X])
  108. TPE_bodyAccelerate(controlledBody,TPE_vec3(0,-1 * ACC,0));
  109. helper_frameEnd();
  110. }
  111. helper_end();
  112. return 0;
  113. }