mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 12:24:26 +02:00
add other ragdolls to simulation
This commit is contained in:
parent
87350ad2d0
commit
0f784a9cc5
3 changed files with 28 additions and 9 deletions
|
@ -204,6 +204,7 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
const int minError = 0.01f;
|
const int minError = 0.01f;
|
||||||
const float maxIterations = 10;
|
const float maxIterations = 10;
|
||||||
const quint64 maxUsec = 2000;
|
const quint64 maxUsec = 2000;
|
||||||
|
_physicsSimulation.setTranslation(_position);
|
||||||
_physicsSimulation.stepForward(deltaTime, minError, maxIterations, maxUsec);
|
_physicsSimulation.stepForward(deltaTime, minError, maxIterations, maxUsec);
|
||||||
} else {
|
} else {
|
||||||
_skeletonModel.moveShapesTowardJoints(1.0f);
|
_skeletonModel.moveShapesTowardJoints(1.0f);
|
||||||
|
@ -230,12 +231,10 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
} else {
|
} else {
|
||||||
_trapDuration = 0.0f;
|
_trapDuration = 0.0f;
|
||||||
}
|
}
|
||||||
/* TODO: Andrew to make this work
|
|
||||||
if (_collisionGroups & COLLISION_GROUP_AVATARS) {
|
if (_collisionGroups & COLLISION_GROUP_AVATARS) {
|
||||||
PerformanceTimer perfTimer("avatars");
|
PerformanceTimer perfTimer("avatars");
|
||||||
updateCollisionWithAvatars(deltaTime);
|
updateCollisionWithAvatars(deltaTime);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// consider updating our billboard
|
// consider updating our billboard
|
||||||
|
@ -1566,13 +1565,11 @@ void MyAvatar::updateCollisionWithAvatars(float deltaTime) {
|
||||||
PhysicsSimulation* simulation = skeleton->getSimulation();
|
PhysicsSimulation* simulation = skeleton->getSimulation();
|
||||||
if (avatar == nearestAvatar) {
|
if (avatar == nearestAvatar) {
|
||||||
if (simulation != &(_physicsSimulation)) {
|
if (simulation != &(_physicsSimulation)) {
|
||||||
std::cout << "adebug adding other avatar " << avatar << " to simulation" << std::endl; // adebug
|
|
||||||
skeleton->setEnableShapes(true);
|
skeleton->setEnableShapes(true);
|
||||||
_physicsSimulation.addEntity(skeleton);
|
_physicsSimulation.addEntity(skeleton);
|
||||||
_physicsSimulation.addRagdoll(skeleton);
|
_physicsSimulation.addRagdoll(skeleton);
|
||||||
}
|
}
|
||||||
} else if (simulation == &(_physicsSimulation)) {
|
} else if (simulation == &(_physicsSimulation)) {
|
||||||
std::cout << "adebug removing other avatar " << avatar << " from simulation" << std::endl; // adebug
|
|
||||||
_physicsSimulation.removeRagdoll(skeleton);
|
_physicsSimulation.removeRagdoll(skeleton);
|
||||||
_physicsSimulation.removeEntity(skeleton);
|
_physicsSimulation.removeEntity(skeleton);
|
||||||
skeleton->setEnableShapes(false);
|
skeleton->setEnableShapes(false);
|
||||||
|
|
|
@ -44,6 +44,19 @@ PhysicsSimulation::~PhysicsSimulation() {
|
||||||
_otherRagdolls.clear();
|
_otherRagdolls.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsSimulation::setRagdoll(Ragdoll* ragdoll) {
|
||||||
|
if (_ragdoll != ragdoll) {
|
||||||
|
if (_ragdoll) {
|
||||||
|
_ragdoll->_ragdollSimulation = NULL;
|
||||||
|
}
|
||||||
|
_ragdoll = ragdoll;
|
||||||
|
if (_ragdoll) {
|
||||||
|
assert(!(_ragdoll->_ragdollSimulation));
|
||||||
|
_ragdoll->_ragdollSimulation = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsSimulation::setEntity(PhysicsEntity* entity) {
|
void PhysicsSimulation::setEntity(PhysicsEntity* entity) {
|
||||||
if (_entity != entity) {
|
if (_entity != entity) {
|
||||||
if (_entity) {
|
if (_entity) {
|
||||||
|
@ -79,6 +92,7 @@ bool PhysicsSimulation::addEntity(PhysicsEntity* entity) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// add to list
|
// add to list
|
||||||
|
assert(!(entity->_simulation));
|
||||||
entity->_simulation = this;
|
entity->_simulation = this;
|
||||||
_otherEntities.push_back(entity);
|
_otherEntities.push_back(entity);
|
||||||
return true;
|
return true;
|
||||||
|
@ -128,19 +142,26 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
|
||||||
// list is full
|
// list is full
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
if (doll->_ragdollSimulation == this) {
|
||||||
if (doll == _otherRagdolls[i]) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
// already in list
|
if (doll == _otherRagdolls[i]) {
|
||||||
return true;
|
// already in list
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add to list
|
// add to list
|
||||||
|
assert(!(doll->_ragdollSimulation));
|
||||||
|
doll->_ragdollSimulation = this;
|
||||||
_otherRagdolls.push_back(doll);
|
_otherRagdolls.push_back(doll);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
||||||
int numDolls = _otherRagdolls.size();
|
int numDolls = _otherRagdolls.size();
|
||||||
|
if (doll->_ragdollSimulation != this) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
if (doll == _otherRagdolls[i]) {
|
if (doll == _otherRagdolls[i]) {
|
||||||
if (i == numDolls - 1) {
|
if (i == numDolls - 1) {
|
||||||
|
@ -152,6 +173,7 @@ void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
||||||
_otherRagdolls.pop_back();
|
_otherRagdolls.pop_back();
|
||||||
_otherRagdolls[i] = lastDoll;
|
_otherRagdolls[i] = lastDoll;
|
||||||
}
|
}
|
||||||
|
doll->_ragdollSimulation = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
void setTranslation(const glm::vec3& translation) { _translation = translation; }
|
void setTranslation(const glm::vec3& translation) { _translation = translation; }
|
||||||
const glm::vec3& getTranslation() const { return _translation; }
|
const glm::vec3& getTranslation() const { return _translation; }
|
||||||
|
|
||||||
void setRagdoll(Ragdoll* ragdoll) { _ragdoll = ragdoll; }
|
void setRagdoll(Ragdoll* ragdoll);
|
||||||
void setEntity(PhysicsEntity* entity);
|
void setEntity(PhysicsEntity* entity);
|
||||||
|
|
||||||
/// \return true if entity was added to or is already in the list
|
/// \return true if entity was added to or is already in the list
|
||||||
|
|
Loading…
Reference in a new issue