This commit is contained in:
Antoine Pilote
2023-09-08 17:21:01 -04:00
parent a9837fbe1a
commit 0fd36c292c
4 changed files with 95 additions and 58 deletions

View File

@@ -279,10 +279,35 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene)
auto camView = scene->m_Registry.view<TransformComponent, CameraComponent>();
for (auto e : camView)
{
auto [transform, cam] = scene->m_Registry.get<TransformComponent, CameraComponent>(e);
auto& [transform, cam] = scene->m_Registry.get<TransformComponent, CameraComponent>(e);
renderList.AddToRenderList(_gizmos["cam"]->GetMeshes()[0], transform.GetGlobalTransform());
auto view = transform.GetGlobalTransform();
Frustum& frustum = cam.CameraInstance->GetFrustum();
auto& frustumCorners = frustum.GetPoints();
constexpr int frustumEdges[12][2] = {
{0, 1}, {1, 3}, {3, 2}, {2, 0}, // Near plane edges
{4, 5}, {5, 7}, {7, 6}, {6, 4}, // Far plane edges
{0, 4}, {1, 5}, {2, 6}, {3, 7} // Connection lines
};
glBegin(GL_LINES);
for (int i = 0; i < 12; ++i) {
int startIdx = frustumEdges[i][0];
int endIdx = frustumEdges[i][1];
const Vector3& startCorner = view * Vector4(frustumCorners[startIdx], 1.0f);
const Vector3& endCorner = frustumCorners[endIdx];
glVertex3f(startCorner.x, startCorner.y, startCorner.z);
glVertex3f(endCorner.x, endCorner.y, endCorner.z);
}
glEnd();
}
renderList.Flush(flatShader, true);
// Lights

View File

