You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2006-04-21
  5. // Updated : 2006-12-06
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/inertia.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename T>
  12. GLM_FUNC_QUALIFIER detail::tmat3x3<T> boxInertia3
  13. (
  14. T const & Mass,
  15. detail::tvec3<T> const & Scale
  16. )
  17. {
  18. detail::tmat3x3<T> Result(T(1));
  19. Result[0][0] = (Scale.y * Scale.y + Scale.z * Scale.z) * Mass / T(12);
  20. Result[1][1] = (Scale.x * Scale.x + Scale.z * Scale.z) * Mass / T(12);
  21. Result[2][2] = (Scale.x * Scale.x + Scale.y * Scale.y) * Mass / T(12);
  22. return Result;
  23. }
  24. template <typename T>
  25. GLM_FUNC_QUALIFIER detail::tmat4x4<T> boxInertia4
  26. (
  27. T const & Mass,
  28. detail::tvec3<T> const & Scale
  29. )
  30. {
  31. detail::tmat4x4<T> Result(T(1));
  32. Result[0][0] = (Scale.y * Scale.y + Scale.z * Scale.z) * Mass / T(12);
  33. Result[1][1] = (Scale.x * Scale.x + Scale.z * Scale.z) * Mass / T(12);
  34. Result[2][2] = (Scale.x * Scale.x + Scale.y * Scale.y) * Mass / T(12);
  35. return Result;
  36. }
  37. template <typename T>
  38. GLM_FUNC_QUALIFIER detail::tmat3x3<T> diskInertia3
  39. (
  40. T const & Mass,
  41. T const & Radius
  42. )
  43. {
  44. T a = Mass * Radius * Radius / T(2);
  45. detail::tmat3x3<T> Result(a);
  46. Result[2][2] *= T(2);
  47. return Result;
  48. }
  49. template <typename T>
  50. GLM_FUNC_QUALIFIER detail::tmat4x4<T> diskInertia4
  51. (
  52. T const & Mass,
  53. T const & Radius
  54. )
  55. {
  56. T a = Mass * Radius * Radius / T(2);
  57. detail::tmat4x4<T> Result(a);
  58. Result[2][2] *= T(2);
  59. Result[3][3] = T(1);
  60. return Result;
  61. }
  62. template <typename T>
  63. GLM_FUNC_QUALIFIER detail::tmat3x3<T> ballInertia3
  64. (
  65. T const & Mass,
  66. T const & Radius
  67. )
  68. {
  69. T a = T(2) * Mass * Radius * Radius / T(5);
  70. return detail::tmat3x3<T>(a);
  71. }
  72. template <typename T>
  73. GLM_FUNC_QUALIFIER detail::tmat4x4<T> ballInertia4
  74. (
  75. T const & Mass,
  76. T const & Radius
  77. )
  78. {
  79. T a = T(2) * Mass * Radius * Radius / T(5);
  80. detail::tmat4x4<T> Result(a);
  81. Result[3][3] = T(1);
  82. return Result;
  83. }
  84. template <typename T>
  85. GLM_FUNC_QUALIFIER detail::tmat3x3<T> sphereInertia3
  86. (
  87. T const & Mass,
  88. T const & Radius
  89. )
  90. {
  91. T a = T(2) * Mass * Radius * Radius / T(3);
  92. return detail::tmat3x3<T>(a);
  93. }
  94. template <typename T>
  95. GLM_FUNC_QUALIFIER detail::tmat4x4<T> sphereInertia4
  96. (
  97. T const & Mass,
  98. T const & Radius
  99. )
  100. {
  101. T a = T(2) * Mass * Radius * Radius / T(3);
  102. detail::tmat4x4<T> Result(a);
  103. Result[3][3] = T(1);
  104. return Result;
  105. }
  106. }//namespace glm