Overte C++ Documentation
AvatarMotionState.h
1 //
2 // AvatarMotionState.h
3 // interface/src/avatar/
4 //
5 // Created by Andrew Meadows 2015.05.14
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_AvatarMotionState_h
13 #define hifi_AvatarMotionState_h
14 
15 #include <QSet>
16 
17 #include <ObjectMotionState.h>
18 #include <BulletUtil.h>
19 
20 #include "OtherAvatar.h"
21 
22 class AvatarMotionState : public ObjectMotionState {
23 public:
24  AvatarMotionState(OtherAvatarPointer avatar, const btCollisionShape* shape);
25 
26  void handleEasyChanges(uint32_t& flags) override;
27 
28  PhysicsMotionType getMotionType() const override { return _motionType; }
29 
30  uint32_t getIncomingDirtyFlags() const override;
31  void clearIncomingDirtyFlags(uint32_t mask = DIRTY_PHYSICS_FLAGS) override;
32 
33  PhysicsMotionType computePhysicsMotionType() const override;
34 
35  bool isMoving() const override;
36 
37  // this relays incoming position/rotation to the RigidBody
38  void getWorldTransform(btTransform& worldTrans) const override;
39 
40  // this relays outgoing position/rotation to the EntityItem
41  void setWorldTransform(const btTransform& worldTrans) override;
42 
43 
44  // These pure virtual methods must be implemented for each MotionState type
45  // and make it possible to implement more complicated methods in this base class.
46 
47  // pure virtual overrides from ObjectMotionState
48  float getObjectRestitution() const override;
49  float getObjectFriction() const override;
50  float getObjectLinearDamping() const override;
51  float getObjectAngularDamping() const override;
52 
53  glm::vec3 getObjectPosition() const override;
54  glm::quat getObjectRotation() const override;
55  glm::vec3 getObjectLinearVelocity() const override;
56  glm::vec3 getObjectAngularVelocity() const override;
57  glm::vec3 getObjectGravity() const override;
58 
59  const QUuid getObjectID() const override;
60 
61  QString getName() const override;
62  ShapeType getShapeType() const override { return SHAPE_TYPE_CAPSULE_Y; }
63  QUuid getSimulatorID() const override;
64 
65  void setBoundingBox(const glm::vec3& corner, const glm::vec3& diagonal);
66 
67  void addDirtyFlags(uint32_t flags) { _dirtyFlags |= flags; }
68 
69  void setCollisionGroup(int32_t group) { _collisionGroup = group; }
70  int32_t getCollisionGroup() { return _collisionGroup; }
71 
72  void computeCollisionGroupAndMask(int32_t& group, int32_t& mask) const override;
73 
74  float getMass() const override;
75 
76  friend class AvatarManager;
77  friend class Avatar;
78 
79 protected:
80  void setRigidBody(btRigidBody* body) override;
81  void setShape(const btCollisionShape* shape) override;
82  void cacheShapeDiameter();
83 
84  // the dtor had been made protected to force the compiler to verify that it is only
85  // ever called by the Avatar class dtor.
86  ~AvatarMotionState();
87 
88  OtherAvatarPointer _avatar;
89  float _diameter { 0.0f };
90  int32_t _collisionGroup;
91  uint32_t _dirtyFlags;
92 };
93 
94 #endif // hifi_AvatarMotionState_h