diff --git a/Engine/include/Components/PhysicsMeshComponent.h b/Engine/include/Components/PhysicsMeshComponent.h index 3e0dd5a..3409ead 100644 --- a/Engine/include/Components/PhysicsMeshComponent.h +++ b/Engine/include/Components/PhysicsMeshComponent.h @@ -80,7 +80,6 @@ namespace Prisma private: ComponentList m_status; - ComponentList m_statusBend; std::function m_apply; std::function m_applySoft; Physics::CollisionData m_collisionData{}; diff --git a/Engine/include/Physics/Physics.h b/Engine/include/Physics/Physics.h index e40d437..9f46a77 100644 --- a/Engine/include/Physics/Physics.h +++ b/Engine/include/Physics/Physics.h @@ -35,11 +35,10 @@ namespace Prisma struct SoftBodySettings { - float gravity = 1.0f; + int numIteration = 1.0f; bool sleep = false; bool updatePosition = false; - JPH::SoftBodySharedSettings::VertexAttributes vertexAttributes = {1, 1, 1}; - JPH::SoftBodySharedSettings::EBendType bendType = JPH::SoftBodySharedSettings::EBendType::None; + JPH::SoftBodySharedSettings::VertexAttributes vertexAttributes = {1.0e-5f, 1.0e-5f, 1.0e-5f}; }; struct LandscapeData diff --git a/Engine/src/Components/PhysicsMeshComponent.cpp b/Engine/src/Components/PhysicsMeshComponent.cpp index c070088..4afd4b4 100644 --- a/Engine/src/Components/PhysicsMeshComponent.cpp +++ b/Engine/src/Components/PhysicsMeshComponent.cpp @@ -17,21 +17,10 @@ void Prisma::PhysicsMeshComponent::ui() m_status.items.push_back("LANDSCAPE COLLIDER"); m_status.items.push_back("CONVEX COLLIDER"); componentType = std::make_tuple(TYPES::STRINGLIST, "Collider", &m_status); - ComponentType componentMass; componentMass = std::make_tuple(TYPES::FLOAT, "Mass", &m_collisionData.mass); - - ComponentType componentGravity; - componentGravity = std::make_tuple(TYPES::FLOAT, "Gravity", &m_settingsSoft.gravity); - - m_statusBend.currentitem = static_cast(m_settingsSoft.bendType); - m_statusBend.items.push_back("NONE"); - m_statusBend.items.push_back("DISTANCE"); - m_statusBend.items.push_back("DIHEDRAL"); - - ComponentType componentBend; - componentBend = std::make_tuple(TYPES::STRINGLIST, "Bend", &m_statusBend); - + ComponentType componentIteration; + componentIteration = std::make_tuple(TYPES::INT, "Iteration", &m_settingsSoft.numIteration); ComponentType componentDynamic; componentDynamic = std::make_tuple(TYPES::BOOL, "Dynamic", &m_collisionData.dynamic); @@ -60,9 +49,7 @@ void Prisma::PhysicsMeshComponent::ui() addGlobal(componentMass); - addGlobal(componentGravity); - - addGlobal(componentBend); + addGlobal(componentIteration); addGlobal(componentDynamic); @@ -238,9 +225,19 @@ BodyCreationSettings Prisma::PhysicsMeshComponent::getBodySettings() case Physics::Collider::BOX_COLLIDER: { auto length = glm::abs((aabbData.max - aabbData.min) * 0.5f); - if (length.x < m_minScale || length.y < m_minScale || length.z < m_minScale) + if (length.x < m_minScale) + { + length.x = 1; + } + + if (length.y < m_minScale) + { + length.y = 1; + } + + if (length.z < m_minScale) { - length = glm::vec3(1, 1, 1); + length.z = 1; } auto boxShape = new BoxShape(JtoVec3(length)); auto result = boxShape->ScaleShape(JtoVec3(scale)); @@ -339,7 +336,7 @@ void Prisma::PhysicsMeshComponent::addSoftBody() mesh->verticesData().indices[i + 2])); } - m_softBodySharedSettings->CreateConstraints(&m_settingsSoft.vertexAttributes, 1, m_settingsSoft.bendType); + m_softBodySharedSettings->CreateConstraints(&m_settingsSoft.vertexAttributes, 1); m_softBodySharedSettings->Optimize(); @@ -348,9 +345,9 @@ void Prisma::PhysicsMeshComponent::addSoftBody() m_collisionData.dynamic ? Layers::MOVING : Layers::NON_MOVING); - sb_settings.mGravityFactor = m_settingsSoft.gravity; sb_settings.mAllowSleeping = m_settingsSoft.sleep; sb_settings.mUpdatePosition = m_settingsSoft.updatePosition; + sb_settings.mNumIterations = m_settingsSoft.numIteration; m_physicsSoftId = Physics::getInstance().bodyInterface().CreateSoftBody(sb_settings); Physics::getInstance().bodyInterface().AddBody(m_physicsSoftId->GetID(), diff --git a/UserEngine/src/PlayerController.cpp b/UserEngine/src/PlayerController.cpp index 2d98503..40b00e7 100644 --- a/UserEngine/src/PlayerController.cpp +++ b/UserEngine/src/PlayerController.cpp @@ -65,16 +65,6 @@ PlayerController::PlayerController(std::shared_ptr scene) : m_sce terrain->addComponent(terrainComponent); m_scene->root->addChild(terrain);*/ - - auto plane = std::dynamic_pointer_cast(nodeHelper.find(m_scene->root, "Cube.004")); - - if (plane) - { - auto physicsComponent = std::dynamic_pointer_cast(plane->components()["Physics"]); - physicsComponent->settingsSoftBody({0, false, false, {1, 1, 1}, SoftBodySharedSettings::EBendType::Dihedral}); - physicsComponent->collisionData({Prisma::Physics::Collider::BOX_COLLIDER, 0.0, true, true}); - } - auto contact = [&](const Body& body) { m_isColliding = true;