99 lines
2.9 KiB
C++
99 lines
2.9 KiB
C++
#include "stdafx.h"
|
|
#include "SoftBodyWindow.h"
|
|
#include "Editor.h"
|
|
|
|
using namespace wi::ecs;
|
|
using namespace wi::scene;
|
|
|
|
void SoftBodyWindow::Create(EditorComponent* _editor)
|
|
{
|
|
editor = _editor;
|
|
wi::gui::Window::Create(ICON_SOFTBODY " Soft Body Physics", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE);
|
|
SetSize(XMFLOAT2(580, 120));
|
|
|
|
closeButton.SetTooltip("Delete MeshComponent");
|
|
OnClose([=](wi::gui::EventArgs args) {
|
|
|
|
wi::Archive& archive = editor->AdvanceHistory();
|
|
archive << EditorComponent::HISTORYOP_COMPONENT_DATA;
|
|
editor->RecordEntity(archive, entity);
|
|
|
|
editor->GetCurrentScene().softbodies.Remove(entity);
|
|
|
|
editor->RecordEntity(archive, entity);
|
|
|
|
editor->optionsWnd.RefreshEntityTree();
|
|
});
|
|
|
|
float x = 95;
|
|
float y = 0;
|
|
float hei = 18;
|
|
float step = hei + 2;
|
|
float wid = 170;
|
|
|
|
massSlider.Create(0, 10, 1, 100000, "Mass: ");
|
|
massSlider.SetTooltip("Set the mass amount for the physics engine.");
|
|
massSlider.SetSize(XMFLOAT2(wid, hei));
|
|
massSlider.SetPos(XMFLOAT2(x, y));
|
|
massSlider.OnSlide([&](wi::gui::EventArgs args) {
|
|
SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
|
|
if (physicscomponent != nullptr)
|
|
{
|
|
physicscomponent->physicsobject = {};
|
|
physicscomponent->mass = args.fValue;
|
|
}
|
|
});
|
|
AddWidget(&massSlider);
|
|
|
|
frictionSlider.Create(0, 1, 0.5f, 100000, "Friction: ");
|
|
frictionSlider.SetTooltip("Set the friction amount for the physics engine.");
|
|
frictionSlider.SetSize(XMFLOAT2(wid, hei));
|
|
frictionSlider.SetPos(XMFLOAT2(x, y += step));
|
|
frictionSlider.OnSlide([&](wi::gui::EventArgs args) {
|
|
SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
|
|
if (physicscomponent != nullptr)
|
|
{
|
|
physicscomponent->physicsobject = {};
|
|
physicscomponent->friction = args.fValue;
|
|
}
|
|
});
|
|
AddWidget(&frictionSlider);
|
|
|
|
restitutionSlider.Create(0, 1, 0, 100000, "Restitution: ");
|
|
restitutionSlider.SetTooltip("Set the restitution amount for the physics engine.");
|
|
restitutionSlider.SetSize(XMFLOAT2(wid, hei));
|
|
restitutionSlider.SetPos(XMFLOAT2(x, y += step));
|
|
restitutionSlider.OnSlide([&](wi::gui::EventArgs args) {
|
|
SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
|
|
if (physicscomponent != nullptr)
|
|
{
|
|
physicscomponent->physicsobject = {};
|
|
physicscomponent->restitution = args.fValue;
|
|
}
|
|
});
|
|
AddWidget(&restitutionSlider);
|
|
|
|
|
|
|
|
SetMinimized(true);
|
|
SetVisible(false);
|
|
|
|
SetEntity(INVALID_ENTITY);
|
|
}
|
|
|
|
|
|
void SoftBodyWindow::SetEntity(Entity entity)
|
|
{
|
|
this->entity = entity;
|
|
|
|
Scene& scene = editor->GetCurrentScene();
|
|
|
|
const SoftBodyPhysicsComponent* physicscomponent = scene.softbodies.GetComponent(entity);
|
|
if (physicscomponent != nullptr)
|
|
{
|
|
massSlider.SetValue(physicscomponent->mass);
|
|
frictionSlider.SetValue(physicscomponent->friction);
|
|
restitutionSlider.SetValue(physicscomponent->restitution);
|
|
}
|
|
}
|