pretty property panel components
This commit is contained in:
@@ -5,13 +5,20 @@
|
||||
#include "open_engine/scene/scene_camera.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/fwd.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui.h>
|
||||
#include <string>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value = 0.0f, float column_width = 100.0f,
|
||||
const std::array<const char*, 3> labels = {"x", "y", "z"});
|
||||
|
||||
struct TagComponent
|
||||
{
|
||||
std::string tag;
|
||||
@@ -36,19 +43,33 @@ namespace OpenEngine {
|
||||
|
||||
struct TransformComponent
|
||||
{
|
||||
glm::mat4 transform{ 1.0f };
|
||||
glm::vec3 translation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 scale = { 1.0f, 1.0f, 1.0f };
|
||||
|
||||
TransformComponent() = default;
|
||||
TransformComponent(const TransformComponent&) = default;
|
||||
TransformComponent(const glm::mat4& transform_mat)
|
||||
: transform(transform_mat) {}
|
||||
TransformComponent(const glm::vec3& position)
|
||||
: translation(position) {}
|
||||
|
||||
operator glm::mat4() { return transform; };
|
||||
operator const glm::mat4() const { return transform; };
|
||||
glm::mat4 GetTransform() const
|
||||
{
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation);
|
||||
|
||||
transform *= glm::rotate(glm::mat4(1.0f), rotation.x, { 1, 0, 0 })
|
||||
* glm::rotate(glm::mat4(1.0f), rotation.y, { 0, 1, 0 })
|
||||
* glm::rotate(glm::mat4(1.0f), rotation.z, { 0, 0, 1 });
|
||||
|
||||
transform *= glm::scale(glm::mat4(1.0f), scale);
|
||||
|
||||
return transform;
|
||||
};
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
ImGui::DragFloat3("Position", glm::value_ptr(transform[3]), 0.1f);
|
||||
DrawVec3Control("Position", translation);
|
||||
DrawVec3Control("Rotation", rotation);
|
||||
DrawVec3Control("Scale", scale);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenEngine {
|
||||
float fov = 45.0f;
|
||||
float perspective_near = 0.01f, perspective_far = 1000.0f;
|
||||
|
||||
float aspect_ratio = 0.0f;
|
||||
float aspect_ratio = 16.0f/9.0f;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user