2d.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #define TPE_RESHAPE_ITERATIONS 5
  2. #define DEBUG_DRAW_DIVIDE 8
  3. #include "helper.h"
  4. #define ROOM_W 5100
  5. #define ROOM_H ((RES_Y * ROOM_W) / RES_X)
  6. #define SQUARE_SIZE 500
  7. TPE_Vec3 environmentDistance(TPE_Vec3 p, TPE_Unit maxD)
  8. {
  9. return TPE_envAABoxInside(p,TPE_vec3(0,0,0),TPE_vec3(ROOM_W,ROOM_H,ROOM_W));
  10. }
  11. int main(void)
  12. {
  13. helper_init();
  14. helper_debugDrawOn = 1;
  15. tpe_world.environmentFunction = environmentDistance;
  16. s3l_scene.camera.transform.translation.z -= ROOM_W / 2;
  17. s3l_scene.camera.focalLength = 0; // set orthographic projection
  18. for (int i = 0; i < 4; ++i)
  19. {
  20. if (i != 2)
  21. {
  22. helper_addCenterRectFull(SQUARE_SIZE,SQUARE_SIZE,100,100);
  23. TPE_bodyRotateByAxis(&tpe_world.bodies[i],TPE_vec3(TPE_FRACTIONS_PER_UNIT / 4,0,0));
  24. tpe_world.bodies[i].joints[4].sizeDivided = 300 / TPE_JOINT_SIZE_MULTIPLIER;
  25. }
  26. else
  27. helper_addBall(600,100);
  28. tpe_world.bodies[i].friction = 400;
  29. TPE_bodyMove(&tpe_world.bodies[i],TPE_vec3(-1000 + i * 800,ROOM_H / 4,0));
  30. }
  31. while (helper_running)
  32. {
  33. helper_frameStart();
  34. if (sdl_keyboard[SDL_SCANCODE_LEFT])
  35. TPE_bodyAccelerate(&tpe_world.bodies[0],TPE_vec3(-10,0,0));
  36. else if (sdl_keyboard[SDL_SCANCODE_RIGHT])
  37. TPE_bodyAccelerate(&tpe_world.bodies[0],TPE_vec3(10,0,0));
  38. if (sdl_keyboard[SDL_SCANCODE_UP])
  39. TPE_bodyAccelerate(&tpe_world.bodies[0],TPE_vec3(0,10,0));
  40. TPE_worldStep(&tpe_world);
  41. helper_set3dColor(100,100,100);
  42. helper_set3dColor(200,10,10);
  43. for (int i = 0; i < tpe_world.bodyCount; ++i)
  44. TPE_bodyApplyGravity(&tpe_world.bodies[i],5);
  45. for (int i = 0; i < tpe_world.bodyCount; ++i)
  46. {
  47. for (int j = 0; j < tpe_world.bodies[i].jointCount; ++j)
  48. {
  49. tpe_world.bodies[i].joints[j].position.z = 0;
  50. tpe_world.bodies[i].joints[j].velocity[2] = 0;
  51. }
  52. }
  53. // if (helper_debugDrawOn)
  54. helper_debugDraw(0);
  55. helper_frameEnd();
  56. }
  57. helper_end();
  58. return 0;
  59. }