TrbDynBody.h

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2009 Sony Computer Entertainment Inc.
00003    All rights reserved.
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 
00015 */
00016 
00017 #ifndef BT_RB_DYN_BODY_H__
00018 #define BT_RB_DYN_BODY_H__
00019 
00020 #include "vectormath/vmInclude.h"
00021 using namespace Vectormath::Aos;
00022 
00023 #include "TrbStateVec.h"
00024 
00025 class CollObject;
00026 
00027 class TrbDynBody
00028 {
00029 public:
00030         TrbDynBody()
00031         {
00032                 fMass   = 0.0f;
00033                 fCollObject = NULL;
00034                 fElasticity = 0.2f;
00035                 fFriction = 0.8f;
00036         }
00037 
00038         // Get methods
00039         float          getMass() const {return fMass;};
00040         float          getElasticity() const {return fElasticity;}
00041         float          getFriction() const {return fFriction;}
00042         CollObject*    getCollObject() const {return fCollObject;}
00043         const Matrix3 &getBodyInertia() const {return fIBody;}
00044         const Matrix3 &getBodyInertiaInv() const {return fIBodyInv;}
00045         float          getMassInv() const {return fMassInv;}
00046 
00047         // Set methods
00048         void           setMass(float mass) {fMass=mass;fMassInv=mass>0.0f?1.0f/mass:0.0f;}
00049         void           setBodyInertia(const Matrix3 bodyInertia) {fIBody = bodyInertia;fIBodyInv = inverse(bodyInertia);}
00050         void           setElasticity(float elasticity) {fElasticity = elasticity;}
00051         void           setFriction(float friction) {fFriction = friction;}
00052         void           setCollObject(CollObject *collObj) {fCollObject = collObj;}
00053         
00054         void           setBodyInertiaInv(const Matrix3 bodyInertiaInv) 
00055         {
00056                 fIBody = inverse(bodyInertiaInv);
00057                 fIBodyInv = bodyInertiaInv;
00058         }
00059         void           setMassInv(float invMass) {
00060                 fMass= invMass>0.0f ? 1.0f/invMass :0.0f;
00061                 fMassInv=invMass;
00062         }
00063 
00064 
00065 private:
00066         // Rigid Body constants
00067         float          fMass;        // Rigid Body mass
00068         float          fMassInv;     // Inverse of mass
00069         Matrix3        fIBody;       // Inertia matrix in body's coords
00070         Matrix3        fIBodyInv;    // Inertia matrix inverse in body's coords
00071         float          fElasticity;  // Coefficient of restitution
00072         float          fFriction;    // Coefficient of friction
00073 
00074 public:
00075         CollObject*    fCollObject;  // Collision object corresponding the RB
00076 } __attribute__ ((aligned(16)));
00077 
00078 #endif //BT_RB_DYN_BODY_H__
00079