Overte C++ Documentation
ObjectDynamic.h
1 //
2 // ObjectDynamic.h
3 // libraries/physcis/src
4 //
5 // Created by Seth Alves 2015-6-2
6 // Copyright 2015 High Fidelity, Inc.
7 // Copyright 2023 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 // SPDX-License-Identifier: Apache-2.0
12 //
13 // http://bulletphysics.org/Bullet/BulletFull/classbtDynamicInterface.html
14 
15 #ifndef hifi_ObjectDynamic_h
16 #define hifi_ObjectDynamic_h
17 
18 #include <QUuid>
19 
20 #include <btBulletDynamicsCommon.h>
21 
22 #include <EntityItemID.h>
23 #include <shared/ReadWriteLockable.h>
24 #include <SpatiallyNestable.h>
25 
26 #include "ObjectMotionState.h"
27 #include "BulletUtil.h"
28 #include <EntityDynamicInterface.h>
29 
30 
31 class ObjectDynamic : public EntityDynamicInterface, public ReadWriteLockable {
32 public:
33  ObjectDynamic(EntityDynamicType type, const QUuid& id, EntityItemPointer ownerEntity);
34  virtual ~ObjectDynamic();
35 
36  virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) override;
37 
38  virtual void removeFromSimulation(EntitySimulationPointer simulation) const override;
39  virtual EntityItemWeakPointer getOwnerEntity() const override { return _ownerEntity; }
40  virtual void setOwnerEntity(const EntityItemPointer ownerEntity) override;
41 
42  virtual void invalidate() {};
43 
44  virtual bool updateArguments(QVariantMap arguments) override;
45  virtual QVariantMap getArguments() override;
46 
47 
48  virtual QByteArray serialize() const override = 0;
49  virtual void deserialize(QByteArray serializedArguments) override = 0;
50 
51  virtual bool lifetimeIsOver() override;
52  virtual quint64 getExpires() override { return _expires; }
53 
54  virtual QList<btRigidBody*> getRigidBodies();
55 
56 protected:
57  quint64 localTimeToServerTime(quint64 timeValue) const;
58  quint64 serverTimeToLocalTime(quint64 timeValue) const;
59 
60  btRigidBody* getOtherRigidBody(EntityItemID otherEntityID);
61  EntityItemPointer getEntityByID(EntityItemID entityID) const;
62  virtual btRigidBody* getRigidBody();
63  virtual void activateBody(bool forceActivation = false);
64  virtual void forceBodyNonStatic();
65 
66  EntityItemWeakPointer _ownerEntity;
67  QString _tag;
68  quint64 _expires { 0 }; // in seconds since epoch
69 
70  EntityItemID _otherID;
71  SpatiallyNestableWeakPointer _other;
72  SpatiallyNestablePointer getOther();
73  int _otherJointIndex { -1 };
74 
75 private:
76  qint64 getEntityServerClockSkew() const;
77 };
78 
79 typedef std::shared_ptr<ObjectDynamic> ObjectDynamicPointer;
80 
81 #endif // hifi_ObjectDynamic_h
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28