feat: Add "simple" inspector to the imgui panels
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include <destrum/Components/Physics/BoxCollider.h>
|
||||
|
||||
#include <destrum/Util/ImGuiUtils.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
nlohmann::json BoxCollider::Serialize() const {
|
||||
auto data = SerializeCollider();
|
||||
data["halfExtents"] = {m_HalfExtents.x, m_HalfExtents.y, m_HalfExtents.z};
|
||||
@@ -17,3 +21,12 @@ void BoxCollider::Deserialize(const nlohmann::json& data) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void BoxCollider::ImGuiInspector() {
|
||||
Collider::ImGuiInspector();
|
||||
|
||||
glm::vec3 halfExtents = m_HalfExtents;
|
||||
if (ImGuiUtils::DrawVec3Control("Half extents", halfExtents)) {
|
||||
SetHalfExtents(halfExtents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <destrum/Components/Physics/CapsuleCollider.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
void CapsuleCollider::ImGuiInspector() {
|
||||
Collider::ImGuiInspector();
|
||||
|
||||
float radius = m_Radius;
|
||||
if (ImGui::DragFloat("Radius", &radius, 0.05f, 0.0001f)) {
|
||||
SetRadius(radius);
|
||||
}
|
||||
|
||||
float height = m_Height;
|
||||
if (ImGui::DragFloat("Height", &height, 0.05f, 0.0001f)) {
|
||||
SetHeight(height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <destrum/Components/Physics/Collider.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include <destrum/Util/ImGuiUtils.h>
|
||||
|
||||
void Collider::ImGuiInspector() {
|
||||
bool isTrigger = m_IsTrigger;
|
||||
if (ImGui::Checkbox("Is trigger", &isTrigger)) {
|
||||
SetTrigger(isTrigger);
|
||||
}
|
||||
|
||||
glm::vec3 centerOffset = m_CenterOffset;
|
||||
if (ImGuiUtils::DrawVec3Control("Center offset", centerOffset)) {
|
||||
SetCenterOffset(centerOffset);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <destrum/ObjectModel/GameObject.h>
|
||||
#include <destrum/Scene/Scene.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] const char* RigidbodyTypeName(RigidbodyType type) {
|
||||
switch (type) {
|
||||
@@ -128,3 +130,48 @@ void Rigidbody::Deserialize(const nlohmann::json& data) {
|
||||
m_AllowSleep = data.at("allowSleep").get<bool>();
|
||||
}
|
||||
}
|
||||
|
||||
void Rigidbody::ImGuiInspector() {
|
||||
static const char* typeNames[] = {"Static", "Dynamic", "Kinematic"};
|
||||
int type = static_cast<int>(m_Type);
|
||||
if (ImGui::Combo("Body type", &type, typeNames, IM_ARRAYSIZE(typeNames))) {
|
||||
SetType(static_cast<RigidbodyType>(type));
|
||||
}
|
||||
|
||||
float mass = m_Mass;
|
||||
if (ImGui::DragFloat("Mass", &mass, 0.1f, 0.0001f)) {
|
||||
SetMass(mass);
|
||||
}
|
||||
|
||||
float friction = m_Friction;
|
||||
if (ImGui::DragFloat("Friction", &friction, 0.01f, 0.0f)) {
|
||||
SetFriction(friction);
|
||||
}
|
||||
|
||||
float restitution = m_Restitution;
|
||||
if (ImGui::SliderFloat("Restitution", &restitution, 0.0f, 1.0f)) {
|
||||
SetRestitution(restitution);
|
||||
}
|
||||
|
||||
bool useGravity = m_UseGravity;
|
||||
if (ImGui::Checkbox("Use gravity", &useGravity)) {
|
||||
SetUseGravity(useGravity);
|
||||
}
|
||||
|
||||
bool allowSleep = m_AllowSleep;
|
||||
if (ImGui::Checkbox("Allow sleep", &allowSleep)) {
|
||||
SetAllowSleep(allowSleep);
|
||||
}
|
||||
|
||||
if (HasPhysicsBody()) {
|
||||
const glm::vec3 velocity = GetLinearVelocity();
|
||||
ImGui::Text(
|
||||
"Linear velocity: %.2f, %.2f, %.2f",
|
||||
velocity.x,
|
||||
velocity.y,
|
||||
velocity.z);
|
||||
ImGui::Text("Physics body: %u", m_Body.id);
|
||||
} else {
|
||||
ImGui::TextDisabled("Physics body: not registered");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <destrum/Components/Physics/SphereCollider.h>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
nlohmann::json SphereCollider::Serialize() const {
|
||||
auto data = SerializeCollider();
|
||||
data["radius"] = m_Radius;
|
||||
@@ -12,3 +14,12 @@ void SphereCollider::Deserialize(const nlohmann::json& data) {
|
||||
SetRadius(data.at("radius").get<float>());
|
||||
}
|
||||
}
|
||||
|
||||
void SphereCollider::ImGuiInspector() {
|
||||
Collider::ImGuiInspector();
|
||||
|
||||
float radius = m_Radius;
|
||||
if (ImGui::DragFloat("Radius", &radius, 0.05f, 0.0001f)) {
|
||||
SetRadius(radius);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user