remove old transform and velocity components and replace with new decomposed components

focus on 2D for now
This commit is contained in:
2022-01-04 22:33:59 +01:00
parent c36fa30cbc
commit 12b0a90ad0
71 changed files with 1114 additions and 528 deletions

View File

@ -4,7 +4,8 @@
#include "./entity.hpp"
#include <mm/components/transform2d.hpp>
#include <mm/components/position2d.hpp>
#include <mm/components/position3d.hpp>
#include <entt/entity/registry.hpp>
@ -37,10 +38,12 @@ void Camera3D(MM::Scene& scene) {
MM::ImGuiWidgets::Entity(tracking, scene);
if (scene.valid(tracking)) {
if (scene.all_of<MM::Components::Transform2D>(tracking)) {
camera->translation = {scene.get<MM::Components::Transform2D>(tracking).position, 0.f};
if (scene.all_of<MM::Components::Position2D>(tracking)) {
camera->translation = {scene.get<MM::Components::Position2D>(tracking).pos, 0.f};
} else if (scene.all_of<MM::Components::Position3D>(tracking)) { // "3d" fallback
camera->translation = scene.get<MM::Components::Position3D>(tracking).pos;
} else {
ImGui::TextUnformatted("error: Entity has no Transform");
ImGui::TextUnformatted("error: Entity has neither Position2D nor Position3D");
}
}
} else {

View File

@ -0,0 +1,21 @@
#include "./position2d.hpp"
#include <imgui/imgui.h>
namespace MM::ImGuiWidgets::Components {
void Position(MM::Components::Position2D& p) {
ImGui::DragFloat2("position (x,y)##Position2D", &p.pos.x, 0.1f);
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Position2D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Position(reg.get<Components::Position2D>(e));
}
} // MM

View File

@ -1,15 +1,15 @@
#pragma once
#include <mm/components/velocity2d.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
#include <mm/components/position2d.hpp>
#include <mm/services/scene_service_interface.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
namespace MM::ImGuiWidgets::Components {
void Velocity(MM::Components::Velocity2D& v);
void Position(MM::Components::Position2D& p);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Velocity2D>(MM::Scene& reg, MM::Entity e);
void ComponentEditorWidget<Components::Position2D>(MM::Scene& reg, MM::Entity e);
}

View File

@ -0,0 +1,21 @@
#include "./position2d_zoffset.hpp"
#include <imgui/imgui.h>
namespace MM::ImGuiWidgets::Components {
void Position_ZOffset(MM::Components::Position2D_ZOffset& z) {
ImGui::SliderFloat("zoffset##Position2D_ZOffset", &z.z_offset, 0.f, 1000.f); // TODO: this depends on the camera far and near plane... somewhat
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Position2D_ZOffset>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Position_ZOffset(reg.get<Components::Position2D_ZOffset>(e));
}
} // MM

View File

@ -0,0 +1,15 @@
#pragma once
#include <mm/components/position2d_zoffset.hpp>
#include <mm/services/scene_service_interface.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
namespace MM::ImGuiWidgets::Components {
void Position_ZOffset(MM::Components::Position2D_ZOffset& t);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Position2D_ZOffset>(MM::Scene& reg, MM::Entity e);
}

View File

@ -0,0 +1,26 @@
#include "./position3d.hpp"
#include <imgui/imgui.h>
//#include <glm/gtc/constants.hpp>
namespace MM::ImGuiWidgets::Components {
void Transform(MM::Components::Position3D& p) {
//ImGui::DragFloat3("position (x,y,z)##Transform3D", &t.position.x, 0.1f);
ImGui::DragFloat3("position (x,y,z)##Position3D", &p.pos.x, 0.1f);
//ImGui::SliderFloat("rotation##Transform3D", &t.rotation, 0.f, glm::pi<float>() * 2.f);
//ImGui::DragFloat3("scale (x,y,z)##Transform3D", &t.scale.x, 1.f, 0.f);
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Position3D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Transform(reg.get<Components::Position3D>(e));
}
} // MM

View File

@ -1,15 +1,15 @@
#pragma once
#include <mm/components/transform2d.hpp>
#include <mm/services/scene_service_interface.hpp>
#include <mm/components/position3d.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
#include <mm/services/scene_service_interface.hpp>
namespace MM::ImGuiWidgets::Components {
void Transform(MM::Components::Transform2D& t);
void Transform(MM::Components::Position3D& p);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Transform2D>(MM::Scene& reg, MM::Entity e);
void ComponentEditorWidget<Components::Position3D>(MM::Scene& reg, MM::Entity e);
}

View File

@ -0,0 +1,23 @@
#include "./rotation2d.hpp"
#include <imgui/imgui.h>
#include <glm/gtc/constants.hpp>
namespace MM::ImGuiWidgets::Components {
void Rotation(MM::Components::Rotation2D& r) {
ImGui::SliderFloat("rotation##Rotation2D", &r.rot, 0.f, glm::two_pi<float>());
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Rotation2D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Rotation(reg.get<Components::Rotation2D>(e));
}
} // MM

View File

@ -1,15 +1,15 @@
#pragma once
#include <mm/components/transform3d.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
#include <mm/components/rotation2d.hpp>
#include <mm/services/scene_service_interface.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
namespace MM::ImGuiWidgets::Components {
void Transform(MM::Components::Transform3D& t);
void Rotation(MM::Components::Rotation2D& r);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Transform3D>(MM::Scene& reg, MM::Entity e);
void ComponentEditorWidget<Components::Rotation2D>(MM::Scene& reg, MM::Entity e);
}

View File

@ -0,0 +1,21 @@
#include "./scale2d.hpp"
#include <imgui/imgui.h>
namespace MM::ImGuiWidgets::Components {
void Scale(MM::Components::Scale2D& s) {
ImGui::DragFloat2("scale (x,y)##Scale2D", &s.scale.x, 0.01f);
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Scale2D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Scale(reg.get<Components::Scale2D>(e));
}
} // MM

View File

@ -0,0 +1,15 @@
#pragma once
#include <mm/components/scale2d.hpp>
#include <mm/services/scene_service_interface.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
namespace MM::ImGuiWidgets::Components {
void Scale(MM::Components::Scale2D& s);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Scale2D>(MM::Scene& reg, MM::Entity e);
}

View File

@ -9,8 +9,6 @@
namespace MM::ImGuiWidgets::Components {
void TilemapRenderable(MM::OpenGL::TilemapRenderable& tm_r) {
ImGui::InputFloat("z", &tm_r.z);
for (size_t i = 0; i < tm_r.sprite_layer.size(); i++) {
ImGui::Separator();
std::string label = "sprite_sheet##";
@ -19,7 +17,7 @@ void TilemapRenderable(MM::OpenGL::TilemapRenderable& tm_r) {
}
}
}
} // MM::ImGuiWidgets::Components
namespace MM {

View File

@ -1,25 +0,0 @@
#include "./transform2d.hpp"
#include <imgui/imgui.h>
#include <glm/gtc/constants.hpp>
namespace MM::ImGuiWidgets::Components {
void Transform(MM::Components::Transform2D& t) {
ImGui::DragFloat2("position (x,y)##Transform", &t.position.x, 0.1f);
ImGui::SliderFloat("rotation##Transform", &t.rotation, 0.f, glm::pi<float>() * 2.f);
ImGui::DragFloat2("scale (x,y)##Transform", &t.scale.x, 1.f, 0.f);
}
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Transform2D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Transform(reg.get<Components::Transform2D>(e));
}
} // MM

View File

@ -1,25 +0,0 @@
#include "./transform3d.hpp"
#include <imgui/imgui.h>
#include <glm/gtc/constants.hpp>
namespace MM::ImGuiWidgets::Components {
void Transform(MM::Components::Transform3D& t) {
ImGui::DragFloat3("position (x,y,z)##Transform3D", &t.position.x, 0.1f);
ImGui::SliderFloat("rotation##Transform3D", &t.rotation, 0.f, glm::pi<float>() * 2.f);
ImGui::DragFloat3("scale (x,y,z)##Transform3D", &t.scale.x, 1.f, 0.f);
}
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Transform3D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Transform(reg.get<Components::Transform3D>(e));
}
} // MM

View File

@ -1,24 +0,0 @@
#include "./velocity2d.hpp"
#include <imgui/imgui.h>
#include <glm/gtc/constants.hpp>
namespace MM::ImGuiWidgets::Components {
void Velocity(MM::Components::Velocity2D& v) {
ImGui::DragFloat2("velocity (x,y)##Velocity", &v.velocity.x, 0.1f);
ImGui::SliderFloat("rotation##Velocity", &v.rotation, -glm::two_pi<float>(), glm::two_pi<float>());
}
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Velocity2D>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::Velocity(reg.get<Components::Velocity2D>(e));
}
} // MM

