bool PhysicsManager::doUpdate(double dt) { // Add all components that came in before the last update processComponents(); processBehaviors(dt); auto state = std::make_shared<PhysicsManagerState>(); std::list<std::shared_ptr<PhysicsManagerState>> stateList(1, state); state->setRepresentations(m_representations); state->setCollisionRepresentations(m_collisionRepresentations); state->setConstraintComponents(m_constraintComponents); { boost::mutex::scoped_lock lock(m_excludedCollisionPairMutex); state->setExcludedCollisionPairs(m_excludedCollisionPairs); } for (const auto& computation : m_computations) { stateList.push_back(computation->update(dt, stateList.back())); } m_finalState.set(*(stateList.back())); return true; }
TEST(DcdCollisionTest, RigidRigidCollisionTest) { auto sphere1 = std::make_shared<Blocks::SphereElement>("Sphere1"); auto sphere2 = std::make_shared<Blocks::SphereElement>("Sphere2"); sphere2->setPose(Math::makeRigidTransform(Math::Quaterniond::Identity(), Vector3d(0.0, 0.0, 0.5))); auto runtime = std::make_shared<Framework::Runtime>(); auto scene = runtime->getScene(); scene->addSceneElement(sphere1); scene->addSceneElement(sphere2); std::vector<std::shared_ptr<Physics::Representation>> physicsRepresentations; physicsRepresentations.push_back(sphere1->getComponents<Physics::Representation>()[0]); physicsRepresentations.push_back(sphere2->getComponents<Physics::Representation>()[0]); auto sphere1Collision = sphere1->getComponents<Collision::Representation>()[0]; auto sphere2Collision = sphere2->getComponents<Collision::Representation>()[0]; sphere1Collision->update(0.0); sphere2Collision->update(0.0); std::vector<std::shared_ptr<Collision::Representation>> collisionRepresentations; collisionRepresentations.push_back(sphere1Collision); collisionRepresentations.push_back(sphere2Collision); auto prepareState = std::make_shared<PrepareCollisionPairs>(false); auto stateTmp = std::make_shared<PhysicsManagerState>(); stateTmp->setRepresentations(physicsRepresentations); stateTmp->setCollisionRepresentations(collisionRepresentations); auto state = prepareState->update(0.0, stateTmp); // This step prepares the collision pairs ASSERT_EQ(1u, state->getCollisionPairs().size()); auto dcdCollision = std::make_shared<DcdCollision>(false); std::shared_ptr<PhysicsManagerState> newState = dcdCollision->update(1.0, state); EXPECT_TRUE(newState->getCollisionPairs().at(0)->hasContacts()); }