No, I am not using class ndPhysicsWorld. I made my own class that inherits from ndWorld and does not use the ndThreadBacgroundWorker.
in any case, I added void CollisionUpdate(ndFloat32 timestep);
Sorry, it is still not working for me. It is only working if the engine is running like your demo scenes are. I need to be able to get contact info when the engine is not running too.
Here's what my update function looks like now. The values for the calculated velocity look like this as I drag a body on the ground. Does these seem reasonable?
18.238883 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-1.129153, 0.000000, 1.579649)
18.258926 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.259144 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-0.787382, 0.000000, 1.414289)
18.279462 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.279676 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (0.000000, 0.000000, 0.000000)
18.301337 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.301552 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-0.794220, 0.000000, 1.128731)
18.324850 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.325108 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-0.337064, 0.000000, 0.720785)
- Code: Select all
void NewtonEngine::updatePoseAndScale (RenderableNode& node)
{
ndBodyDynamic* const body = static_cast<ndBodyDynamic*> (node->getUserdata());
if (!body) return;
ndMatrix currentPose;
eigenToNewton (node->getSpaceTime().worldTransform, currentPose);
body->SetMatrix (currentPose);
ndShapeInstance& shape = body->GetCollisionShape();
Eigen::Vector3f s = node->getSpaceTime().scale;
ndVector scale = ndVector (s.x(), s.y(), s.z(), 0.0f);
shape.SetScale (scale);
node->getSpaceTime().startScale = s;
node->getSpaceTime().makeCurrentPoseStartPose();
// body->veloc = (body->posit - desired position) / timestep
Eigen::Vector3f previousSpot = node->getSpaceTime().previousWorldTransform.translation();
Eigen::Vector3f newSpot = node->getSpaceTime().worldTransform.translation();
ndFloat32 timeStep = (1.0f / 60.0f);
Eigen::Vector3f v = (previousSpot - newSpot) / timeStep;
ndVector veloc = ndVector (v.x(), v.y(), v.z(), 0.0f);
body->SetVelocity (veloc);
state->world->CollisionUpdate (timeStep);
}
mean time, can you tell me how you implement your add body function.
where are you making the call from, this will give some idea how to make that modification.
I'm running Newton on a separate thread. When I add a new body I call this function.
- Code: Select all
void NewtonBodyHandler::addBody (RenderableNode& node, PhysicsEngineState engineState)
{
// if the engine is running, bodies have to be added on Newton's thread
engineState == PhysicsEngineState::Running ? pendingAdds.enqueue (node) : addBodyToEngine (node);
}
If the engine is running, I add the body to a thread-safe queue and then add to the engine during the ndWorld::OnPostUpdate
- Code: Select all
void NewtonBodyHandler::onPostUpdate (ndFloat32 timestep)
{
while (pendingAdds.size_approx())
{
RenderableNode node;
bool found = pendingAdds.try_dequeue (node);
if (found)
addBodyToEngine (node);
}
}