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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include "Headers/PhysicsComponent.h"

#include "Core/Math/Headers/Transform.h"
#include "Graphs/Headers/SceneGraphNode.h"
#include "Geometry/Shapes/Headers/Object3D.h"
#include "Dynamics/Physics/Headers/PXDevice.h"
#include "Dynamics/Physics/Headers/PhysicsAPIWrapper.h"

namespace Divide {

PhysicsComponent::PhysicsComponent(SceneGraphNode* const parentSGN) : SGNComponent(SGNComponent::SGN_COMP_PHYSICS, parentSGN),
                                                                       _physicsCollisionGroup(NODE_COLLIDE_IGNORE),
                                                                       _transformUpdated(true),
                                                                       _physicsAsset(nullptr),
                                                                       _transform(nullptr)
{
    _transform = MemoryManager_NEW Transform();
    reset();
}

PhysicsComponent::~PhysicsComponent()
{
    MemoryManager::DELETE( _transform );
}

void PhysicsComponent::reset() {
    _worldMatrix.identity();
    _scaleCache.set(1.0f);
    _positionCache.set(0.0f);
    _orientationCache.identity();
    _prevTransformValues._translation.set(0.0f);
    _prevTransformValues._scale.set(1.0f);
    _prevTransformValues._orientation.identity();
}

void PhysicsComponent::useDefaultTransform(const bool state) {
    if (state && !_transform) {
        _transform = MemoryManager_NEW Transform();
       reset();
    } else if (!state && _transform) {
        MemoryManager::DELETE(_transform);
        reset();
    }
}

void PhysicsComponent::physicsAsset(PhysicsAsset* const asset) {
    DIVIDE_ASSERT(_physicsAsset == nullptr, 
                  "PhysicsComponent error: Double set physics asset detected! remove the previous one first!");
    _physicsAsset = asset;
	if ( _physicsAsset ) {
		_physicsAsset->setParent( this );
	}
}

void PhysicsComponent::cookCollisionMesh(const stringImpl& sceneName) {
    STUBBED("ToDo: add terrain height field and water cooking support! -Ionut")
	for (SceneGraphNode::NodeChildren::value_type& it : _parentSGN->getChildren()) {
        it.second->getComponent<PhysicsComponent>()->cookCollisionMesh( sceneName );
    }

    if (_parentSGN->getNode()->getType() == TYPE_OBJECT3D) {
        U32 obj3DExclussionMask = Object3D::TEXT_3D | Object3D::MESH | Object3D::FLYWEIGHT;
        if ( !bitCompare( obj3DExclussionMask, dynamic_cast<Object3D*>( _parentSGN->getNode() )->getObjectType() ) ) {
            PHYSICS_DEVICE.createActor( _parentSGN, sceneName,
                _parentSGN->usageContext() == SceneGraphNode::NODE_STATIC ? MASK_RIGID_STATIC : MASK_RIGID_DYNAMIC,
                _physicsCollisionGroup == NODE_COLLIDE_IGNORE ? GROUP_NON_COLLIDABLE :
                ( _physicsCollisionGroup == NODE_COLLIDE_NO_PUSH ? GROUP_COLLIDABLE_NON_PUSHABLE : GROUP_COLLIDABLE_PUSHABLE ) );
        }
    }

}

void PhysicsComponent::setTransformDirty() {
    if ( _physicsAsset ) {
        _physicsAsset->resetTransforms( true );
    }
    _transformUpdated = true;
}

void PhysicsComponent::setPosition(const vec3<F32>& position) {
    if (_transform) {
        _transform->setPosition(position);
        setTransformDirty();
    }
}

void PhysicsComponent::setScale(const vec3<F32>& scale) {
    if (_transform) {
        _transform->setScale(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotation(const vec3<F32>& axis, F32 degrees, bool inDegrees) {
    if (_transform) {
        _transform->setRotation(axis, degrees, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotation(const vec3<F32>& euler, bool inDegrees) {
    if (_transform) {
        _transform->setRotation(euler, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotation(const Quaternion<F32>& quat) {
    if (_transform) {
        _transform->setRotation(quat);
        setTransformDirty();
    }
}

void PhysicsComponent::translate(const vec3<F32>& axisFactors) {
    if (_transform) {
        _transform->translate(axisFactors);
        setTransformDirty();
    }
}

void PhysicsComponent::scale(const vec3<F32>& axisFactors) {
    if (_transform) {
        _transform->scale(axisFactors);
        setTransformDirty();
    }
}

void PhysicsComponent::rotate(const vec3<F32>& axis, F32 degrees, bool inDegrees) {
    if (_transform) {
        _transform->rotate(axis, degrees, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::rotate(const vec3<F32>& euler, bool inDegrees) {
    if (_transform) {
        _transform->rotate(euler, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::rotate(const Quaternion<F32>& quat) {
    if (_transform) {
        _transform->rotate(quat);
        setTransformDirty();
    }
}

void PhysicsComponent::rotateSlerp(const Quaternion<F32>& quat, const D32 deltaTime) {
    if (_transform) {
        _transform->rotateSlerp(quat, deltaTime);
        setTransformDirty();
    }
}

void PhysicsComponent::setScale(const F32 scale) {
    if (_transform) {
        _transform->setScale(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::setScaleX(const F32 scale) {
    if (_transform) {
        _transform->setScaleX(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::setScaleY(const F32 scale) {
    if (_transform) {
        _transform->setScaleY(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::setScaleZ(const F32 scale) {
    if (_transform) {
        _transform->setScaleZ(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::scale(const F32 scale) {
    if (_transform) {
        _transform->scale(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::scaleX(const F32 scale) {
    if (_transform) {
        _transform->scaleX(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::scaleY(const F32 scale) {
    if (_transform) {
        _transform->scaleY(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::scaleZ(const F32 scale) {
    if (_transform) {
        _transform->scaleZ(scale);
        setTransformDirty();
    }
}

void PhysicsComponent::rotateX(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->rotateX(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::rotateY(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->rotateY(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::rotateZ(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->rotateZ(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotationX(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->setRotationX(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotationXEuler(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->setRotationXEuler(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotationY(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->setRotationY(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::setRotationZ(const F32 angle, bool inDegrees) {
    if (_transform) {
        _transform->setRotationZ(angle, inDegrees);
        setTransformDirty();
    }
}

void PhysicsComponent::translateX(const F32 positionX) {
    if (_transform) {
        _transform->translateX(positionX);
        setTransformDirty();
    }
}

void PhysicsComponent::translateY(const F32 positionY) {
    if (_transform) {
        _transform->translateY(positionY);
        setTransformDirty();
    }
}

void PhysicsComponent::translateZ(const F32 positionZ) {
    if (_transform) {
        _transform->translateZ(positionZ);
        setTransformDirty();
    }
}

void PhysicsComponent::setPositionX(const F32 positionX) {
    if (_transform) {
        _transform->setPositionX(positionX);
        setTransformDirty();
    }
}

void PhysicsComponent::setPositionY(const F32 positionY) {
    if (_transform) {
        _transform->setPositionY(positionY);
        setTransformDirty();
    }
}

void PhysicsComponent::setPositionZ(const F32 positionZ) {
    if (_transform) {
        _transform->setPositionZ(positionZ);
        setTransformDirty();
    }
}

const mat4<F32>& PhysicsComponent::getWorldMatrix( D32 interpolationFactor, const bool local ) {
    if (_transform) {
        if (interpolationFactor < 0.95) {
            _worldMatrix.identity();
            _worldMatrix.setScale(lerp(_prevTransformValues._scale, _transform->getScale(), (F32)interpolationFactor));
            _worldMatrix *= Divide::getMatrix(slerp(_prevTransformValues._orientation, 
                                                    _transform->getOrientation(), 
                                                    (F32)interpolationFactor));
            _worldMatrix.setTranslation(lerp(_prevTransformValues._translation, 
                                             _transform->getPosition(), 
                                             (F32)interpolationFactor));
        } else {
            _worldMatrix.set(_transform->getMatrix());
        }
        _prevTransformValues = _transform->getValues();
    } else {
        _worldMatrix.identity();
    }

    const SceneGraphNode* const parent = _parentSGN->getParent();
    if ( !local && parent ) {
        _worldMatrix *= parent->getComponent<PhysicsComponent>()->getWorldMatrix(interpolationFactor, local);
    }

    return _worldMatrix;
}

/// Return the scale factor
const vec3<F32>& PhysicsComponent::getScale( const bool local ) {
    if (_transform) {
        _scaleCache.set(_transform->getScale());
    } else {
        _scaleCache.set(1.0f);
    }

    const SceneGraphNode* const parent = _parentSGN->getParent();
    if ( !local && parent ) {
        _scaleCache *= parent->getComponent<PhysicsComponent>()->getScale(local);
    } 

    return _scaleCache;
}

/// Return the position
const vec3<F32>& PhysicsComponent::getPosition( const bool local) {
    if (_transform) {
        _positionCache.set(_transform->getPosition());
    } else {
        _positionCache.set(0.0f);
    }

    const SceneGraphNode* const parent = _parentSGN->getParent();
    if ( !local && parent ) {
        _positionCache += parent->getComponent <PhysicsComponent>()->getPosition(local);
    }

    return _positionCache;
}

/// Return the orientation quaternion
const Quaternion<F32>& PhysicsComponent::getOrientation( const bool local ) {
    if (_transform) {
        _orientationCache.set(_transform->getOrientation());
    } else {
        _orientationCache.identity();
    }

    const SceneGraphNode* const parent = _parentSGN->getParent();
    if ( !local && parent ) {
        _orientationCache.set(parent->getComponent<PhysicsComponent>()->getOrientation(local).inverse() * _orientationCache);
    }

    return _orientationCache;
}

};

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

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

329 Diff Diff IonutCava picture IonutCava Tue 07 Oct, 2014 12:51:37 +0000

[Ionut]
- Modified material class and shaders to support multiple BRDFs (currently, only Flat, Phong and Blinn-Phong supported with Cook-Torrance and Oren-Nayar in future commits)
- Optimized transform updates and queries
- Fixed an indirect draw command (no buffer was bound to GL_DRAW_INDIRECT_BUFFER, violating a core requirement)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

324 Diff Diff IonutCava picture IonutCava Sun 14 Sep, 2014 14:01:39 +0000

[Ionut]
- New memory management system (no custom allocators in this commit)
— Memory tracer to detect memory leaks on shutdown (from: https://www.relisoft.com/book/tech/9new.html)
— SAFE_DELETE_XYZ are now inline template functions not macros
— ASSERTION system now supports logging and message boxes and continue on error configurable for each build type
— Fixed a lot of memory leaks detected by the new system (some still remain)

- Added SRGB support (part 1)
— Albedo textures are loaded as SRGB (make sure resources are SRGB)
— Shaders output gamma corrected colors
— Moved terrain textures back to 2 array system (albedo and normal maps, albedo maps using a SRGB sampler)

- Sky is now loaded via the ResourceCache system
- Added include safeguards in shader atoms

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

308 Diff Diff IonutCava picture IonutCava Sat 16 Aug, 2014 19:49:31 +0000

[Ionut]
- Moved Transform from SceneGraphNode to PhysicsComponent and modified BoundingBox update system based on transform update
- Added PhysicsAsset to PhysicsComponent for interfacing with PshysicsAPIs (e.g. PhysXActor inherits PhysicsAsset)
- PhysicsAsset keeps track of the parent PhysicsComponent to have direct access to a node’s transform
- Rewrote GUIConsole to only print items when visible, and use a single circular buffer for entries.
- Updated GUI input system to match the interface that both Kernel and SceneManager share (should probably abstract all the input methods in a class and have Kernel, SceneManager, Scene and GUI inherit from that. In next commit.)
- Updated CEGUI to probably match the OIS states(mouse, keyboard, etc) and properly inject time inputs.

279 IonutCava picture IonutCava Sat 28 Jun, 2014 16:20:46 +0000

[Ionut][[BR]]
- Unified draw command system into GenericDrawCommand [[BR]]
- Fixed double VB creation in Object3D [[BR]]
- Reworked triangle data computation (now Object3D’s responsibility) [[BR]]
- VertexArrays can now render using the primitive type specified in the draw command instead of the fixed type specified at creation [[BR]]
- Optimized terrain shader [[BR]]