diff --git a/examples/PhysicsPlayground/main.cpp b/examples/PhysicsPlayground/main.cpp index dd6218403..90451d989 100644 --- a/examples/PhysicsPlayground/main.cpp +++ b/examples/PhysicsPlayground/main.cpp @@ -272,7 +272,11 @@ int main() NazaraSlot(Nz::WindowEventHandler, OnMouseMoved, cameraMove); NazaraSlot(Nz::WindowEventHandler, OnMouseMoved, grabbedObjectMove); - //std::optional grabConstraint; +#if USE_JOLT + std::optional grabConstraint; +#else + std::optional grabConstraint; +#endif auto mouseMoveCallback = [&](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent& event) { @@ -299,21 +303,20 @@ int main() Nz::Vector3f from = cameraComponent.Unproject({ float(event.x), float(event.y), 0.f }); Nz::Vector3f to = cameraComponent.Unproject({ float(event.x), float(event.y), 1.f }); +#if USE_JOLT Nz::JoltPhysics3DSystem::RaycastHit lastHitInfo; - auto callback = [&](const Nz::JoltPhysics3DSystem::RaycastHit& hitInfo) -> std::optional +#else + Nz::BulletPhysics3DSystem::RaycastHit lastHitInfo; +#endif + auto callback = [&](const decltype(lastHitInfo)& hitInfo) -> std::optional { if (hitInfo.hitEntity == boxEntity) { Nz::Vector3f dirToCenter = Nz::Vector3f::Zero() - hitInfo.hitPosition; dirToCenter.Normalize(); -#ifdef USE_JOLT - if (Nz::Vector3f::DotProduct(dirToCenter, (hitInfo.hitPosition - from).Normalize()) < 0.f) - return std::nullopt; -#else if (Nz::Vector3f::DotProduct(dirToCenter, hitInfo.hitNormal) < 0.f) return std::nullopt; -#endif } lastHitInfo = hitInfo; @@ -325,7 +328,7 @@ int main() { if (lastHitInfo.hitBody && lastHitInfo.hitEntity != boxEntity) { - //grabConstraint.emplace(*lastHitInfo.hitBody, lastHitInfo.hitPosition); + grabConstraint.emplace(*lastHitInfo.hitBody, lastHitInfo.hitPosition); //grabConstraint->SetImpulseClamp(30.f); grabbedObjectMove.Connect(eventHandler.OnMouseMoved, [&, body = lastHitInfo.hitBody, distance = Nz::Vector3f::Distance(from, lastHitInfo.hitPosition)](const Nz::WindowEventHandler*, const Nz::WindowEvent::MouseMoveEvent& event) @@ -334,7 +337,7 @@ int main() Nz::Vector3f to = cameraComponent.Unproject({ float(event.x), float(event.y), 1.f }); Nz::Vector3f newPosition = from + (to - from).Normalize() * distance; - //grabConstraint->SetSecondAnchor(newPosition); + grabConstraint->SetSecondAnchor(newPosition); }); } else @@ -349,7 +352,7 @@ int main() { if (event.button == Nz::Mouse::Left) { - //grabConstraint.reset(); + grabConstraint.reset(); cameraMove.Disconnect(); grabbedObjectMove.Disconnect(); }