Fixed imguizmo aspect ratio
This commit is contained in:
@@ -30,7 +30,7 @@ ViewportWidget::~ViewportWidget()
|
||||
void ViewportWidget::Update(float ts)
|
||||
{
|
||||
editorContext.GetScene()->Update(ts);
|
||||
auto& editorCam = editorContext.GetScene()->m_EditorCamera;
|
||||
auto editorCam = (EditorCamera*)(editorContext.GetScene()->GetCurrentCamera().get());
|
||||
editorCam->Update(ts, isHoveringViewport);
|
||||
|
||||
const Vector2 viewportSize = sceneViewport->GetViewportSize();
|
||||
@@ -67,6 +67,7 @@ void ViewportWidget::Draw()
|
||||
VkDescriptorSet textureDesc = sceneViewport->GetRenderTarget()->GetImGuiDescriptorSet();
|
||||
|
||||
ImVec2 imagePos = ImGui::GetWindowPos() + ImGui::GetCursorPos();
|
||||
ImVec2 viewportMin = ImGui::GetCursorScreenPos();
|
||||
// Input::SetEditorViewportSize(m_ViewportPos, viewportPanelSize);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||
//m_ViewportPos = { imagePos.x, imagePos.y };
|
||||
@@ -85,7 +86,7 @@ void ViewportWidget::Draw()
|
||||
// TODO(antopilo) drag n drop
|
||||
ImGuizmo::SetDrawlist();
|
||||
ImGuizmo::AllowAxisFlip(true);
|
||||
ImGuizmo::SetRect(imagePos.x, imagePos.y, viewportPanelSize.x, viewportPanelSize.y);
|
||||
ImGuizmo::SetRect(viewportMin.x, viewportMin.y, regionAvail.x, regionAvail.y);
|
||||
|
||||
// TODO(grid)
|
||||
auto selection = editorContext.GetSelection();
|
||||
@@ -99,20 +100,19 @@ void ViewportWidget::Draw()
|
||||
{
|
||||
TransformComponent& tc = selection.Entity.GetComponent<TransformComponent>();
|
||||
Matrix4 transform = tc.GetGlobalTransform();
|
||||
const auto& editorCam = editorContext.GetScene()->GetCurrentCamera();
|
||||
auto editorCam = editorContext.GetScene()->GetCurrentCamera();
|
||||
Matrix4 cameraView = editorCam->GetTransform();
|
||||
|
||||
// Since imguizmo doesnt support reverse-Z, we need to create a new projection matrix
|
||||
// With a normal near and far plane.
|
||||
Matrix4 normalZProjection = glm::perspectiveFov(glm::radians(editorCam->Fov), 9.0f * editorCam->AspectRatio, 9.0f, editorCam->Far, editorCam->Near);
|
||||
|
||||
Matrix4 normalZProjection = glm::perspectiveFov(glm::radians(editorCam->Fov), 9.0f * editorCam->AspectRatio, 9.0f, editorCam->Near, editorCam->Far);
|
||||
static Vector3 camPreviousPos = editorContext.GetScene()->m_EditorCamera->Translation;
|
||||
static Vector3 camNewPos = Vector3(0, 0, 0);
|
||||
Vector3 camDelta = camNewPos - camPreviousPos;
|
||||
Vector3 previousGlobalPos = transform[3];
|
||||
// Imguizmo calculates the delta from the gizmo,
|
||||
ImGuizmo::Manipulate(
|
||||
glm::value_ptr(editorContext.GetScene()->GetCurrentCamera()->GetTransform()),
|
||||
glm::value_ptr(editorCam->GetTransform()),
|
||||
glm::value_ptr(normalZProjection),
|
||||
CurrentOperation, CurrentMode,
|
||||
glm::value_ptr(transform), NULL,
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Nuake
|
||||
// This is the *whole* buffer
|
||||
struct MaterialData
|
||||
{
|
||||
std::array<MaterialBufferStruct, 1000> Data;
|
||||
std::array<MaterialBufferStruct, 3000> Data;
|
||||
};
|
||||
|
||||
struct LightData
|
||||
@@ -86,7 +86,7 @@ namespace Nuake
|
||||
};
|
||||
|
||||
constexpr uint32_t MAX_MODEL_MATRIX = 3000;
|
||||
constexpr uint32_t MAX_MATERIAL = 1000;
|
||||
constexpr uint32_t MAX_MATERIAL = 3000;
|
||||
constexpr uint32_t MAX_TEXTURES = 500;
|
||||
constexpr uint32_t MAX_CAMERAS = 100;
|
||||
constexpr uint32_t MAX_LIGHTS = 100;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "vk_mem_alloc.h"
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
bool NKUseValidationLayer = true;
|
||||
|
||||
@@ -85,7 +86,7 @@ void VkRenderer::Initialize()
|
||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024 }
|
||||
};
|
||||
|
||||
GlobalDescriptorAllocator.InitPool(Device, 1000, sizes);
|
||||
GlobalDescriptorAllocator.InitPool(Device, 5000, sizes);
|
||||
|
||||
InitCommands();
|
||||
|
||||
@@ -325,9 +326,9 @@ void VkRenderer::InitDescriptors()
|
||||
// create a descriptor pool
|
||||
std::vector<DescriptorAllocatorGrowable::PoolSizeRatio> frame_sizes =
|
||||
{
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 3 },
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3 },
|
||||
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 3 },
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 64 },
|
||||
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 64 },
|
||||
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 64 },
|
||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4 },
|
||||
};
|
||||
|
||||
@@ -341,13 +342,8 @@ void VkRenderer::PrepareSceneData(RenderContext ctx)
|
||||
std::vector<Ref<Scene>> scenes;
|
||||
scenes.reserve(SceneViewports.size());
|
||||
|
||||
for (auto& [scene, views] : SceneViewports)
|
||||
for (auto& [scene, _] : SceneViewports)
|
||||
{
|
||||
for (auto& view : views)
|
||||
{
|
||||
//Viewports[view]->Resize();
|
||||
}
|
||||
|
||||
scenes.push_back(scene);
|
||||
}
|
||||
|
||||
@@ -831,8 +827,10 @@ void DescriptorAllocator::InitPool(VkDevice device, uint32_t maxSets, std::span<
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
VkDescriptorPoolCreateInfo pool_info = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
|
||||
pool_info.flags = 0;
|
||||
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
pool_info.maxSets = maxSets;
|
||||
pool_info.poolSizeCount = (uint32_t)poolSizes.size();
|
||||
pool_info.pPoolSizes = poolSizes.data();
|
||||
|
||||
@@ -195,13 +195,6 @@ void Window::Draw()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We cannot render to a framebuffer that is smaller than 1x1.
|
||||
Vector2 size = this->framebuffer->GetSize();
|
||||
size.x = std::max(size.x, 1.0f);
|
||||
size.y = std::max(size.y, 1.0f);
|
||||
|
||||
cam->AspectRatio = size.x / size.y;
|
||||
}
|
||||
|
||||
void Window::EndDraw()
|
||||
|
||||
Reference in New Issue
Block a user