History

support for simple kinematic motion

Andrew Meadows committed 11 years ago

Commit 250fd981 parent 04b4a9514 files · +251 −31Browse files

Showing the changes to libraries/physics/src/ObjectMotionState.cpp (1 of 14 files). Show all

Unified · Split

libraries/physics/src/ObjectMotionState.cpp+14−3
@@ -14,7 +14,9 @@ · 13 unmodified lines
14#include <math.h>14#include <math.h>
15 15
16#include "BulletUtil.h"16#include "BulletUtil.h"
17#include "KinematicController.h"
17#include "ObjectMotionState.h"18#include "ObjectMotionState.h"
19#include "PhysicsEngine.h"
18 20
19const float MIN_DENSITY = 200.0f;21const float MIN_DENSITY = 200.0f;
20const float DEFAULT_DENSITY = 1000.0f;22const float DEFAULT_DENSITY = 1000.0f;
@@ -67,6 +69,10 @@ ObjectMotionState::ObjectMotionState() : · 46 unmodified lines
67ObjectMotionState::~ObjectMotionState() {69ObjectMotionState::~ObjectMotionState() {
68 // NOTE: you MUST remove this MotionState from the world before you call the dtor.70 // NOTE: you MUST remove this MotionState from the world before you call the dtor.
69 assert(_body == NULL);71 assert(_body == NULL);
72 if (_kinematicController) {
73 delete _kinematicController;
74 _kinematicController = NULL;
75 }
70}76}
71 77
72void ObjectMotionState::setDensity(float density) {78void ObjectMotionState::setDensity(float density) {
@@ -121,11 +127,9 @@ bool ObjectMotionState::doesNotNeedToSendUpdate() const { · 48 unmodified lines
121 return !_body->isActive() && _numNonMovingUpdates > MAX_NUM_NON_MOVING_UPDATES;127 return !_body->isActive() && _numNonMovingUpdates > MAX_NUM_NON_MOVING_UPDATES;
122}128}
123 129
124const float FIXED_SUBSTEP = 1.0f / 60.0f;
125
126bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) {130bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) {
127 assert(_body);131 assert(_body);
128 float dt = (float)(simulationFrame - _sentFrame) * FIXED_SUBSTEP;132 float dt = (float)(simulationFrame - _sentFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP;
129 _sentFrame = simulationFrame;133 _sentFrame = simulationFrame;
130 bool isActive = _body->isActive();134 bool isActive = _body->isActive();
131 135
@@ -186,4 +190,11 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { · 54 unmodified lines
186 return (fabsf(glm::dot(actualRotation, _sentRotation)) < MIN_ROTATION_DOT);190 return (fabsf(glm::dot(actualRotation, _sentRotation)) < MIN_ROTATION_DOT);
187}191}
188 192
193void ObjectMotionState::removeKinematicController() {
194 if (_kinematicController) {
195 delete _kinematicController;
196 _kinematicController = NULL;
197 }
198}
199
189#endif // USE_BULLET_PHYSICS200#endif // USE_BULLET_PHYSICS

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t