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