hello.c 998 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** Completely basic program showing an initialization of a body consisting of
  2. a single joint and dropping it on the floor, then plotting the body vertical
  3. position over time. */
  4. #include "../tinyphysicsengine.h"
  5. #include <stdio.h>
  6. TPE_Vec3 environmentDistance(TPE_Vec3 point, TPE_Unit maxDistance)
  7. {
  8. return TPE_envGround(point,0); // just an infinite flat plane
  9. }
  10. int main(void)
  11. {
  12. TPE_Body body;
  13. TPE_World world;
  14. TPE_Joint joint;
  15. int frame = 0;
  16. joint = TPE_joint(TPE_vec3(0,TPE_F * 8,0),TPE_F);
  17. TPE_bodyInit(&body,&joint,1,0,0,2 * TPE_F);
  18. TPE_worldInit(&world,&body,1,environmentDistance);
  19. while (TPE_bodyIsActive(&body))
  20. {
  21. if (frame % 6 == 0) // print once in 6 frames
  22. {
  23. TPE_Unit height = TPE_bodyGetCenterOfMass(&body).y;
  24. for (int i = 0; i < (height * 4) / TPE_F; ++i)
  25. putchar(' ');
  26. puts("*");
  27. }
  28. TPE_bodyApplyGravity(&body,TPE_F / 100);
  29. TPE_worldStep(&world);
  30. frame++;
  31. }
  32. puts("body deactivated");
  33. return 0;
  34. }