some physics update

This commit is contained in:
turanszkij
2018-10-17 18:35:58 +01:00
parent b4074558e3
commit 58638389bd
6 changed files with 46 additions and 16 deletions
+12 -1
View File
@@ -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));
+18 -13
View File
@@ -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
}
+4 -1
View File
@@ -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);
+11
View File
@@ -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:
+1 -1
View File
@@ -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()
Binary file not shown.