CedricGuillemet / ImGuizmo

Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui
MIT License
3.1k stars 873 forks source link

Issue with ortho projection on Vulkan #283

Open gamecoder-nz opened 1 year ago

gamecoder-nz commented 1 year ago

I'm sure I'm doing something wrong but I can't figure out what. I have an orthographic projection like this

m_AspectRatio = (float)width / (float)height;
float orthoLeft = 0.0f;
float orthoRight = (float)m_OrthographicHeight * m_AspectRatio * m_Zoom;
float orthoTop = (float)m_OrthographicHeight * m_Zoom;
float orthoBottom = 0.0f;

m_Projection = glm::ortho(orthoLeft, orthoRight, orthoBottom, orthoTop, (float)m_OrthographicNear, (float)m_OrthographicFar);

glm::mat4 transformationMatrix = glm::translate(glm::mat4(1.0f), m_Position);

m_View = glm::inverse(transformationMatrix);

The camera doesn't rotate and stays at z = 10 but the y axis for the guizmo is inverted. It is pointing the wrong direction and drags in the wrong direction.

view

gamecoder-nz commented 1 year ago

If I create another matrix where the top and bottom are swapped like this glm::ortho(orthoLeft, orthoRight, orthoTop, orthoBottom, (float)m_OrthographicNear, (float)m_OrthographicFar);

Then it works

gamecoder-nz commented 1 year ago

It also works if I swap the projection matrices around. So the top and bottom for ImGuizmo has to be the opposite of what's used for the engine.