mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Deleted old gizmo classes and dynamic sizes for gizmo in viewport
This commit is contained in:
@@ -163,6 +163,20 @@ bool GizmoDrawer::IsEntityInSelection(Nuake::Entity entity)
|
||||
return false;
|
||||
}
|
||||
|
||||
float GizmoDrawer::GetGizmoScale(const Vector3& camPosition, const Nuake::Vector3& position)
|
||||
{
|
||||
float distance = Distance(camPosition, position);
|
||||
|
||||
constexpr float ClosestDistance = 3.5f;
|
||||
if (distance < ClosestDistance)
|
||||
{
|
||||
float fraction = distance / ClosestDistance;
|
||||
return fraction;
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
void GizmoDrawer::DrawAxis(Ref<Scene> scene, bool occluded)
|
||||
{
|
||||
RenderCommand::Enable(RendererEnum::DEPTH_TEST);
|
||||
@@ -171,7 +185,9 @@ void GizmoDrawer::DrawAxis(Ref<Scene> scene, bool occluded)
|
||||
m_LineShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform());
|
||||
m_LineShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
m_LineShader->SetUniform1f("u_Opacity", occluded ? 0.1f : 0.5f);
|
||||
m_LineShader->SetUniformVec4("u_Color", {0.0f, 0.0f, 0.0f, 0.0f});
|
||||
m_AxisLineBuffer->Bind();
|
||||
glLineWidth(1.0f);
|
||||
Nuake::RenderCommand::DrawLines(0, 6);
|
||||
}
|
||||
}
|
||||
@@ -432,6 +448,8 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
gizmoShader->SetUniform1f("u_Opacity", occluded ? 0.1f : 0.5f);
|
||||
RenderCommand::Disable(RendererEnum::FACE_CULL);
|
||||
|
||||
const Vector3& cameraPosition = scene->m_EditorCamera->GetTranslation();
|
||||
|
||||
// Camera
|
||||
auto camView = scene->m_Registry.view<TransformComponent, CameraComponent>();
|
||||
for (auto e : camView)
|
||||
@@ -448,7 +466,7 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
const Vector3& particleGlobalPosition = transform.GetGlobalPosition();
|
||||
particleTransform[3] = initialTransform[3];
|
||||
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5));
|
||||
particleTransform = glm::scale(particleTransform, m_GizmoSize * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
@@ -487,7 +505,7 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
const Vector3& particleGlobalPosition = transform.GetGlobalPosition();
|
||||
particleTransform[3] = initialTransform[3];
|
||||
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5));
|
||||
particleTransform = glm::scale(particleTransform, m_GizmoSize * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
@@ -509,7 +527,7 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
const Vector3& particleGlobalPosition = transform.GetGlobalPosition();
|
||||
particleTransform[3] = initialTransform[3];
|
||||
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.5, 0.5, 0.5));
|
||||
particleTransform = glm::scale(particleTransform, m_GizmoSize * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
@@ -531,18 +549,18 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
// Translation
|
||||
const Vector3& particleGlobalPosition = transform.GetGlobalPosition();
|
||||
particleTransform[3] = initialTransform[3];
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.1, 0.1, 0.1));
|
||||
particleTransform = glm::scale(particleTransform, Vector3(0.1, 0.1, 0.1) * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, particleTransform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Sound emitter
|
||||
auto audioView = scene->m_Registry.view<TransformComponent, AudioEmitterComponent>();
|
||||
for (auto e : audioView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/speaker.png").get());
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/sound_emitter.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", ((int32_t)(uint32_t)(e)) + 1);
|
||||
auto [transformComponent, audioEmitterComponent] = scene->m_Registry.get<TransformComponent, AudioEmitterComponent>(e);
|
||||
|
||||
@@ -551,15 +569,55 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
transform = glm::inverse(scene->m_EditorCamera->GetTransform());
|
||||
|
||||
// Translation
|
||||
const Vector3& globalPosition = transformComponent.GetGlobalPosition();
|
||||
const Vector3& particleGlobalPosition = transformComponent.GetGlobalPosition();
|
||||
transform[3] = initialTransform[3];
|
||||
transform = glm::scale(transform, Vector3(0.5f, 0.5f, 0.5f));
|
||||
transform = glm::scale(transform, m_GizmoSize * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, transform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
|
||||
// Rigid body
|
||||
auto rigidbodyView = scene->m_Registry.view<TransformComponent, RigidBodyComponent>();
|
||||
for (auto e : rigidbodyView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/rigidbody.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", ((int32_t)(uint32_t)(e)) + 1);
|
||||
auto [transformComponent, rigidbodyComponent] = scene->m_Registry.get<TransformComponent, RigidBodyComponent>(e);
|
||||
|
||||
auto initialTransform = transformComponent.GetGlobalTransform();
|
||||
Matrix4 transform = initialTransform;
|
||||
transform = glm::inverse(scene->m_EditorCamera->GetTransform());
|
||||
|
||||
// Translation
|
||||
const Vector3& particleGlobalPosition = transformComponent.GetGlobalPosition();
|
||||
transform[3] = initialTransform[3];
|
||||
transform = glm::scale(transform, m_GizmoSize * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, transform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
// Particle Emitter
|
||||
auto particleEmitterView = scene->m_Registry.view<TransformComponent, ParticleEmitterComponent>();
|
||||
for (auto e : particleEmitterView)
|
||||
{
|
||||
gizmoShader->SetUniformTex("gizmo_texture", TextureManager::Get()->GetTexture("Resources/Gizmos/particles.png").get());
|
||||
gizmoShader->SetUniform1i("u_EntityID", ((int32_t)(uint32_t)(e)) + 1);
|
||||
auto [transformComponent, particleEmitter] = scene->m_Registry.get<TransformComponent, ParticleEmitterComponent>(e);
|
||||
|
||||
auto initialTransform = transformComponent.GetGlobalTransform();
|
||||
Matrix4 transform = initialTransform;
|
||||
transform = glm::inverse(scene->m_EditorCamera->GetTransform());
|
||||
|
||||
// Translation
|
||||
const Vector3& particleGlobalPosition = transformComponent.GetGlobalPosition();
|
||||
transform[3] = initialTransform[3];
|
||||
transform = glm::scale(transform, m_GizmoSize * GetGizmoScale(cameraPosition, particleGlobalPosition));
|
||||
|
||||
renderList.AddToRenderList(Renderer::QuadMesh, transform);
|
||||
renderList.Flush(gizmoShader, true);
|
||||
}
|
||||
|
||||
// Revert to default depth testing
|
||||
//glDepthFunc(GL_LESS);
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <src/Resource/Model.h>
|
||||
#include <src/Physics/PhysicsShapes.h>
|
||||
|
||||
#include "Gizmos/CapsuleGizmo.h"
|
||||
#include "Gizmos/CylinderGizmo.h"
|
||||
#include "../Windows/EditorInterface.h"
|
||||
#include "src/AI/NavMeshDebugDrawer.h"
|
||||
|
||||
@@ -22,8 +20,10 @@ private:
|
||||
Shader* m_LineShader;
|
||||
NavMeshDebugDrawer m_DebugDrawer;
|
||||
std::map<std::string, Ref<Model>> m_Gizmos;
|
||||
std::map<uint32_t, Scope<CapsuleGizmo>> m_CapsuleGizmo;
|
||||
std::map<uint32_t, Scope<CylinderGizmo>> m_CylinderGizmo;
|
||||
std::map<uint32_t, Scope<Nuake::CapsuleGizmo>> m_CapsuleGizmo;
|
||||
std::map<uint32_t, Scope<Nuake::CylinderGizmo>> m_CylinderGizmo;
|
||||
|
||||
const Vector3 m_GizmoSize = Vector3(0.25f);
|
||||
|
||||
const std::vector<LineVertex> m_Vertices
|
||||
{
|
||||
@@ -60,4 +60,5 @@ private:
|
||||
void GenerateSphereGizmo();
|
||||
bool IsEntityInSelection(Nuake::Entity entity);
|
||||
|
||||
float GetGizmoScale(const Vector3& camPosition, const Nuake::Vector3& transform);
|
||||
};
|
||||
@@ -1,122 +0,0 @@
|
||||
#include "CapsuleGizmo.h"
|
||||
|
||||
#include <src/Core/Maths.h>
|
||||
|
||||
CapsuleGizmo::CapsuleGizmo() :
|
||||
_Radius(0.0f),
|
||||
_Height(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void CapsuleGizmo::Bind()
|
||||
{
|
||||
_CapsuleBuffer->Bind();
|
||||
}
|
||||
|
||||
void CapsuleGizmo::UpdateShape(float radius, float height)
|
||||
{
|
||||
if (_Radius == radius && _Height == height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Radius = radius;
|
||||
_Height = height;
|
||||
CreateMesh();
|
||||
}
|
||||
|
||||
void CapsuleGizmo::CreateMesh()
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
_CapsuleVertices.clear();
|
||||
|
||||
const float halfHeight = _Height / 2.0f;
|
||||
const float radius = _Radius;
|
||||
const float bottomCircleHeight = -halfHeight + radius;
|
||||
const float topCircleHeight = halfHeight - radius;
|
||||
|
||||
// Generate circles
|
||||
const float subDivision = 32.0f;
|
||||
constexpr const float pi = glm::pi<float>() * 4.0;
|
||||
float increment = pi / subDivision;
|
||||
for (int i = 0; i < subDivision * 2.0; i++)
|
||||
{
|
||||
float current = increment * (i);
|
||||
float x = glm::cos(current) * radius;
|
||||
float z = glm::sin(current) * radius;
|
||||
|
||||
current = increment * (i + 1);
|
||||
float x2 = glm::cos(current) * radius;
|
||||
float z2 = glm::sin(current) * radius;
|
||||
|
||||
Vector3 vert1, vert2;
|
||||
if (i < subDivision)
|
||||
{
|
||||
vert1 = Vector3(x, topCircleHeight, z);
|
||||
vert2 = Vector3(x2, topCircleHeight, z2);
|
||||
}
|
||||
else
|
||||
{
|
||||
vert1 = Vector3(x, bottomCircleHeight, z);
|
||||
vert2 = Vector3(x2, bottomCircleHeight, z2);
|
||||
}
|
||||
|
||||
_CapsuleVertices.push_back(LineVertex{ vert1, Color(1.0, 0, 0.0, 0.5) });
|
||||
_CapsuleVertices.push_back(LineVertex{ vert2, Color(1.0, 0, 0.0, 0.5) });
|
||||
}
|
||||
|
||||
for (int i = 0; i < subDivision * 2.0; i++)
|
||||
{
|
||||
float current = increment * (i);
|
||||
float x = glm::cos(current) * radius;
|
||||
float z = glm::sin(current) * radius;
|
||||
|
||||
current = increment * (i + 1);
|
||||
float x2 = glm::cos(current) * radius;
|
||||
float z2 = glm::sin(current) * radius;
|
||||
|
||||
float heightOffset = topCircleHeight;
|
||||
if (z < 0.0)
|
||||
{
|
||||
heightOffset = bottomCircleHeight;
|
||||
}
|
||||
|
||||
Vector3 vert1, vert2;
|
||||
if (i < subDivision)
|
||||
{
|
||||
vert1 = Vector3(x, z + heightOffset, 0);
|
||||
vert2 = Vector3(x2, z2 + heightOffset, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
vert1 = Vector3(0, z + heightOffset, x);
|
||||
vert2 = Vector3(0, z2 + heightOffset, x2);
|
||||
}
|
||||
|
||||
_CapsuleVertices.push_back(LineVertex{ vert1, Color(1.0, 0, 0.0, 0.5) });
|
||||
_CapsuleVertices.push_back(LineVertex{ vert2, Color(1.0, 0, 0.0, 0.5) });
|
||||
}
|
||||
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(radius, bottomCircleHeight, 0), Color(1.0, 0, 0.0, 0.5) });
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(radius, topCircleHeight, 0), Color(1.0, 0, 0.0, 0.5) });
|
||||
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(-radius, bottomCircleHeight, 0), Color(1.0, 0, 0.0, 0.5) });
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(-radius, topCircleHeight, 0), Color(1.0, 0, 0.0, 0.5) });
|
||||
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(0, bottomCircleHeight, radius), Color(1.0, 0, 0.0, 0.5) });
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(0, topCircleHeight, radius), Color(1.0, 0, 0.0, 0.5) });
|
||||
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(0, bottomCircleHeight, -radius), Color(1.0, 0, 0.0, 0.5) });
|
||||
_CapsuleVertices.push_back(LineVertex{ Vector3(0, topCircleHeight, -radius), Color(1.0, 0, 0.0, 0.5) });
|
||||
|
||||
_CapsuleBuffer = CreateRef<Nuake::VertexArray>();
|
||||
_CapsuleBuffer->Bind();
|
||||
|
||||
_CapsuleVertexBuffer = CreateRef<VertexBuffer>(_CapsuleVertices.data(), _CapsuleVertices.size() * sizeof(Nuake::LineVertex));
|
||||
auto vblayout = CreateRef<VertexBufferLayout>();
|
||||
vblayout->Push<float>(3);
|
||||
vblayout->Push<float>(4);
|
||||
|
||||
_CapsuleBuffer->AddBuffer(*_CapsuleVertexBuffer, *vblayout);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
#include <src/Core/Core.h>
|
||||
#include <src/Rendering/Vertex.h>
|
||||
#include <src/Rendering/Buffers/VertexBuffer.h>
|
||||
#include <src/Rendering/Buffers/VertexArray.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CapsuleGizmo
|
||||
{
|
||||
private:
|
||||
std::vector<Nuake::LineVertex> _CapsuleVertices;
|
||||
Ref<Nuake::VertexArray> _CapsuleBuffer;
|
||||
Ref<Nuake::VertexBuffer> _CapsuleVertexBuffer;
|
||||
|
||||
float _Radius;
|
||||
float _Height;
|
||||
|
||||
public:
|
||||
CapsuleGizmo();
|
||||
~CapsuleGizmo() = default;
|
||||
|
||||
void UpdateShape(float radius, float height);
|
||||
void CreateMesh();
|
||||
void Bind();
|
||||
};
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "CylinderGizmo.h"
|
||||
|
||||
#include <src/Core/Maths.h>
|
||||
|
||||
CylinderGizmo::CylinderGizmo(Nuake::Color color) :
|
||||
_Radius(0.0f),
|
||||
_Height(0.0f),
|
||||
_Color(color)
|
||||
{
|
||||
}
|
||||
|
||||
void CylinderGizmo::Bind()
|
||||
{
|
||||
_CylinderBuffer->Bind();
|
||||
}
|
||||
|
||||
void CylinderGizmo::UpdateShape(float radius, float height, Nuake::Color color)
|
||||
{
|
||||
if (_Radius == radius && _Height == height && _Color == color)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Radius = radius;
|
||||
_Height = height;
|
||||
_Color = color;
|
||||
|
||||
CreateMesh();
|
||||
}
|
||||
|
||||
void CylinderGizmo::CreateMesh()
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
_CylinderVertices.clear();
|
||||
|
||||
const float halfHeight = _Height / 2.0f;
|
||||
const float radius = _Radius;
|
||||
const float bottomCircleHeight = -halfHeight;
|
||||
const float topCircleHeight = halfHeight;
|
||||
|
||||
// Generate circles
|
||||
const float subDivision = 32.0f;
|
||||
constexpr const float pi = glm::pi<float>() * 4.0;
|
||||
float increment = pi / subDivision;
|
||||
for (int i = 0; i < subDivision * 2.0; i++)
|
||||
{
|
||||
float current = increment * (i);
|
||||
float x = glm::cos(current) * radius;
|
||||
float z = glm::sin(current) * radius;
|
||||
|
||||
current = increment * (i + 1);
|
||||
float x2 = glm::cos(current) * radius;
|
||||
float z2 = glm::sin(current) * radius;
|
||||
|
||||
Vector3 vert1, vert2;
|
||||
if (i < subDivision)
|
||||
{
|
||||
vert1 = Vector3(x, topCircleHeight, z);
|
||||
vert2 = Vector3(x2, topCircleHeight, z2);
|
||||
}
|
||||
else
|
||||
{
|
||||
vert1 = Vector3(x, bottomCircleHeight, z);
|
||||
vert2 = Vector3(x2, bottomCircleHeight, z2);
|
||||
}
|
||||
|
||||
_CylinderVertices.push_back(LineVertex{ vert1, _Color });
|
||||
_CylinderVertices.push_back(LineVertex{ vert2, _Color });
|
||||
}
|
||||
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(radius, bottomCircleHeight, 0), _Color });
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(radius, topCircleHeight, 0), _Color });
|
||||
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(-radius, bottomCircleHeight, 0), _Color });
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(-radius, topCircleHeight, 0), _Color });
|
||||
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(0, bottomCircleHeight, radius), _Color });
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(0, topCircleHeight, radius), _Color });
|
||||
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(0, bottomCircleHeight, -radius), _Color });
|
||||
_CylinderVertices.push_back(LineVertex{ Vector3(0, topCircleHeight, -radius), _Color });
|
||||
|
||||
_CylinderBuffer = CreateRef<Nuake::VertexArray>();
|
||||
_CylinderBuffer->Bind();
|
||||
|
||||
_CylinderVertexBuffer = CreateRef<VertexBuffer>(_CylinderVertices.data(), _CylinderVertices.size() * sizeof(Nuake::LineVertex));
|
||||
auto vblayout = CreateRef<VertexBufferLayout>();
|
||||
vblayout->Push<float>(3);
|
||||
vblayout->Push<float>(4);
|
||||
|
||||
_CylinderBuffer->AddBuffer(*_CylinderVertexBuffer, *vblayout);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <src/Core/Core.h>
|
||||
#include "src/Core/Maths.h"
|
||||
#include <src/Rendering/Vertex.h>
|
||||
#include <src/Rendering/Buffers/VertexBuffer.h>
|
||||
#include <src/Rendering/Buffers/VertexArray.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CylinderGizmo
|
||||
{
|
||||
private:
|
||||
std::vector<Nuake::LineVertex> _CylinderVertices;
|
||||
Ref<Nuake::VertexArray> _CylinderBuffer;
|
||||
Ref<Nuake::VertexBuffer> _CylinderVertexBuffer;
|
||||
|
||||
float _Radius;
|
||||
float _Height;
|
||||
Nuake::Color _Color;
|
||||
|
||||
public:
|
||||
CylinderGizmo(Nuake::Color color = Nuake::Color(1, 0, 0, 1));
|
||||
~CylinderGizmo() = default;
|
||||
|
||||
void UpdateShape(float radius, float height, Nuake::Color color = Nuake::Color(1, 0, 0, 1));
|
||||
void CreateMesh();
|
||||
void Bind();
|
||||
};
|
||||
Reference in New Issue
Block a user