stack.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "helper.h"
  2. TPE_Vec3 environmentDistance(TPE_Vec3 p, TPE_Unit maxD)
  3. {
  4. TPE_ENV_START( TPE_envHalfPlane(p,TPE_vec3(0,0,0),TPE_vec3(256,256,0)),p )
  5. TPE_ENV_NEXT( TPE_envHalfPlane(p,TPE_vec3(0,0,0),TPE_vec3(-256,256,-256)),p )
  6. TPE_ENV_NEXT( TPE_envHalfPlane(p,TPE_vec3(0,0,0),TPE_vec3(-256,256,256)),p )
  7. TPE_ENV_END
  8. }
  9. uint8_t debugDrawOn = 1;
  10. unsigned long timeMeasure = 0;
  11. int main(void)
  12. {
  13. helper_init();
  14. tpe_world.environmentFunction = environmentDistance;
  15. s3l_scene.camera.transform.translation.y = 3000;
  16. s3l_scene.camera.transform.translation.z = -1000;
  17. for (int i = 0; i < 16; ++i)
  18. {
  19. switch (i % 5)
  20. {
  21. case 0: helper_addBox(800,800,800,400,700); break;
  22. case 1: helper_addTriangle(1100,200,600); break;
  23. case 2: helper_addBall(500,700); break;
  24. case 3: helper_addRect(800,800,400,800); break;
  25. case 4: helper_add2Line(900,200,600); break;
  26. default: break;
  27. }
  28. TPE_bodyMove(&tpe_world.bodies[tpe_world.bodyCount - 1],TPE_vec3((1 - (i % 4)) * 1200,8000,(2 - (i / 4)) * 1200));
  29. //if (i % 2)
  30. //tpe_world.bodies[tpe_world.bodyCount - 1].flags |= TPE_BODY_FLAG_NONROTATING;
  31. }
  32. while (helper_running)
  33. {
  34. helper_frameStart();
  35. helper_cameraFreeMovement();
  36. if (helper_frame % 16 == 0)
  37. {
  38. //helper_printCPU();
  39. //helper_printCamera();
  40. if (sdl_keyboard[SDL_SCANCODE_L])
  41. for (int i = 0; i < tpe_world.bodyCount; ++i)
  42. {
  43. TPE_bodyActivate(&tpe_world.bodies[i]);
  44. TPE_bodyAccelerate(&tpe_world.bodies[i],TPE_vec3(0,500,0));
  45. }
  46. printf("world update (us): %lu\n",timeMeasure / 16);
  47. timeMeasure = 0;
  48. }
  49. unsigned long t1 = helper_getMicroSecs();
  50. TPE_worldStep(&tpe_world);
  51. timeMeasure += helper_getMicroSecs() - t1;
  52. helper_set3dColor(180,10,10);
  53. for (int i = 0; i < tpe_world.bodyCount; ++i)
  54. {
  55. TPE_bodyApplyGravity(&tpe_world.bodies[i],5);
  56. TPE_Joint *joints = tpe_world.bodies[i].joints;
  57. TPE_Vec3 pos = TPE_bodyGetCenterOfMass(&tpe_world.bodies[i]);
  58. TPE_Vec3 right = TPE_vec3(512,0,0);
  59. TPE_Vec3 forw = TPE_vec3(0,0,512);
  60. if (i % 5 != 2 && i % 5 != 1)
  61. {
  62. if (i % 5 != 4)
  63. {
  64. forw = TPE_vec3Minus(joints[2].position,joints[0].position);
  65. right = TPE_vec3Minus(joints[1].position,joints[0].position);
  66. }
  67. else
  68. forw = TPE_vec3Minus(joints[1].position,joints[0].position);
  69. }
  70. TPE_Vec3 orient = TPE_rotationFromVecs(forw,right);
  71. switch (i % 5)
  72. {
  73. case 0: helper_draw3dBox(pos,TPE_vec3(1200,1200,1200),orient); break;
  74. case 1: helper_draw3dTriangle(joints[0].position,joints[1].position,joints[2].position); break;
  75. case 2: helper_draw3dSphere(pos,TPE_vec3(500,500,500),orient); break;
  76. case 3: helper_draw3dBox(pos,TPE_vec3(1200,400,1200),orient); break;
  77. case 4: helper_draw3dBox(pos,TPE_vec3(200,200,1200),orient); break;
  78. default: break;
  79. }
  80. }
  81. helper_set3dColor(100,100,100);
  82. helper_draw3dTriangle(TPE_vec3(0,0,0),TPE_vec3(-5000,5000,-10000),TPE_vec3(-5000,5000,10000));
  83. helper_set3dColor(140,140,140);
  84. helper_draw3dTriangle(TPE_vec3(0,0,0),TPE_vec3(-5000,5000,10000),TPE_vec3(5000,5000,0));
  85. helper_set3dColor(80,80,80);
  86. helper_draw3dTriangle(TPE_vec3(0,0,0),TPE_vec3(-5000,5000,-10000),TPE_vec3(5000,5000,0));
  87. if (helper_debugDrawOn)
  88. helper_debugDraw();
  89. helper_frameEnd();
  90. }
  91. helper_end();
  92. return 0;
  93. }