Browse Source

fixed deletion of unused constraints

master
Otto Naderer 7 years ago
parent
commit
41d9752cc1
  1. 13
      src/irrDynamics.cpp

13
src/irrDynamics.cpp

@ -52,6 +52,8 @@ void irrDynamics::simStep(u32 curTimeStamp)
if (inst->lastStep == 0)
inst->lastStep = curTimeStamp;
// printf("NUMCONST: %i\n", inst->world->getNumConstraints());
inst->world->stepSimulation((curTimeStamp - inst->lastStep) * 0.001f, 5);
inst->updateObjects();
inst->lastStep = curTimeStamp;
@ -271,6 +273,8 @@ bool irrDynamics::createHingeConstraint(scene::ISceneNode* nodeA, scene::ISceneN
btHingeConstraint* constraint = new btHingeConstraint(*(iterA->second), *(iterB->second), btVector3(pivotInA.X, pivotInA.Y, pivotInA.Z), btVector3(pivotInB.X, pivotInB.Y, pivotInB.Z), btVector3(axisInA.X, axisInA.Y, axisInA.Z), btVector3(axisInB.X, axisInB.Y, axisInB.Z));
inst->world->addConstraint(constraint);
iterA->second->addConstraintRef(constraint);
iterB->second->addConstraintRef(constraint);
return true;
}
@ -296,6 +300,8 @@ bool irrDynamics::createPoint2PointConstraint(scene::ISceneNode* nodeA, scene::I
btPoint2PointConstraint* constraint = new btPoint2PointConstraint(*(iterA->second), *(iterB->second), btVector3(pivotInA.X, pivotInA.Y, pivotInA.Z), btVector3(pivotInB.X, pivotInB.Y, pivotInB.Z));
inst->world->addConstraint(constraint);
iterA->second->addConstraintRef(constraint);
iterB->second->addConstraintRef(constraint);
return true;
}
@ -344,6 +350,8 @@ bool irrDynamics::createSliderConstraint(scene::ISceneNode* nodeA,
btSliderConstraint* constraint = new btSliderConstraint(*(iterA->second), *(iterB->second), matA, matB, true);
inst->world->addConstraint(constraint);
iterA->second->addConstraintRef(constraint);
iterB->second->addConstraintRef(constraint);
return true;
}
@ -455,6 +463,7 @@ void irrDynamics::setPosition(scene::ISceneNode* node, const core::vector3df& ne
void irrDynamics::removeConstraints(btRigidBody* rigidBody)
{
const int len = rigidBody->getNumConstraintRefs();
printf("CONSTREF A: %i\n", rigidBody->getNumConstraintRefs());
//first, remove constraint reference at the other node
for (int i = 0; i < len; i++)
{
@ -465,12 +474,14 @@ void irrDynamics::removeConstraints(btRigidBody* rigidBody)
bodyB->removeConstraintRef(constraint);
}
printf("CONSTREF B: %i\n", rigidBody->getNumConstraintRefs());
//then remove/delete at our side
while (rigidBody->getNumConstraintRefs() > 0)
{
btTypedConstraint* constraint = rigidBody->getConstraintRef(0);
world->removeConstraint(constraint);
rigidBody->removeConstraintRef(constraint);
world->removeConstraint(constraint);
delete constraint;
printf("DELETED\n");
}
}

Loading…
Cancel
Save