Added Collision Tag Matrix #296

Merged
srishamharan merged 5 commits from SP3-4-Editor into main 2022-12-27 13:59:49 +08:00
3 changed files with 38 additions and 8 deletions
Showing only changes of commit 37f62fdd24 - Show all commits

View File

@ -13,6 +13,8 @@ namespace SHADE
{
ImGui::BeginTable("CollisionMtxTable", SHCollisionTag::NUM_LAYERS + 1, ImGuiTableRowFlags_Headers);
ImGui::TableNextRow();
ImGui::PushID("CollisionTagNames");
for (int i = SHCollisionTag::NUM_LAYERS; i >= 0; --i)
{
ImGui::TableNextColumn();
@ -22,8 +24,11 @@ namespace SHADE
if (!tag)
continue;
//ImGui::Text(tagName.data());
SHEditorWidgets::InputText("##" + std::to_string(i), [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue);
ImGui::PushID(i);
SHEditorWidgets::InputText("##", [i]{return SHCollisionTagMatrix::GetTagName(i);}, [i](std::string const& value){SHCollisionTagMatrix::GetTag(i)->SetName(value);}, tagName.data(), ImGuiInputTextFlags_EnterReturnsTrue);
ImGui::PopID();
}
ImGui::PopID();
for (int i = 0; i < SHCollisionTag::NUM_LAYERS; ++i)
{
std::string tagName = SHCollisionTagMatrix::GetTagName(i);
@ -50,7 +55,7 @@ namespace SHADE
ImGui::TableNextColumn();
//if(i == idx)
// continue;
std::string_view label = std::format("##{} vs {}", tagName, tagName2).data();
std::string label = std::format("##{} vs {}", tagName, tagName2);
SHEditorWidgets::CheckBox(label, [tag, &idx]{return tag->GetLayerState(idx);}, [tag, i, idx](bool const& value){tag->SetLayerState(idx, value); SHCollisionTagMatrix::GetTag(idx)->SetLayerState(i, value);}, label.substr(2));
}
}

View File

@ -18,7 +18,7 @@
#include "Physics/Interface/SHColliderComponent.h"
#include "Reflection/SHReflectionMetadata.h"
#include "Resource/SHResourceManager.h"
#include "Physics/Collision/SHCollisionTagMatrix.h"
namespace SHADE
{
template<typename T>
@ -314,6 +314,12 @@ namespace SHADE
if (!component)
return;
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHColliderComponent>());
std::vector<const char*> collisionTagNames(SHCollisionTag::NUM_LAYERS);
//Fetch tag names
for(int i{}; i < SHCollisionTag::NUM_LAYERS; ++i)
{
collisionTagNames[i] = SHCollisionTagMatrix::GetTagName(i).c_str();
}
const auto componentType = rttr::type::get(*component);
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
@ -332,7 +338,7 @@ namespace SHADE
SHCollisionShape* collider = &component->GetCollisionShape(i);
auto cursorPos = ImGui::GetCursorPos();
//collider->IsTrigger
if (collider->GetType() == SHCollisionShape::Type::BOX)
{
SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
@ -361,7 +367,7 @@ namespace SHADE
{
SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); });
SHEditorWidgets::ComboBox("Tag", collisionTagNames, [collider]{return SHCollisionTagMatrix::GetTagIndex(collider->GetCollisionTag().GetName());}, [collider](int const& value){collider->SetCollisionTag(SHCollisionTagMatrix::GetTag(value));});
if(ImGui::CollapsingHeader("Physics Material"))
{
SHEditorWidgets::DragFloat("Friction", [collider] { return collider->GetFriction(); }, [collider](float value) { collider->SetFriction(value); }, "Friction", 0.05f, 0.0f, 1.0f);
@ -388,6 +394,7 @@ namespace SHADE
{
colliderToDelete = i;
}
SHEditorWidgets::EndPanel();
ImGui::PopID();
}
@ -399,14 +406,26 @@ namespace SHADE
if (ImGui::BeginMenu("Add Collider"))
{
int newColl = -1;
if (ImGui::Selectable("Box Collider"))
{
component->AddBoundingBox();
newColl = component->AddBoundingBox();
}
if (ImGui::Selectable("Sphere Collider"))
{
component->AddBoundingSphere();
newColl = component->AddBoundingSphere();
}
//No idea why this doesn't work
//if (newColl > 0)
//{
// auto newCollisionShape = component->GetCollisionShape(newColl);
// auto prevCollisionShapeInSeq = component->GetCollisionShape(newColl - 1);
// newCollisionShape.SetCollisionTag(SHCollisionTagMatrix::GetTag(prevCollisionShapeInSeq.GetCollisionTag().GetName()));
//}
ImGui::EndMenu();
}
}

View File

@ -14,6 +14,7 @@
#include "Physics/Interface/SHColliderComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
#include "Physics/Collision/SHCollisionTagMatrix.h"
namespace YAML
{
@ -117,13 +118,14 @@ namespace YAML
static constexpr const char* Density = "Density";
static constexpr const char* PositionOffset = "Position Offset";
static constexpr const char* RotationOffset = "Rotation Offset";
static constexpr const char* CollisionTag = "Collision Tag";
static Node encode(SHCollisionShape& rhs)
{
Node node;
node[IsTrigger] = rhs.IsTrigger();
node[CollisionTag] = rhs.GetCollisionTag().GetName();
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
SHCollisionShape::Type colliderType = rhs.GetType();
@ -160,6 +162,10 @@ namespace YAML
{
if (node[IsTrigger].IsDefined())
rhs.SetIsTrigger(node[IsTrigger].as<bool>());
if(node[CollisionTag].IsDefined())
rhs.SetCollisionTag(SHCollisionTagMatrix::GetTag(node[CollisionTag].as<std::string>()));
if (!node[Type].IsDefined())
return false;
rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();