testGeneral.c 4.2 KB

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