Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for using the mouse wheel to manipulate the gizmo #19

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Brio/Config/InterfaceConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Brio.Config;
using ImGuiNET;

namespace Brio.Config;

internal class InterfaceConfiguration
{
Expand All @@ -7,4 +9,7 @@ internal class InterfaceConfiguration
public bool ShowInCutscene { get; set; } = false;
public bool ShowWhenUIHidden { get; set; } = false;
public bool CensorActorNames { get; set; } = false;

public ImGuiKey IncrementSmall { get; set; } = ImGuiKey.RightCtrl;
public ImGuiKey IncrementLarge { get; set; } = ImGuiKey.RightShift;
}
46 changes: 46 additions & 0 deletions Brio/Core/ImGuizmoExtensions.cs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left Shift and Left Ctrl are already in use.

Maby use Right Shift and Right Ctrl with ImGui.IsKeyPressed() instead?

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Brio.Config;
using ImGuiNET;
using ImGuizmoNET;
using System.Numerics;

namespace Brio.Core;

internal static class ImGuizmoExtensions
{
public static bool MouseWheelManipulate(ref Matrix4x4 matrix)
{
if(ImGui.IsAnyMouseDown())
return false;

float mouseWheel = ImGui.GetIO().MouseWheel / 100;

if(mouseWheel != 0)
{
bool smallIncrement = ImGui.IsKeyDown(ConfigurationService.Instance.Configuration.Interface.IncrementSmall);
if(smallIncrement)
mouseWheel /= 10;

bool largeIncrement = ImGui.IsKeyDown(ConfigurationService.Instance.Configuration.Interface.IncrementLarge);
if(largeIncrement)
mouseWheel *= 10;

if(ImGuizmo.IsOver(OPERATION.ROTATE_X))
{
matrix = Matrix4x4.CreateRotationX(mouseWheel) * matrix;
return true;
}
else if(ImGuizmo.IsOver(OPERATION.ROTATE_Y))
{
matrix = Matrix4x4.CreateRotationY(mouseWheel) * matrix;
return true;
}
else if(ImGuizmo.IsOver(OPERATION.ROTATE_Z))
{
matrix = Matrix4x4.CreateRotationZ(mouseWheel) * matrix;
return true;
}
}

return false;
}
}
5 changes: 5 additions & 0 deletions Brio/UI/Windows/Specialized/PosingGraphicalWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ private unsafe void DrawGizmo()

ImGuizmo.Enable(true);

if(ImGuizmoExtensions.MouseWheelManipulate(ref matrix))
{
_trackingMatrix = matrix;
}

if(ImGuizmo.Manipulate(ref viewMatrix.M11, ref projectionMatrix.M11, OPERATION.ROTATE, _posingService.CoordinateMode.AsGizmoMode(), ref matrix.M11))
{
_trackingMatrix = matrix;
Expand Down
6 changes: 6 additions & 0 deletions Brio/UI/Windows/Specialized/PosingOverlayWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ private unsafe void DrawGizmo(PosingCapability posing, OverlayUIState uiState)

Transform? newTransform = null;

if(ImGuizmoExtensions.MouseWheelManipulate(ref matrix))
{
newTransform = matrix.ToTransform();
_trackingTransform = newTransform;
}

if(ImGuizmo.Manipulate(
ref worldViewMatrix.M11,
ref projectionMatrix.M11,
Expand Down
Loading