psydack/uimgui

[QUESTION] I figured out how to draw Gizmo from ImGuizmo, but they distorted.

Closed this issue · 2 comments

Well, as the title says, I figured out how to draw it all, but for some reason it doesn't display correctly. I'm not very good at matrices and I have no idea how to fix it at all.

I`m using Unity 2021.1.17f1 with Built-in render pipeline.
Package version 4.1.1 (Last at the moment.)

https://youtu.be/yEWYUFGb97w

private void OnLayout(UImGui.UImGui obj)
{
ImGuizmo.BeginFrame();
ImGuizmo.SetRect(0, 0, Screen.height, Screen.width);

Matrix4x4 matrix = _objectInScene.transform.localToWorldMatrix;
Matrix4x4 view = _currentCamera.worldToCameraMatrix;
Matrix4x4 projection = _currentCamera.projectionMatrix;

ImGuizmo.Manipulate(ref view.m00, ref projection.m00, OPERATION.TRANSLATE, MODE.WORLD, ref matrix.m00);
ImGuizmo.DrawGrid(ref view.m00, ref projection.m00, ref matrix.m00, 50f);

}

Zguy commented

Seems like Screen.height and Screen.width should switch places in your SetRect call. You may also want to add a SetOrthographic call depending on your camera settings.

Also, I don't think you need to call BeginFrame yourself, UImGui should be doing that for you.

There's a new version that look fix it using the comment above. I'm closing this issue. Re-open if you need