inertia.c 517 B

12345678910111213141516171819202122232425262728293031
  1. #include "inertia.h"
  2. void inertiaSphere(Matrix3* mat, float mass, float radius) {
  3. float s = (2.0 / 5.0) * mass * radius * radius;
  4. *mat = (Matrix3){0};
  5. mat->m[0] = s;
  6. mat->m[4] = s;
  7. mat->m[8] = s;
  8. }
  9. // axis aligned box
  10. void inertiaBox(Matrix3* mat, float mass, vec3 dims) {
  11. float otm = mass / 12.f;
  12. float x2 = dims.x * dims.x;
  13. float y2 = dims.y * dims.y;
  14. float z2 = dims.z * dims.z;
  15. *mat = (Matrix3){0};
  16. mat->m[0] = otm * (y2 + z2);
  17. mat->m[4] = otm * (x2 + z2);
  18. mat->m[8] = otm * (y2 + x2);
  19. }