envaccel.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /** Boring demo, shows how to accelerate environment functions with bounding
  2. volume checks. */
  3. #include "helper.h"
  4. #define ACCELERATE 1 // if you turn this off, FPS will drastically drop
  5. TPE_Vec3 environmentDistance(TPE_Vec3 p, TPE_Unit maxD)
  6. {
  7. /* this is our highly complex environment function that find the closest point
  8. against a grid of shape chunks -- with acceleration we apply bounding
  9. volume checks to the big chunks and each smaller subchunk */
  10. TPE_ENV_START( TPE_envAABoxInside(p,TPE_vec3(0,0,0),TPE_vec3(30000,30000,30000)), p )
  11. for (int bigZ = -1; bigZ < 1; ++bigZ) // big chunks
  12. for (int bigY = -1; bigY < 1; ++bigY)
  13. for (int bigX = -1; bigX < 1; ++bigX)
  14. {
  15. TPE_Vec3 bigCenter =
  16. TPE_vec3(bigX * 20 * TPE_F,bigY * 20 * TPE_F,bigZ * 20 * TPE_F);
  17. #if ACCELERATE
  18. // bouding volume check for the big chunks of environment
  19. if (TPE_ENV_BCUBE_TEST(p,maxD,bigCenter,20 * TPE_F))
  20. #endif
  21. for (int smallZ = 0; smallZ < 2; ++smallZ) // smaller chunks
  22. for (int smallY = 0; smallY < 2; ++smallY)
  23. for (int smallX = 0; smallX < 2; ++smallX)
  24. {
  25. TPE_Vec3 smallCenter = TPE_vec3Plus(bigCenter,
  26. TPE_vec3(smallX * 8 * TPE_F,smallY * 8 * TPE_F,smallZ * 8 * TPE_F));
  27. #if ACCELERATE
  28. // bouding volume check for the smaller subchanks of environment
  29. if (TPE_ENV_BSPHERE_TEST(p,maxD,smallCenter,8 * TPE_F))
  30. #endif
  31. {
  32. TPE_ENV_NEXT( TPE_envBox(p,smallCenter,TPE_vec3(2 * TPE_F,4 * TPE_F / 3,4 * TPE_F / 3),
  33. TPE_vec3(TPE_F / 100,TPE_F / 20,TPE_F / 15)), p );
  34. TPE_ENV_NEXT( TPE_envCylinder(p,smallCenter,TPE_vec3(TPE_F * 4,TPE_F * 3,3 * TPE_F / 4),3 * TPE_F / 4), p);
  35. TPE_ENV_NEXT( TPE_envSphere(p,TPE_vec3Minus(smallCenter,TPE_vec3(-3 * TPE_F / 4,TPE_F,0)), 2 * TPE_F ) , p );
  36. }
  37. }
  38. }
  39. TPE_ENV_END
  40. }
  41. int main(void)
  42. {
  43. helper_init();
  44. helper_debugDrawOn = 1;
  45. tpe_world.environmentFunction = environmentDistance;
  46. s3l_scene.camera.transform.translation.z -= TPE_F * 4;
  47. while (helper_running)
  48. {
  49. helper_frameStart();
  50. helper_cameraFreeMovement();
  51. TPE_worldStep(&tpe_world);
  52. if (helper_frame % 32 == 0)
  53. helper_printCPU();
  54. if (helper_debugDrawOn)
  55. helper_debugDraw(1);
  56. helper_frameEnd();
  57. }
  58. helper_end();
  59. return 0;
  60. }