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 class btConvexShape;
16 
17 namespace Resource
18 {
19  class BulletShape;
20 }
21 
22 namespace MWPhysics
23 {
24 
25  class PtrHolder
26  {
27  public:
28  virtual ~PtrHolder() {}
29 
30  void updatePtr(const MWWorld::Ptr& updated)
31  {
32  mPtr = updated;
33  }
34 
36  {
37  return mPtr;
38  }
39 
41  {
42  return mPtr;
43  }
44 
45  protected:
47  };
48 
49  class Actor : public PtrHolder
50  {
51  public:
52  Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<const Resource::BulletShape> shape, btCollisionWorld* world);
53  ~Actor();
54 
58  void enableCollisionMode(bool collision);
59 
60  bool getCollisionMode() const
61  {
63  }
64 
65  btConvexShape* getConvexShape() const { return mConvexShape; }
66 
70  void enableCollisionBody(bool collision);
71 
72  void updateScale();
73  void updateRotation();
74 
78  bool isRotationallyInvariant() const;
79 
84  void updatePosition();
85 
87 
91  osg::Vec3f getHalfExtents() const;
92 
97  osg::Vec3f getCollisionObjectPosition() const;
98 
102  void setPosition(const osg::Vec3f& position);
103 
104  osg::Vec3f getPosition() const;
105 
106  osg::Vec3f getPreviousPosition() const;
107 
113  osg::Vec3f getRenderingHalfExtents() const;
114 
118  void setInertialForce(const osg::Vec3f &force);
119 
123  const osg::Vec3f &getInertialForce() const
124  {
125  return mForce;
126  }
127 
128  void setOnGround(bool grounded);
129 
130  bool getOnGround() const
131  {
133  }
134 
135  void setOnSlope(bool slope);
136 
137  bool getOnSlope() const
138  {
140  }
141 
142  btCollisionObject* getCollisionObject() const
143  {
144  return mCollisionObject.get();
145  }
146 
148  void setCanWaterWalk(bool waterWalk);
149 
151  void setWalkingOnWater(bool walkingOnWater);
152  bool isWalkingOnWater() const;
153 
154  private:
156  void updateCollisionMask();
157  void addCollisionMask(int collisionMask);
158  int getCollisionMask();
159 
162 
164 
165  std::unique_ptr<btCollisionShape> mShape;
166  btConvexShape* mConvexShape;
167 
168  std::unique_ptr<btCollisionObject> mCollisionObject;
169 
170  osg::Vec3f mMeshTranslation;
171  osg::Vec3f mHalfExtents;
172  osg::Quat mRotation;
173 
174  osg::Vec3f mScale;
175  osg::Vec3f mRenderingScale;
176  osg::Vec3f mPosition;
177  osg::Vec3f mPreviousPosition;
178 
179  osg::Vec3f mForce;
180  bool mOnGround;
181  bool mOnSlope;
184 
185  btCollisionWorld* mCollisionWorld;
186 
187  Actor(const Actor&);
188  Actor& operator=(const Actor&);
189  };
190 
191 }
192 
193 
194 #endif
bool mWalkingOnWater
Definition: actor.hpp:161
osg::Vec3f mScale
Definition: actor.hpp:174
bool mExternalCollisionMode
Definition: actor.hpp:183
void updatePosition()
Definition: actor.cpp:100
osg::Quat mRotation
Definition: actor.hpp:172
void setWalkingOnWater(bool walkingOnWater)
Sets whether this actor has been walking on the water surface in the last frame.
Definition: actor.cpp:203
bool getOnGround() const
Definition: actor.hpp:130
void setOnSlope(bool slope)
Definition: actor.cpp:193
void updateCollisionMask()
Removes then re-adds the collision object to the dynamics world.
Definition: actor.cpp:83
bool isRotationallyInvariant() const
Definition: actor.cpp:152
MWWorld::ConstPtr getPtr() const
Definition: actor.hpp:40
bool mOnSlope
Definition: actor.hpp:181
virtual ~PtrHolder()
Definition: actor.hpp:28
btCollisionObject * getCollisionObject() const
Definition: actor.hpp:142
osg::Vec3f getHalfExtents() const
Definition: actor.cpp:173
std::unique_ptr< btCollisionShape > mShape
Definition: actor.hpp:165
osg::Vec3f mMeshTranslation
Definition: actor.hpp:170
void enableCollisionMode(bool collision)
Definition: actor.cpp:64
osg::Vec3f mHalfExtents
Definition: actor.hpp:171
int getCollisionMask()
Definition: actor.cpp:89
osg::Vec3f getPreviousPosition() const
Definition: actor.cpp:137
~Actor()
Definition: actor.cpp:58
bool mInternalCollisionMode
Definition: actor.hpp:182
osg::Vec3f getPosition() const
Definition: actor.cpp:132
osg::Vec3f getRenderingHalfExtents() const
Definition: actor.cpp:178
MWWorld::Ptr mPtr
Definition: actor.hpp:46
osg::Vec3f mPreviousPosition
Definition: actor.hpp:177
bool mCanWaterWalk
Definition: actor.hpp:160
std::unique_ptr< btCollisionObject > mCollisionObject
Definition: actor.hpp:168
btConvexShape * getConvexShape() const
Definition: actor.hpp:65
Actor(const MWWorld::Ptr &ptr, osg::ref_ptr< const Resource::BulletShape > shape, btCollisionWorld *world)
Definition: actor.cpp:19
void updateScale()
Definition: actor.cpp:157
osg::Vec3f mRenderingScale
Definition: actor.hpp:175
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
btCollisionWorld * mCollisionWorld
Definition: actor.hpp:185
Actor & operator=(const Actor &)
bool getCollisionMode() const
Definition: actor.hpp:60
void enableCollisionBody(bool collision)
Definition: actor.cpp:69
void addCollisionMask(int collisionMask)
Definition: actor.cpp:78
MWWorld::Ptr getPtr()
Definition: actor.hpp:35
bool getOnSlope() const
Definition: actor.hpp:137
void setCanWaterWalk(bool waterWalk)
Sets whether this actor should be able to collide with the water surface.
Definition: actor.cpp:208
osg::Vec3f mPosition
Definition: actor.hpp:176
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
bool mOnGround
Definition: actor.hpp:180
void updatePtr(const MWWorld::Ptr &updated)
Definition: actor.hpp:30
osg::Vec3f getCollisionObjectPosition() const
Definition: actor.cpp:119
void setInertialForce(const osg::Vec3f &force)
Definition: actor.cpp:183
void updateRotation()
Definition: actor.cpp:142
Definition: actor.hpp:25
void updateCollisionObjectPosition()
Definition: actor.cpp:110
bool isWalkingOnWater() const
Definition: actor.cpp:198
btConvexShape * mConvexShape
Definition: actor.hpp:166
void setOnGround(bool grounded)
Definition: actor.cpp:188
const osg::Vec3f & getInertialForce() const
Definition: actor.hpp:123
osg::Vec3f mForce
Definition: actor.hpp:179
bool mRotationallyInvariant
Definition: actor.hpp:163
void setPosition(const osg::Vec3f &position)
Definition: actor.cpp:124
Definition: actor.hpp:49