1
0

TrbDynBody.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright (C) 2009 Sony Computer Entertainment Inc.
  3. All rights reserved.
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_RB_DYN_BODY_H__
  14. #define BT_RB_DYN_BODY_H__
  15. #include "bullet/vectormath/vmInclude.h"
  16. using namespace Vectormath::Aos;
  17. #include "TrbStateVec.h"
  18. class CollObject;
  19. class TrbDynBody
  20. {
  21. public:
  22. TrbDynBody()
  23. {
  24. fMass = 0.0f;
  25. fCollObject = NULL;
  26. fElasticity = 0.2f;
  27. fFriction = 0.8f;
  28. }
  29. // Get methods
  30. float getMass() const {return fMass;};
  31. float getElasticity() const {return fElasticity;}
  32. float getFriction() const {return fFriction;}
  33. CollObject* getCollObject() const {return fCollObject;}
  34. const Matrix3 &getBodyInertia() const {return fIBody;}
  35. const Matrix3 &getBodyInertiaInv() const {return fIBodyInv;}
  36. float getMassInv() const {return fMassInv;}
  37. // Set methods
  38. void setMass(float mass) {fMass=mass;fMassInv=mass>0.0f?1.0f/mass:0.0f;}
  39. void setBodyInertia(const Matrix3 bodyInertia) {fIBody = bodyInertia;fIBodyInv = inverse(bodyInertia);}
  40. void setElasticity(float elasticity) {fElasticity = elasticity;}
  41. void setFriction(float friction) {fFriction = friction;}
  42. void setCollObject(CollObject *collObj) {fCollObject = collObj;}
  43. void setBodyInertiaInv(const Matrix3 bodyInertiaInv)
  44. {
  45. fIBody = inverse(bodyInertiaInv);
  46. fIBodyInv = bodyInertiaInv;
  47. }
  48. void setMassInv(float invMass) {
  49. fMass= invMass>0.0f ? 1.0f/invMass :0.0f;
  50. fMassInv=invMass;
  51. }
  52. private:
  53. // Rigid Body constants
  54. float fMass; // Rigid Body mass
  55. float fMassInv; // Inverse of mass
  56. Matrix3 fIBody; // Inertia matrix in body's coords
  57. Matrix3 fIBodyInv; // Inertia matrix inverse in body's coords
  58. float fElasticity; // Coefficient of restitution
  59. float fFriction; // Coefficient of friction
  60. public:
  61. CollObject* fCollObject; // Collision object corresponding the RB
  62. } __attribute__ ((aligned(16)));
  63. #endif //BT_RB_DYN_BODY_H__