2d.c 1.6 KB

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