CedricGuillemet / ImGuizmo

Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gizmo not showing up when using DirectX 12

Adam-Miszczak opened this issue · comments

Hi, I'm creating an application in DX12 and I ported over the ImGuizmo code from the DX11 version which mostly looks like this:

    if (selected != NULL) {
      int transform = 0;
      ImGuizmo::BeginFrame();
      ImGuizmo::Enable(true);

      XMMATRIX local = selected->localMatrix;
      XMMATRIX view = camera->viewMatrix;
      XMMATRIX proj = camera->projectionMatrix;
      XMFLOAT4X4 _local, _view, _proj;
      XMStoreFloat4x4(&_local, local);
      XMStoreFloat4x4(&_view,  view);
      XMStoreFloat4x4(&_proj,  proj);

      float pos[3] = { selected->position.x, selected->position.y, selected->position.z };
      float rot[3] = { selected->rotation.x, selected->rotation.y, selected->rotation.z };
      float scl[3] = { selected->scale.x, selected->scale.y, selected->scale.z };

      ImGuizmo::RecomposeMatrixFromComponents(pos, rot, scl, *_local.m);

      static ImGuizmo::MODE currentGizmoMode(ImGuizmo::LOCAL);
      ImGuizmo::SetRect(0, 0, m_width, m_height);
      const float snap = 0.000001f;
      switch (transformMode) {
      case 0:
          if (ImGuizmo::Manipulate(*_view.m, *_proj.m, ImGuizmo::TRANSLATE, currentGizmoMode, *_local.m, NULL, NULL)) transform = 1;
          break;
      case 1:
          if (ImGuizmo::Manipulate(*_view.m, *_proj.m, ImGuizmo::ROTATE, currentGizmoMode, *_local.m, NULL, &snap)) transform = 1;
          break;
      case 2:
          if (ImGuizmo::Manipulate(*_view.m, *_proj.m, ImGuizmo::SCALE, currentGizmoMode, *_local.m, NULL, NULL)) transform = 2;
          break;
      }

      selected->localMatrix = local;
    transform = 0;
}

But the gizmo does not appear. In RenderDoc I can see that the draw call for the gizmo window is issued but the position values for the vertices come up as 'NaN'. I'm using the latest version of ImGuizmo and ImGui v1.85 WIP (Docking Branch). What's going wrong? Thanks.

In such case, I would put the gizmo is 'default' condition:

  • set matrix manipulation to be identity
  • set view matrix as identity as well but pushed back a little so gizmo should be visible
  • have projection matrix values copy pasted from the sample
  • removed interaction code

Then, when the gizmo is visible, replace with your code and expected values.
Do you see NaN is RenderDoc other than the vertices? any NaN is view/projection?

Hi Cedric thanks for your help it was indeed a problem with my matrices, I was transposing them before using them in my ImGuizmo code which caused the Gizmo to not appear. Thanks!