Overte C++ Documentation
DetailedMotionState.h
1 //
2 // DetailedMotionState.h
3 // interface/src/avatar/
4 //
5 // Created by Luis Cuenca 1/11/2019
6 // Copyright 2019 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_DetailedMotionState_h
13 #define hifi_DetailedMotionState_h
14 
15 #include <QSet>
16 
17 #include <ObjectMotionState.h>
18 #include <BulletUtil.h>
19 
20 #include "OtherAvatar.h"
21 
22 class DetailedMotionState : public ObjectMotionState {
23 public:
24  DetailedMotionState(AvatarPointer avatar, const btCollisionShape* shape, int jointIndex);
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_HULL; }
63  QUuid getSimulatorID() const override;
64 
65  void addDirtyFlags(uint32_t flags) { _dirtyFlags |= flags; }
66 
67  void computeCollisionGroupAndMask(int32_t& group, int32_t& mask) const override;
68 
69  float getMass() const override;
70  void forceActive();
71  QUuid getAvatarID() const { return _avatar->getID(); }
72  int32_t getJointIndex() const { return _jointIndex; }
73  void setIsBound(bool isBound, const std::vector<int32_t>& boundJoints) { _isBound = isBound; _boundJoints = boundJoints; }
74  bool getIsBound(std::vector<int32_t>& boundJoints) const { boundJoints = _boundJoints; return _isBound; }
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 
83  // the dtor had been made protected to force the compiler to verify that it is only
84  // ever called by the Avatar class dtor.
85  ~DetailedMotionState();
86 
87  AvatarPointer _avatar;
88  float _diameter { 0.0f };
89 
90  uint32_t _dirtyFlags;
91  int32_t _jointIndex { -1 };
92  OtherAvatarPointer _otherAvatar { nullptr };
93  bool _isBound { false };
94  std::vector<int32_t> _boundJoints;
95 };
96 
97 #endif // hifi_DetailedMotionState_h