OSDN Git Service

Started kinematic controller
[skyscrapersim/skyscraper.git] / ogrebullet / Dynamics / include / OgreBulletDynamicsCharacter.h
1 /***************************************************************************
2
3 This source file is part of OGREBULLET
4 (Object-oriented Graphics Rendering Engine Bullet Wrapper)
5 For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10
6
7 Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)
8
9
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 THE SOFTWARE.
28 -----------------------------------------------------------------------------
29 */
30
31 #ifndef _OGREBULLETDYNAMICS_Character_H
32 #define _OGREBULLETDYNAMICS_Character_H
33
34 #include "OgreBulletDynamicsPreRequisites.h"
35
36 #include "OgreBulletCollisionsObject.h"
37 #include "OgreBulletCollisionsWorld.h"
38 #include "BulletDynamics/Character/btKinematicCharacterController.h"
39 #include "BulletCollision/CollisionDispatch/btGhostObject.h"
40 #include "Utils/OgreBulletConverter.h"
41
42 #include "OgreBulletDynamicsWorld.h"
43
44 namespace OgreBulletDynamics
45 {
46     // -------------------------------------------------------------------------
47     // basic character controller class
48     class _OgreBulletExport CharacterController : public OgreBulletCollisions::Object
49     {
50     public:
51             CharacterController(const Ogre::String &name, 
52                                   DynamicsWorld *world,
53                                   Ogre::SceneNode *node);
54
55             virtual ~CharacterController();
56
57         void addToWorld();
58         void removeFromWorld();
59         void setLinearVelocity(const Ogre::Vector3 &vel);
60         void setLinearVelocity(const Ogre::Real x, const Ogre::Real y, const Ogre::Real z);
61                 Ogre::Vector3 getLinearVelocity();
62         void setAngularVelocity(const Ogre::Vector3 &vel);
63         void setAngularVelocity(const Ogre::Real x, const Ogre::Real y, const Ogre::Real z);
64                 Ogre::Vector3 getAngularVelocity();
65         void setAngularFactor(const Ogre::Vector3 &vel);
66         void setAngularFactor(const Ogre::Real x, const Ogre::Real y, const Ogre::Real z);
67                 Ogre::Vector3 getAngularFactor();
68         void applyImpulse(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position);
69         void applyForce(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position);
70                 void setSleepingThresholds( const Ogre::Real linear, const Ogre::Real angular );
71                 void setGravity(const Ogre::Vector3 &gravity);
72                 Ogre::Vector3 getGravity();
73
74
75         inline btRigidBody*         getBulletRigidBody() const;
76         inline btDynamicsWorld*     getBulletDynamicsWorld() const;
77         inline DynamicsWorld*       getDynamicsWorld();
78
79         Ogre::SceneNode*  getSceneNode() const {return mRootNode;};
80
81         inline void disableDeactivation();
82         inline void enableActiveState ();
83         inline void forceActivationState();
84         void setDeactivationTime(const float ftime);
85
86         inline const btTransform &getCenterOfMassTransform() const;
87         inline Ogre::Quaternion    getCenterOfMassOrientation () const;
88         inline Ogre::Vector3 getCenterOfMassPosition() const;
89
90         Ogre::Vector3       getCenterOfMassPivot (const Ogre::Vector3 &pivotPosition) const;
91         
92         void setDamping( const Ogre::Real linearDamping, const Ogre::Real angularDamping );
93         protected:
94                 short mCollisionGroup;
95                 short mCollisionMask;
96                 bool in_world;
97                 btKinematicCharacterController *m_character;
98     };
99     // -------------------------------------------------------------------------
100     // basic rigid body class inline methods
101     // -------------------------------------------------------------------------
102     /*inline btRigidBody*  RigidBody::getBulletRigidBody() const 
103     {
104         return static_cast <btRigidBody* > (mObject);
105     };*/
106     // -------------------------------------------------------------------------
107     inline btDynamicsWorld*     CharacterController::getBulletDynamicsWorld() const 
108     { 
109         return static_cast <btDynamicsWorld * > (mWorld->getBulletCollisionWorld ());
110     };
111     // -------------------------------------------------------------------------
112     inline DynamicsWorld*       CharacterController::getDynamicsWorld() 
113     { 
114         return static_cast <DynamicsWorld* > (mWorld);
115     };
116     
117 }
118 #endif //_OGREBULLETDYNAMICS_Character_H
119