Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/ogrebullet/Dynamics/OgreBulletDynamicsRigidBody.h @ 2163

Last change on this file since 2163 was 2119, checked in by rgrieder, 16 years ago

Merged physics branch into physics_new branch.

  • Property svn:eol-style set to native
File size: 7.8 KB
Line 
1/***************************************************************************
2
3This source file is part of OGREBULLET
4(Object-oriented Graphics Rendering Engine Bullet Wrapper)
5For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10
6
7Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)
8
9
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GPL General Public License with runtime exception as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details.
19
20You should have received a copy of the GPL General Public License with runtime exception along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24-----------------------------------------------------------------------------
25*/
26
27#ifndef _OGREBULLETDYNAMICS_RigidObject_H
28#define _OGREBULLETDYNAMICS_RigidObject_H
29
30#include "OgreBulletDynamicsPreRequisites.h"
31
32#include "OgreBulletCollisionsObject.h"
33#include "OgreBulletCollisionsWorld.h"
34#include "Utils/OgreBulletConverter.h"
35
36#include "OgreBulletDynamicsWorld.h"
37
38#include "Constraints/OgreBulletDynamicsRaycastVehicle.h"
39
40namespace OgreBulletDynamics
41{
42    // -------------------------------------------------------------------------
43    // basic rigid body class
44    class RigidBody : public OgreBulletCollisions::Object
45    {
46    public:
47            RigidBody(const Ogre::String &name, 
48                                  DynamicsWorld *world,
49                                  const short collisionGroup = 0,
50                                  const short collisionMask = 0);
51
52            virtual ~RigidBody();
53
54        void setShape(Ogre::SceneNode *node, 
55            OgreBulletCollisions::CollisionShape *shape,
56            const float      bodyRestitution,
57            const float      bodyFriction,
58            const float      bodyMass,
59            const Ogre::Vector3 &pos = Ogre::Vector3::ZERO, 
60            const Ogre::Quaternion &quat = Ogre::Quaternion::IDENTITY);
61
62        void setStaticShape(Ogre::SceneNode *node,
63            OgreBulletCollisions::CollisionShape *shape,
64            const float      bodyRestitution,
65            const float      bodyFriction,
66            const Ogre::Vector3 &pos = Ogre::Vector3::ZERO, 
67            const Ogre::Quaternion &quat = Ogre::Quaternion::IDENTITY);
68
69        void setStaticShape(OgreBulletCollisions::CollisionShape *shape,
70            const float      bodyRestitution,
71            const float      bodyFriction,
72            const Ogre::Vector3 &pos = Ogre::Vector3::ZERO, 
73            const Ogre::Quaternion &quat = Ogre::Quaternion::IDENTITY);
74
75
76        void setLinearVelocity(const Ogre::Vector3 &vel);
77        void setLinearVelocity(const Ogre::Real x, const Ogre::Real y, const Ogre::Real z);
78                Ogre::Vector3 getLinearVelocity();
79        void applyImpulse(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position);
80        void applyForce(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position);
81
82
83        inline btRigidBody*         getBulletRigidBody() const;
84        inline btDynamicsWorld*     getBulletDynamicsWorld() const;
85        inline DynamicsWorld*       getDynamicsWorld();
86
87        Ogre::SceneNode*  getSceneNode() const {return mRootNode;};
88
89        inline bool isStaticObject() const;
90        inline bool isKinematicObject() const;
91
92                void setKinematicObject(bool isKinematic);
93
94        inline void disableDeactivation();
95        inline void enableActiveState ();
96        inline void forceActivationState();
97        void setDeactivationTime(const float ftime);
98
99        inline const btTransform &getCenterOfMassTransform() const;
100        inline Ogre::Quaternion    getCenterOfMassOrientation () const;
101        inline Ogre::Vector3 getCenterOfMassPosition() const;
102
103        Ogre::Vector3       getCenterOfMassPivot (const Ogre::Vector3 &pivotPosition) const;
104       
105        void setDamping( const Ogre::Real linearDamping, const Ogre::Real angularDamping );
106        protected:
107                short mCollisionGroup;
108                short mCollisionMask;
109    };
110    // -------------------------------------------------------------------------
111    // basic rigid body class
112    class WheeledRigidBody : public RigidBody
113    {
114    public:
115        WheeledRigidBody(const Ogre::String &name, DynamicsWorld *world): 
116            RigidBody(name, world),
117                mVehicle(0)
118        {
119        };
120
121       
122        void setVehicle(RaycastVehicle *v){mVehicle = v;};
123
124       virtual void setPosition(const btVector3 &pos);
125       virtual void setOrientation(const btQuaternion &quat);
126       virtual void setTransform(const btVector3 &pos, const btQuaternion &quat);
127       virtual void setTransform(const btTransform& worldTrans);
128
129        virtual ~WheeledRigidBody(){};
130
131    protected:
132                RaycastVehicle *mVehicle;
133
134    };
135    // -------------------------------------------------------------------------
136    // basic rigid body class inline methods
137    // -------------------------------------------------------------------------
138    inline btRigidBody*  RigidBody::getBulletRigidBody() const 
139    {
140        return static_cast <btRigidBody* > (mObject);
141    };
142    // -------------------------------------------------------------------------
143    inline btDynamicsWorld*     RigidBody::getBulletDynamicsWorld() const 
144    { 
145        return static_cast <btDynamicsWorld * > (mWorld->getBulletCollisionWorld ());
146    };
147    // -------------------------------------------------------------------------
148    inline DynamicsWorld*       RigidBody::getDynamicsWorld() 
149    { 
150        return static_cast <DynamicsWorld* > (mWorld);
151    };
152    // -------------------------------------------------------------------------
153    inline bool RigidBody::isStaticObject() const 
154    {
155        return getBulletRigidBody()->isStaticObject();
156    }
157    // -------------------------------------------------------------------------
158    inline bool RigidBody::isKinematicObject() const 
159    {
160        return getBulletRigidBody()->isKinematicObject();
161    };
162    // -------------------------------------------------------------------------
163    inline void RigidBody::disableDeactivation()
164    {
165        getBulletRigidBody()->setActivationState(DISABLE_DEACTIVATION);
166    }
167    // -------------------------------------------------------------------------
168    inline void RigidBody::enableActiveState()
169    {
170        getBulletRigidBody()->setActivationState(ACTIVE_TAG);
171    }
172    // -------------------------------------------------------------------------
173    inline void RigidBody::forceActivationState()
174    {
175        getBulletRigidBody()->forceActivationState(ACTIVE_TAG);
176    }
177    // -------------------------------------------------------------------------
178    // -------------------------------------------------------------------------
179    inline const btTransform &RigidBody::getCenterOfMassTransform() const
180    {
181        return getBulletRigidBody()->getCenterOfMassTransform();
182    }
183    // -------------------------------------------------------------------------
184    inline Ogre::Quaternion RigidBody::getCenterOfMassOrientation() const
185    {
186        return OgreBulletCollisions::BtOgreConverter::to(getCenterOfMassTransform().getRotation ());
187    }
188    // -------------------------------------------------------------------------
189    inline Ogre::Vector3 RigidBody::getCenterOfMassPosition() const
190    {
191        return OgreBulletCollisions::BtOgreConverter::to(getBulletRigidBody()->getCenterOfMassPosition());
192    }
193    // -------------------------------------------------------------------------   
194   
195}
196#endif //_OGREBULLETDYNAMICS_RigidObject_H
197
Note: See TracBrowser for help on using the repository browser.