OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
actor.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWPHYSICS_ACTOR_H
2 #define OPENMW_MWPHYSICS_ACTOR_H
3 
4 #include <memory>
5 
6 #include "../mwworld/ptr.hpp"
7 
8 #include <osg/Vec3f>
9 #include <osg/Quat>
10 #include <osg/ref_ptr>
11 
12 class btCollisionWorld;
13 class btCollisionShape;
14 class btCollisionObject;
15 
16 namespace Resource
17 {
18  class BulletShape;
19 }
20 
21 namespace MWPhysics
22 {
23 
24  class PtrHolder
25  {
26  public:
27  virtual ~PtrHolder() {}
28 
29  void updatePtr(const MWWorld::Ptr& updated)
30  {
31  mPtr = updated;
32  }
33 
35  {
36  return mPtr;
37  }
38 
40  {
41  return mPtr;
42  }
43 
44  protected:
46  };
47 
48  class Actor : public PtrHolder
49  {
50  public:
51  Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<const Resource::BulletShape> shape, btCollisionWorld* world);
52  ~Actor();
53 
57  void enableCollisionMode(bool collision);
58 
59  bool getCollisionMode() const
60  {
62  }
63 
67  void enableCollisionBody(bool collision);
68 
69  void updateScale();
70  void updateRotation();
71 
76  void updatePosition();
77 
79 
83  osg::Vec3f getHalfExtents() const;
84 
89  osg::Vec3f getCollisionObjectPosition() const;
90 
94  void setPosition(const osg::Vec3f& position);
95 
96  osg::Vec3f getPosition() const;
97 
98  osg::Vec3f getPreviousPosition() const;
99 
105  osg::Vec3f getRenderingHalfExtents() const;
106 
110  void setInertialForce(const osg::Vec3f &force);
111 
115  const osg::Vec3f &getInertialForce() const
116  {
117  return mForce;
118  }
119 
120  void setOnGround(bool grounded);
121 
122  bool getOnGround() const
123  {
125  }
126 
127  btCollisionObject* getCollisionObject() const
128  {
129  return mCollisionObject.get();
130  }
131 
133  void setCanWaterWalk(bool waterWalk);
134 
136  void setWalkingOnWater(bool walkingOnWater);
137  bool isWalkingOnWater() const;
138 
139  private:
141  void updateCollisionMask();
142  void addCollisionMask(int collisionMask);
143  int getCollisionMask();
144 
147 
148  std::auto_ptr<btCollisionShape> mShape;
149 
150  std::auto_ptr<btCollisionObject> mCollisionObject;
151 
152  osg::Vec3f mMeshTranslation;
153  osg::Vec3f mHalfExtents;
154  osg::Quat mRotation;
155 
156  osg::Vec3f mScale;
157  osg::Vec3f mRenderingScale;
158  osg::Vec3f mPosition;
159  osg::Vec3f mPreviousPosition;
160 
161  osg::Vec3f mForce;
162  bool mOnGround;
165 
166  btCollisionWorld* mCollisionWorld;
167 
168  Actor(const Actor&);
169  Actor& operator=(const Actor&);
170  };
171 
172 }
173 
174 
175 #endif
bool mWalkingOnWater
Definition: actor.hpp:146
osg::Vec3f mScale
Definition: actor.hpp:156
bool mExternalCollisionMode
Definition: actor.hpp:164
void updatePosition()
Definition: actor.cpp:95
osg::Quat mRotation
Definition: actor.hpp:154
void setWalkingOnWater(bool walkingOnWater)
Sets whether this actor has been walking on the water surface in the last frame.
Definition: actor.cpp:188
bool getOnGround() const
Definition: actor.hpp:122
std::auto_ptr< btCollisionObject > mCollisionObject
Definition: actor.hpp:150
void updateCollisionMask()
Removes then re-adds the collision object to the dynamics world.
Definition: actor.cpp:78
MWWorld::ConstPtr getPtr() const
Definition: actor.hpp:39
virtual ~PtrHolder()
Definition: actor.hpp:27
btCollisionObject * getCollisionObject() const
Definition: actor.hpp:127
osg::Vec3f getHalfExtents() const
Definition: actor.cpp:163
osg::Vec3f mMeshTranslation
Definition: actor.hpp:152
void enableCollisionMode(bool collision)
Definition: actor.cpp:59
osg::Vec3f mHalfExtents
Definition: actor.hpp:153
int getCollisionMask()
Definition: actor.cpp:84
osg::Vec3f getPreviousPosition() const
Definition: actor.cpp:132
~Actor()
Definition: actor.cpp:53
bool mInternalCollisionMode
Definition: actor.hpp:163
osg::Vec3f getPosition() const
Definition: actor.cpp:127
osg::Vec3f getRenderingHalfExtents() const
Definition: actor.cpp:168
MWWorld::Ptr mPtr
Definition: actor.hpp:45
osg::Vec3f mPreviousPosition
Definition: actor.hpp:159
bool mCanWaterWalk
Definition: actor.hpp:145
Actor(const MWWorld::Ptr &ptr, osg::ref_ptr< const Resource::BulletShape > shape, btCollisionWorld *world)
Definition: actor.cpp:19
void updateScale()
Definition: actor.cpp:147
osg::Vec3f mRenderingScale
Definition: actor.hpp:157
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
std::auto_ptr< btCollisionShape > mShape
Definition: actor.hpp:148
btCollisionWorld * mCollisionWorld
Definition: actor.hpp:166
Actor & operator=(const Actor &)
bool getCollisionMode() const
Definition: actor.hpp:59
void enableCollisionBody(bool collision)
Definition: actor.cpp:64
void addCollisionMask(int collisionMask)
Definition: actor.cpp:73
MWWorld::Ptr getPtr()
Definition: actor.hpp:34
void setCanWaterWalk(bool waterWalk)
Sets whether this actor should be able to collide with the water surface.
Definition: actor.cpp:193
osg::Vec3f mPosition
Definition: actor.hpp:158
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
bool mOnGround
Definition: actor.hpp:162
void updatePtr(const MWWorld::Ptr &updated)
Definition: actor.hpp:29
osg::Vec3f getCollisionObjectPosition() const
Definition: actor.cpp:114
void setInertialForce(const osg::Vec3f &force)
Definition: actor.cpp:173
void updateRotation()
Definition: actor.cpp:137
Definition: actor.hpp:24
void updateCollisionObjectPosition()
Definition: actor.cpp:105
bool isWalkingOnWater() const
Definition: actor.cpp:183
void setOnGround(bool grounded)
Definition: actor.cpp:178
const osg::Vec3f & getInertialForce() const
Definition: actor.hpp:115
osg::Vec3f mForce
Definition: actor.hpp:161
void setPosition(const osg::Vec3f &position)
Definition: actor.cpp:119
Definition: actor.hpp:48