View File

@ -0,0 +1,21 @@
#include "./velocity2d_position.hpp"
#include <imgui/imgui.h>
namespace MM::ImGuiWidgets::Components {
void VelocityPosition(MM::Components::Velocity2DPosition& v) {
ImGui::DragFloat2("velocity (x,y)##Velocity2DPosition", &v.pos_vel.x, 0.1f);
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Velocity2DPosition>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::VelocityPosition(reg.get<Components::Velocity2DPosition>(e));
}
} // MM

View File

@ -0,0 +1,15 @@
#pragma once
#include <mm/components/velocity2d_position.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
#include <mm/services/scene_service_interface.hpp>
namespace MM::ImGuiWidgets::Components {
void VelocityPosition(MM::Components::Velocity2DPosition& v);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Velocity2DPosition>(MM::Scene& reg, MM::Entity e);
}

View File

@ -0,0 +1,21 @@
#include "./velocity2d_rotation.hpp"
#include <imgui/imgui.h>
namespace MM::ImGuiWidgets::Components {
void VelocityRotation(MM::Components::Velocity2DRotation& v) {
ImGui::DragFloat("rotation##Velocity2DRotation", &v.rot_vel);
}
} // MM::ImGuiWidgets::Components
namespace MM {
template <>
void ComponentEditorWidget<Components::Velocity2DRotation>(MM::Scene& reg, MM::Entity e) {
ImGuiWidgets::Components::VelocityRotation(reg.get<Components::Velocity2DRotation>(e));
}
} // MM

