From 58638389bddf2a0843f1c56ebc3bed65599ae989 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Wed, 17 Oct 2018 18:35:58 +0100 Subject: [PATCH] some physics update --- Editor/Editor.cpp | 13 +++++++++- WickedEngine/wiPhysicsEngine_Bullet.cpp | 31 ++++++++++++++---------- WickedEngine/wiSceneSystem.cpp | 5 +++- WickedEngine/wiSceneSystem.h | 11 +++++++++ WickedEngine/wiVersion.cpp | 2 +- models/physics_test.wiscene | Bin 0 -> 16438 bytes 6 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 models/physics_test.wiscene diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 9abf60362..11cc1d5ed 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -228,7 +228,7 @@ void EditorComponent::Load() Scene& scene = wiRenderer::GetScene(); cinemaModeCheckBox = new wiCheckBox("Cinema Mode: "); - cinemaModeCheckBox->SetSize(XMFLOAT2(20, 20)); + cinemaModeCheckBox->SetSize(XMFLOAT2(18, 18)); cinemaModeCheckBox->SetPos(XMFLOAT2(screenW - 55 - 860 - 120, 0)); cinemaModeCheckBox->SetTooltip("Toggle Cinema Mode (All HUD disabled). Press ESC to exit."); cinemaModeCheckBox->OnClick([&](wiEventArgs args) { @@ -242,6 +242,17 @@ void EditorComponent::Load() }); GetGUI().AddWidget(cinemaModeCheckBox); + wiCheckBox* physicsEnabledCheckBox = new wiCheckBox("Physics Enabled: "); + physicsEnabledCheckBox->SetSize(XMFLOAT2(18, 18)); + physicsEnabledCheckBox->SetPos(XMFLOAT2(screenW - 55 - 860 - 120, 22)); + physicsEnabledCheckBox->SetTooltip("Toggle Physics Engine On/Off"); + physicsEnabledCheckBox->OnClick([&](wiEventArgs args) { + Scene& scene = wiRenderer::GetScene(); + scene.SetPhysicsEnabled(args.bValue); + }); + physicsEnabledCheckBox->SetCheck(wiRenderer::GetScene().IsPhysicsEnabled()); + GetGUI().AddWidget(physicsEnabledCheckBox); + wiComboBox* renderPathComboBox = new wiComboBox("Render Path: "); renderPathComboBox->SetSize(XMFLOAT2(100, 20)); diff --git a/WickedEngine/wiPhysicsEngine_Bullet.cpp b/WickedEngine/wiPhysicsEngine_Bullet.cpp index c7d26d79e..ca50281c3 100644 --- a/WickedEngine/wiPhysicsEngine_Bullet.cpp +++ b/WickedEngine/wiPhysicsEngine_Bullet.cpp @@ -21,7 +21,7 @@ using namespace wiSceneSystem; namespace wiPhysicsEngine { - btVector3 gravity(0, -110, 0); + btVector3 gravity(0, -10, 0); int softbodyIterationCount = 5; btCollisionConfiguration* collisionConfiguration = nullptr; btCollisionDispatcher* dispatcher = nullptr; @@ -39,17 +39,18 @@ namespace wiPhysicsEngine void Initialize() { // collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. - collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); + collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration; // use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) dispatcher = new btCollisionDispatcher(collisionConfiguration); // btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. - overlappingPairCache = new btDbvtBroadphase(); + overlappingPairCache = new btDbvtBroadphase; // the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) solver = new btSequentialImpulseConstraintSolver; + //dynamicsWorld = new btSimpleDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); //dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration); dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration, softBodySolver); @@ -59,12 +60,14 @@ namespace wiPhysicsEngine dynamicsWorld->setGravity(gravity); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().air_density = (btScalar)0.0; - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().water_density = 0; - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().water_offset = 0; - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().water_normal = btVector3(0, 0, 0); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().m_gravity.setValue(gravity.x(), gravity.y(), gravity.z()); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().m_sparsesdf.Initialize(); + btSoftRigidDynamicsWorld* softRigidWorld = (btSoftRigidDynamicsWorld*)dynamicsWorld; + btSoftBodyWorldInfo& softWorldInfo = softRigidWorld->getWorldInfo(); + softWorldInfo.air_density = (btScalar)0.0; + softWorldInfo.water_density = 0; + softWorldInfo.water_offset = 0; + softWorldInfo.water_normal = btVector3(0, 0, 0); + softWorldInfo.m_gravity.setValue(gravity.x(), gravity.y(), gravity.z()); + softWorldInfo.m_sparsesdf.Initialize(); } void CleanUp() @@ -114,7 +117,7 @@ namespace wiPhysicsEngine switch (physicscomponent.shape) { case RigidBodyPhysicsComponent::CollisionShape::BOX: - shape = new btBoxShape(S * 0.5f); + shape = new btBoxShape(S); break; case RigidBodyPhysicsComponent::CollisionShape::SPHERE: @@ -176,9 +179,10 @@ namespace wiPhysicsEngine if (shape != nullptr) { - shape->setMargin(btScalar(0.01)); + // Use default margin for now + //shape->setMargin(btScalar(0.01)); - btScalar mass(physicscomponent.mass); + btScalar mass = physicscomponent.mass; bool isDynamic = (mass != 0.f && !physicscomponent.IsKinematic()); @@ -455,7 +459,8 @@ namespace wiPhysicsEngine } } - dynamicsWorld->stepSimulation(dt, 10); + // Scale dt, otherwise simulation is just too slow (todo: review) + dynamicsWorld->stepSimulation(dt * 60, 10); wiProfiler::GetInstance().EndRange(); // Physics } diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 90f5c1808..b594545bb 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -835,7 +835,10 @@ namespace wiSceneSystem RunAnimationUpdateSystem(animations, transforms, dt); - wiPhysicsEngine::RunPhysicsUpdateSystem(weather, transforms, meshes, objects, rigidbodies, softbodies, dt); + if (IsPhysicsEnabled()) + { + wiPhysicsEngine::RunPhysicsUpdateSystem(weather, transforms, meshes, objects, rigidbodies, softbodies, dt); + } RunTransformUpdateSystem(transforms); diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 9fe4a4721..f93933ba8 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -894,6 +894,17 @@ namespace wiSceneSystem XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); WeatherComponent weather; + enum FLAGS + { + EMPTY = 0, + PHYSICS_ENABLED = 1 << 0, + }; + uint32_t _flags = PHYSICS_ENABLED; + + inline void SetPhysicsEnabled(bool value) { if (value) { _flags |= PHYSICS_ENABLED; } else { _flags &= ~PHYSICS_ENABLED; } } + + inline bool IsPhysicsEnabled() const { return _flags & PHYSICS_ENABLED; } + // Update all components by a given timestep (in seconds): void Update(float dt); // Remove everything from the scene that it owns: diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 41e6db95b..fea4d1683 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 21; // minor bug fixes, alterations, refactors, updates - const int revision = 10; + const int revision = 11; long GetVersion() diff --git a/models/physics_test.wiscene b/models/physics_test.wiscene new file mode 100644 index 0000000000000000000000000000000000000000..0c573fdbe140982f75904b6181a0f28850220bc2 GIT binary patch literal 16438 zcmeHO3v^Z0nZEK0g1nKpJfwyo5Q7Q`lC$p#C~rYau|bf4Nel>vN3aMew}Mcy%34Yv zA}ZozIkhutrK8QrJ=XvOUE(ZV6%{KC4$!75f>SGnx`z3`ef}@m_n1r2E|zxIoV8BA z|Nr*C|JUB<+(+)|5DSma5$vM+#DcM7=FKl(STUoxq;%%uxfK&;R+KE9J#%iXwOUM? zJM-3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