Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
Copyright (c) 2016 DIVIDE-Studio
Copyright (c) 2009 Ionut Cava

This file is part of DIVIDE Framework.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software
and associated documentation files (the "Software"), to deal in the Software
without restriction,
including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#ifndef _PHYSICS_COMPONENT_H_
#define _PHYSICS_COMPONENT_H_

#include "SGNComponent.h"
#include "Core/Math/Headers/Transform.h"

#include <stack>

namespace Divide {

class Transform;
class PhysicsAsset;
class SceneGraphNode;

enum class PhysicsGroup : U32 {
    GROUP_STATIC = 0,
    GROUP_DYNAMIC,
    GROUP_KINEMATIC,
    GROUP_RAGDOL,
    GROUP_VEHICLE,
    GROUP_IGNORE,
    GROUP_COUNT
};

class PhysicsComponent : public SGNComponent, public TransformInterface {
  public:
    enum class TransformType : U32 {
        TRANSLATION = 0,
        SCALE,
        ROTATION,
        VIEW_OFFSET,
        COUNT
    };

    class TransformMask {
        public:
           TransformMask()
           {
               clearAllFlags();
           }

           inline bool hasSetFlags() const {
                return getFlag(TransformType::SCALE) ||
                       getFlag(TransformType::ROTATION) ||
                       getFlag(TransformType::TRANSLATION) ||
                       getFlag(TransformType::VIEW_OFFSET);
           }

           inline bool hasSetAllFlags() const {
               return getFlag(TransformType::SCALE) &&
                      getFlag(TransformType::ROTATION) &&
                      getFlag(TransformType::TRANSLATION) &&
                      getFlag(TransformType::VIEW_OFFSET);
           }

           inline bool getFlag(TransformType type) const {
               return _transformFlags[to_uint(type)] == true;
           }

           inline void clearAllFlags() {
               _transformFlags[to_const_uint(TransformType::SCALE)] = false;
               _transformFlags[to_const_uint(TransformType::ROTATION)] = false;
               _transformFlags[to_const_uint(TransformType::TRANSLATION)] = false;
               _transformFlags[to_const_uint(TransformType::VIEW_OFFSET)] = false;
           }

           inline void setAllFlags() {
               _transformFlags[to_const_uint(TransformType::SCALE)] = true;
               _transformFlags[to_const_uint(TransformType::ROTATION)] = true;
               _transformFlags[to_const_uint(TransformType::TRANSLATION)] = true;
           }

           inline bool clearFlag(TransformType type) {
               _transformFlags[to_uint(type)] = false;
           }

           inline void setFlag(TransformType type) {
               _transformFlags[to_uint(type)] = true;
           }

           inline void setFlags(const TransformMask& other) {
               _transformFlags[to_const_uint(TransformType::SCALE)] =
                       other.getFlag(TransformType::SCALE);
               _transformFlags[to_const_uint(TransformType::ROTATION)] =
                       other.getFlag(TransformType::ROTATION);
               _transformFlags[to_const_uint(TransformType::TRANSLATION)] =
                       getFlag(TransformType::TRANSLATION);
               _transformFlags[to_const_uint(TransformType::VIEW_OFFSET)] =
                       getFlag(TransformType::VIEW_OFFSET);

           }
        private:
           std::array<AtomicWrapper<bool>, to_const_uint(TransformType::COUNT)> _transformFlags;
    };

    struct IgnoreViewSettings {
        IgnoreViewSettings() : _cameraGUID(-1)
        {
        }

        I64 _cameraGUID;
        vec3<F32> _posOffset;
        mat4<F32> _transformOffset;
    };

   public:
    void update(const U64 deltaTime);

    inline const PhysicsGroup& physicsGroup() const {
        return _physicsCollisionGroup;
    }


    void cookCollisionMesh(const stringImpl& sceneName);

    void reset();

    const mat4<F32>& getWorldMatrix();

    const mat4<F32>& getWorldMatrix(D64 interpolationFactor);
    
    /// Component <-> Transform interface
    void setPosition(const vec3<F32>& position) override;
    void setPositionX(const F32 positionX) override;
    void setPositionY(const F32 positionY) override;
    void setPositionZ(const F32 positionZ) override;
    void translate(const vec3<F32>& axisFactors) override;
    using TransformInterface::setPosition;

    void setScale(const vec3<F32>& ammount) override;
    void setScaleX(const F32 ammount) override;
    void setScaleY(const F32 ammount) override;
    void setScaleZ(const F32 ammount) override;
    void scale(const vec3<F32>& axisFactors) override;
    void scaleX(const F32 ammount) override;
    void scaleY(const F32 ammount) override;
    void scaleZ(const F32 ammount) override;
    using TransformInterface::setScale;

    void setRotation(const vec3<F32>& axis, F32 degrees, bool inDegrees = true) override;
    void setRotation(F32 pitch, F32 yaw, F32 roll, bool inDegrees = true) override;
    void setRotation(const Quaternion<F32>& quat) override;
    void setRotationX(const F32 angle, bool inDegrees = true) override;
    void setRotationY(const F32 angle, bool inDegrees = true) override;
    void setRotationZ(const F32 angle, bool inDegrees = true) override;
    using TransformInterface::setRotation;

    void rotate(const vec3<F32>& axis, F32 degrees, bool inDegrees = true) override;
    void rotate(F32 pitch, F32 yaw, F32 roll, bool inDegrees = true) override;
    void rotate(const Quaternion<F32>& quat) override;
    void rotateSlerp(const Quaternion<F32>& quat, const D64 deltaTime) override;
    void rotateX(const F32 angle, bool inDegrees = true) override;
    void rotateY(const F32 angle, bool inDegrees = true) override;
    void rotateZ(const F32 angle, bool inDegrees = true) override;
    using TransformInterface::rotate;

