rigid.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _RIGID_H_
  23. #define _RIGID_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _MPOINT3_H_
  28. #include "math/mPoint3.h"
  29. #endif
  30. #ifndef _MMATRIX_H_
  31. #include "math/mMatrix.h"
  32. #endif
  33. #ifndef _MQUAT_H_
  34. #include "math/mQuat.h"
  35. #endif
  36. //----------------------------------------------------------------------------
  37. class Rigid
  38. {
  39. public:
  40. MatrixF objectInertia; ///< Moment of inertia
  41. MatrixF invObjectInertia; ///< Inverse moment of inertia
  42. MatrixF invWorldInertia; ///< Inverse moment of inertia in world space
  43. Point3F force;
  44. Point3F torque;
  45. Point3F linVelocity; ///< Linear velocity
  46. Point3F linPosition; ///< Current position
  47. Point3F linMomentum; ///< Linear momentum
  48. Point3F angVelocity; ///< Angular velocity
  49. QuatF angPosition; ///< Current rotation
  50. Point3F angMomentum; ///< Angular momentum
  51. Point3F centerOfMass; ///< Center of mass in object space
  52. Point3F worldCenterOfMass; ///< CofM in world space
  53. F32 mass; ///< Rigid body mass
  54. F32 oneOverMass; ///< 1 / mass
  55. F32 restitution; ///< Collision restitution
  56. F32 friction; ///< Friction coefficient
  57. bool atRest;
  58. private:
  59. void translateCenterOfMass(const Point3F &oldPos,const Point3F &newPos);
  60. public:
  61. //
  62. Rigid();
  63. void clearForces();
  64. void integrate(F32 delta);
  65. void updateInertialTensor();
  66. void updateVelocity();
  67. void updateCenterOfMass();
  68. void applyImpulse(const Point3F &v,const Point3F &impulse);
  69. bool resolveCollision(const Point3F& p,const Point3F &normal,Rigid*);
  70. bool resolveCollision(const Point3F& p,const Point3F &normal);
  71. F32 getZeroImpulse(const Point3F& r,const Point3F& normal);
  72. F32 getKineticEnergy();
  73. void getOriginVector(const Point3F &r,Point3F* v);
  74. void setCenterOfMass(const Point3F &v);
  75. void getVelocity(const Point3F &p,Point3F* r);
  76. void getTransform(MatrixF* mat);
  77. void setTransform(const MatrixF& mat);
  78. void setObjectInertia(const Point3F& r);
  79. void setObjectInertia();
  80. void invertObjectInertia();
  81. bool checkRestCondition();
  82. void setAtRest();
  83. };
  84. #endif