@@ -64,11 +64,14 @@ namespace Nuake
ImGui::PushFont(FontManager::GetFont(Icons));
const char* icon = ICON_FA_FOLDER;
const std::string id = ICON_FA_FOLDER + std::string("##") + directory->name;
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
if (ImGui::Button(id.c_str(), ImVec2(100, 100)))
{
m_CurrentDirectory = directory;
}
ImGui::PopStyleVar();
const std::string hoverMenuId = std::string("item_hover_menu") + std::to_string(drawId);
if (ImGui::IsItemHovered() && ImGui::IsMouseReleased(1))
{
@@ -669,11 +672,12 @@ namespace Nuake
bool child = ImGui::BeginChild("Content", avail);
ImGui::PopStyleVar();
ImGui::SameLine();
if (child)
{
int width = avail.x;
ImVec2 buttonSize = ImVec2(80, 80);
int amount = (int)(width / 100);
ImVec2 buttonSize = ImVec2(110, 110);
int amount = (int)(width / buttonSize.x);
if (amount <= 0) amount = 1;
int i = 1; // current amount of item per row.
@@ -683,7 +687,7 @@ namespace Nuake
if (m_CurrentDirectory && m_CurrentDirectory != FileSystem::RootDirectory && m_CurrentDirectory->Parent)
{
ImGui::TableNextColumn();
if (ImGui::Button("..", ImVec2(100, 100)))
if (ImGui::Button("..", buttonSize))
m_CurrentDirectory = m_CurrentDirectory->Parent;
i++;
}
@@ -711,7 +715,7 @@ namespace Nuake
{
if(m_SearchKeyword.empty() || f->GetName().find(String::Sanitize(m_SearchKeyword)) != std::string::npos)
{
if (i - 1 % amount != 0 || i == 1)
if (i + 1 % amount != 0 || i == 1)
{
ImGui::TableNextColumn();
}

View File

@@ -1,63 +1,69 @@
#include "src/Core/Maths.h"
using namespace Nuake;
Quat Nuake::LookAt(Vector3 sourcePoint, Vector3 destPoint)
namespace Nuake
{
Vector3 forwardVector = glm::normalize(destPoint - sourcePoint);
Quat Nuake::LookAt(Vector3 sourcePoint, Vector3 destPoint)
{
Vector3 forwardVector = glm::normalize(destPoint - sourcePoint);
float dot = glm::dot(Vector3(0, 0, 1), forwardVector);
if (glm::abs(dot - (-1.0f)) < 0.000001f)
{
return Quat(0, 1, 0, 3.1415926535897932f);
}
if (glm::abs(dot - (1.0f)) < 0.000001f)
{
return Quat(); // identity
float dot = glm::dot(Vector3(0, 0, 1), forwardVector);
if (glm::abs(dot - (-1.0f)) < 0.000001f)
{
return Quat(0, 1, 0, 3.1415926535897932f);
}
if (glm::abs(dot - (1.0f)) < 0.000001f)
{
return Quat(); // identity
}
float rotAngle = acos(dot);
Vector3 rotAxis = glm::cross(Vector3(0, 0, 1), forwardVector);
rotAxis = glm::normalize(rotAxis);
return CreateFromAxisAngle(rotAxis, rotAngle);
}
float rotAngle = acos(dot);
Vector3 rotAxis = glm::cross(Vector3(0, 0, 1), forwardVector);
rotAxis = glm::normalize(rotAxis);
return CreateFromAxisAngle(rotAxis, rotAngle);
}
// just in case you need that function also
Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle)
{
float halfAngle = angle * .5f;
float s = sin(halfAngle);
Quat q;
q.x = axis.x * s;
q.y = axis.y * s;
q.z = axis.z * s;
q.w = cos(halfAngle);
return q;
}
// just in case you need that function also
Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle)
{
float halfAngle = angle * .5f;
float s = sin(halfAngle);
Quat q;
q.x = axis.x * s;
q.y = axis.y * s;
q.z = axis.z * s;
q.w = cos(halfAngle);
return q;
}
Quat Nuake::QuatFromEuler(float x, float y, float z)
{
Quat pitchQuat = glm::angleAxis(Rad(x), Vector3(1.0f, 0.0f, 0.0f));
Quat yawQuat = glm::angleAxis(Rad(y), Vector3(0.0f, 1.0f, 0.0f));
Quat rollQuat = glm::angleAxis(Rad(z), Vector3(0.0f, 0.0f, -1.0f));
Quat orientation = yawQuat * pitchQuat * rollQuat;
Quat Nuake::QuatFromEuler(float x, float y, float z)
{
Quat pitchQuat = glm::angleAxis(Rad(x), Vector3(1.0f, 0.0f, 0.0f));
Quat yawQuat = glm::angleAxis(Rad(y), Vector3(0.0f, 1.0f, 0.0f));
Quat rollQuat = glm::angleAxis(Rad(z), Vector3(0.0f, 0.0f, -1.0f));
Quat orientation = yawQuat * pitchQuat * rollQuat;
return glm::normalize(orientation);
}
return glm::normalize(orientation);
}
Vector3 Nuake::QuatToDirection(const Quat& quat)
{
return glm::normalize(quat * Vector3(0, 0, -1));
}
Vector3 Nuake::QuatToDirection(const Quat& quat)
{
return glm::normalize(quat * Vector3(0, 0, -1));
}
void Nuake::Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale)
{
pos = m[3];
for (int i = 0; i < 3; i++)
scale[i] = glm::length(Vector3(m[i]));
const Matrix3 rotMtx(
Vector3(m[0]) / scale[0],
Vector3(m[1]) / scale[1],
Vector3(m[2]) / scale[2]);
rot = glm::quat_cast(rotMtx);
}
void Nuake::Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale)
{
pos = m[3];
for (int i = 0; i < 3; i++)
scale[i] = glm::length(Vector3(m[i]));
const Matrix3 rotMtx(
Vector3(m[0]) / scale[0],
Vector3(m[1]) / scale[1],
Vector3(m[2]) / scale[2]);
rot = glm::quat_cast(rotMtx);
}
const Matrix4& Nuake::TransformToCameraTransform(const Matrix4& mat)
{
return mat;
}
}

View File

@@ -25,4 +25,6 @@ namespace Nuake
Quat QuatFromEuler(float x, float y, float z);
Vector3 QuatToDirection(const Quat& quat);
void Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale);
const Matrix4& TransformToCameraTransform(const Matrix4& mat);
}