    inline void setTransform(const TransformValues& values) {
        setPosition(values._translation);
        setRotation(values._orientation);
        setScale(values._scale);
    }

    bool isUniformScaled() const;

    /// Return the position
    vec3<F32> getPosition() const override;
    /// Return the local position
    vec3<F32> getLocalPosition() const;
    /// Return the position
    vec3<F32> getPosition(D64 interpolationFactor) const;
    /// Return the local position
    vec3<F32> getLocalPosition(D64 interpolationFactor) const;

    /// Return the scale factor
    vec3<F32> getScale() const override;
    /// Return the local scale factor
    vec3<F32> getLocalScale() const;
    /// Return the scale factor
    vec3<F32> getScale(D64 interpolationFactor) const;
    /// Return the local scale factor
    vec3<F32> getLocalScale(D64 interpolationFactor) const;

    /// Return the orientation quaternion
    Quaternion<F32> getOrientation() const override;
    /// Return the local orientation quaternion
    Quaternion<F32> getLocalOrientation() const;
    /// Return the orientation quaternion
    Quaternion<F32> getOrientation(D64 interpolationFactor) const;
    /// Return the local orientation quaternion
    Quaternion<F32> getLocalOrientation(D64 interpolationFactor) const;

    const mat4<F32>& getMatrix() override;

    void pushTransforms();
    bool popTransforms();
    
    inline bool ignoreView(const I64 cameraGUID) const { 
        return _ignoreViewSettings._cameraGUID == cameraGUID;
    }

    void setViewOffset(const vec3<F32>& posOffset, const mat4<F32>& rotationOffset);

    void ignoreView(const bool state, const I64 cameraGUID);

   protected:
    friend class SceneGraphNode;
    PhysicsComponent(SceneGraphNode& parentSGN, PhysicsGroup physicsGroup);
    ~PhysicsComponent();

    inline void addTransformUpdateCbk(DELEGATE_CBK<> cbk) {
        _transformCallbacks.push_back(cbk);
    }

   private:
    void clean(bool interp);
    void setTransformDirty(TransformType type);
    bool isParentTransformDirty() const;

    Transform* getTransform() const;
    PhysicsAsset* getPhysicsAsset() const;

    bool physicsDriven() const;

   protected:

    TransformInterface* _transformInterface;
    IgnoreViewSettings _ignoreViewSettings;
    PhysicsGroup _physicsCollisionGroup;
    TransformValues _prevTransformValues;
    typedef std::stack<TransformValues> TransformStack;
    TransformStack _transformStack;
    TransformMask _transformUpdatedMask;

    vectorImpl<DELEGATE_CBK<> > _transformCallbacks;

    /// Transform cache values
    std::atomic_bool _dirty;
    std::atomic_bool _dirtyInterp;
    std::atomic_bool _parentDirty;

    bool _isUniformScaled;
    mat4<F32> _worldMatrix;
    D64  _prevInterpValue;
    mat4<F32> _worldMatrixInterp;
};

};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Graphs/Components/Headers/PhysicsComponent.h

Diff revisions: vs.
Revision Author Commited Message
750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

713 Diff Diff IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;

696 Diff Diff IonutCava picture IonutCava Mon 09 May, 2016 16:14:09 +0000

[IonutCava]
- More physics system preparation:
— Define specific px groups for nodes: static, kinematic, dynamic, ragdoll, etc

695 Diff Diff IonutCava picture IonutCava Sun 08 May, 2016 22:45:32 +0000

[IonutCava]
- Better separation of rigid body based physics and standard transform system

680 Diff Diff IonutCava picture IonutCava Thu 14 Apr, 2016 16:15:38 +0000

[IonutCava]
- Added a mat2 class (untested)
- Added static asserts to matrices, vectors and quaternions to allow only arithmetic (sans bool) data types
- Added more vector unit tests
- Added unit tests for matrices
- D32 finally renamed to D64 as the VC++ compiler is considered as the reference compiler

650 Diff Diff IonutCava picture IonutCava Tue 23 Feb, 2016 16:54:54 +0000

[IonutCava]
- Fix decoupling between PhysicsComponent and BoundsComponent
— SceneNodes now keep references to all owning SGNs and informs them when the bounds change
- AnimationComponent does not need a SceneAnimator on creation but most functionality will assert if one is not specified
— This was needed for the new component configuration system
- Added placeholder classes for an Inverse Kinematic component and a Ragdoll component
- SNG component configuration is now an upfront requirement: pass a component type mask when adding a node the the scenegraph
- SGN SpatialPartitionFlag is now an update flag that is set and cleared. More flags can be added in a similar fashion to nodes

649 Diff Diff IonutCava picture IonutCava Mon 22 Feb, 2016 17:16:17 +0000

[IonutCava]
- Attempt to uncouple PhysicsComponent from BoundsComponent

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

638 Diff Diff IonutCava picture IonutCava Mon 01 Feb, 2016 16:58:43 +0000

[IonutCava]
- Parent <-> Children transform hierarchy with cache fix

637 IonutCava picture IonutCava Sun 31 Jan, 2016 18:43:55 +0000

[IonutCava]
- More octree updates
- Investigate transform chain failure with nodes that have multiple children
— First child clears parent’s transform flag leaving the other children to update wrong