View File

@ -0,0 +1,15 @@
#pragma once
#include <mm/components/velocity2d_rotation.hpp>
#include <mm/imgui/imgui_entt_entity_editor.hpp>
#include <mm/services/scene_service_interface.hpp>
namespace MM::ImGuiWidgets::Components {
void VelocityRotation(MM::Components::Velocity2DRotation& v);
}
namespace MM {
template <>
void ComponentEditorWidget<Components::Velocity2DRotation>(MM::Scene& reg, MM::Entity e);
}

View File

@ -1,8 +1,5 @@
#include "./scene_tools.hpp"
//#include <mm/services/opengl_renderer.hpp>
//#include <mm/resource_manager.hpp>
#include "mm/components/velocity2d_rotation.hpp"
#include <mm/engine.hpp>
@ -10,18 +7,18 @@
#include <imgui/imgui.h>
#include <mm/components/name.hpp>
#include <mm/components/transform2d.hpp>
#include <mm/components/velocity2d.hpp>
#include <mm/components/time_delta.hpp>
//#include <mm/imgui/widgets/texture_resource_manager.hpp>
#include <mm/imgui/widgets/entity.hpp>
#include <mm/imgui/widgets/components/name.hpp>
#include <mm/imgui/widgets/components/transform2d.hpp>
#include <mm/imgui/widgets/components/transform3d.hpp>
#include <mm/imgui/widgets/components/velocity2d.hpp>
#include <mm/imgui/widgets/components/position2d.hpp>
#include <mm/imgui/widgets/components/position2d_zoffset.hpp>
#include <mm/imgui/widgets/components/position3d.hpp>
#include <mm/imgui/widgets/components/rotation2d.hpp>
#include <mm/imgui/widgets/components/scale2d.hpp>
#include <mm/imgui/widgets/components/velocity2d_position.hpp>
#include <mm/imgui/widgets/components/velocity2d_rotation.hpp>
#include <mm/imgui/widgets/components/view_dir2d.hpp>
#include <mm/imgui/widgets/components/view_dir3d.hpp>
#include <mm/imgui/widgets/components/color.hpp>
@ -29,9 +26,6 @@
#include <mm/imgui/widgets/camera.hpp>
//#include <mm/imgui/widgets/filesystem.hpp>
//#include <mm/services/filesystem.hpp>
#include <mm/logger.hpp>
#define LOGIGS(x) LOG("ImGuiSceneToolsService", x)
@ -48,9 +42,13 @@ namespace MM::Services {
_entity_editor.show_window = false;
_entity_editor.registerComponent<MM::Components::Name>("Name");
_entity_editor.registerComponent<MM::Components::Transform2D>("Transform2D");
_entity_editor.registerComponent<MM::Components::Transform3D>("Transform3D");
_entity_editor.registerComponent<MM::Components::Velocity2D>("Velocity2D");
_entity_editor.registerComponent<MM::Components::Position2D>("Position2D");
_entity_editor.registerComponent<MM::Components::Position2D_ZOffset>("Position2D_ZOffset");
_entity_editor.registerComponent<MM::Components::Position3D>("Position3D");
_entity_editor.registerComponent<MM::Components::Rotation2D>("Rotation2D");
_entity_editor.registerComponent<MM::Components::Scale2D>("Scale2D");
_entity_editor.registerComponent<MM::Components::Velocity2DPosition>("Velocity2DPosition");
_entity_editor.registerComponent<MM::Components::Velocity2DRotation>("Velocity2DRotation");
_entity_editor.registerComponent<MM::Components::ViewDir2D>("ViewDir2D");
_entity_editor.registerComponent<MM::Components::ViewDir3D>("ViewDir3D");
_entity_editor.registerComponent<MM::Components::Color>("Color");