From 8bc28f2ba65e49c2ad85645bdfb9d55b206f0566 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Tue, 28 Mar 2023 18:42:49 +0800 Subject: [PATCH 01/21] Update: debug --- ImGuizmo.cpp | 12 ++++++++---- ImGuizmo.h | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index d9757869..b0ea508d 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -24,6 +24,8 @@ // SOFTWARE. // +#include + #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif @@ -1129,7 +1131,7 @@ namespace IMGUIZMO_NAMESPACE } } - static void ComputeTripodAxisAndVisibility(const int axisIndex, vec_t& dirAxis, vec_t& dirPlaneX, vec_t& dirPlaneY, bool& belowAxisLimit, bool& belowPlaneLimit, const bool localCoordinates = false) + static void ComputeTripodAxisAndVisibility(const int axisIndex, vec_t& dirAxis, vec_t& dirPlaneX, vec_t& dirPlaneY, bool& belowAxisLimit, bool& belowPlaneLimit, const bool localCoordinates = false, CONSTANCY constancy = SCALE_CONST) { dirAxis = directionUnary[axisIndex]; dirPlaneX = directionUnary[(axisIndex + 1) % 3]; @@ -1157,6 +1159,8 @@ namespace IMGUIZMO_NAMESPACE float lenDirPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneY, localCoordinates); float lenDirMinusPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneY, localCoordinates); + std::cout << lenDir << " " << lenDirMinus << " " << lenDirPlaneX << " " << lenDirMinusPlaneX << " " << lenDirPlaneY << " " << lenDirMinusPlaneY << std::endl; + // For readability bool & allowFlip = gContext.mAllowAxisFlip; float mulAxis = (allowFlip && lenDir < lenDirMinus&& fabsf(lenDir - lenDirMinus) > FLT_EPSILON) ? -1.f : 1.f; @@ -1500,7 +1504,7 @@ namespace IMGUIZMO_NAMESPACE } } - static void DrawTranslationGizmo(OPERATION op, int type) + static void DrawTranslationGizmo(OPERATION op, int type, CONSTANCY constancy) { ImDrawList* drawList = gContext.mDrawList; if (!drawList) @@ -2481,7 +2485,7 @@ namespace IMGUIZMO_NAMESPACE gContext.mAllowAxisFlip = value; } - bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix, const float* snap, const float* localBounds, const float* boundsSnap) + bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix, const float* snap, const float* localBounds, const float* boundsSnap, CONSTANCY constancy) { // Scale is always local or matrix will be skewed when applying world scale or oriented matrix ComputeContext(view, projection, matrix, (operation & SCALE) ? LOCAL : mode); @@ -2522,7 +2526,7 @@ namespace IMGUIZMO_NAMESPACE if (!gContext.mbUsingBounds) { DrawRotationGizmo(operation, type); - DrawTranslationGizmo(operation, type); + DrawTranslationGizmo(operation, type, constancy); DrawScaleGizmo(operation, type); DrawScaleUniveralGizmo(operation, type); } diff --git a/ImGuizmo.h b/ImGuizmo.h index cdc11ecf..35b9662b 100644 --- a/ImGuizmo.h +++ b/ImGuizmo.h @@ -202,7 +202,13 @@ namespace IMGUIZMO_NAMESPACE WORLD }; - IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL); + enum CONSTANCY + { + SCALE_CONST = (1u << 0), + DISPLAY_CONST + }; + + IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL, CONSTANCY constancy = SCALE_CONST); // // Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en // It seems to be a defensive patent in the US. I don't think it will bring troubles using it as From 6edb4f9b698e3917265410e9c15cfe009d24008c Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Tue, 28 Mar 2023 18:58:26 +0800 Subject: [PATCH 02/21] Update: scale factor --- ImGuizmo.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index b0ea508d..15548803 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1150,14 +1150,15 @@ namespace IMGUIZMO_NAMESPACE else { // new method - float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates); - float lenDirMinus = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirAxis, localCoordinates); + float scale_factor = (gContext.mViewMat.m16)[0]; + float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates) / scale_factor; + float lenDirMinus = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirAxis, localCoordinates)/ scale_factor; - float lenDirPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneX, localCoordinates); - float lenDirMinusPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneX, localCoordinates); + float lenDirPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneX, localCoordinates)/ scale_factor; + float lenDirMinusPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneX, localCoordinates)/ scale_factor; - float lenDirPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneY, localCoordinates); - float lenDirMinusPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneY, localCoordinates); + float lenDirPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneY, localCoordinates)/ scale_factor; + float lenDirMinusPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneY, localCoordinates)/ scale_factor; std::cout << lenDir << " " << lenDirMinus << " " << lenDirPlaneX << " " << lenDirMinusPlaneX << " " << lenDirPlaneY << " " << lenDirMinusPlaneY << std::endl; From f2c2c9083d7716a81cb06306babd3e7b6ff506ed Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Tue, 28 Mar 2023 19:02:42 +0800 Subject: [PATCH 03/21] Update: scale --- ImGuizmo.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 15548803..2eb14b94 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1151,25 +1151,25 @@ namespace IMGUIZMO_NAMESPACE { // new method float scale_factor = (gContext.mViewMat.m16)[0]; - float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates) / scale_factor; - float lenDirMinus = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirAxis, localCoordinates)/ scale_factor; + float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates); + float lenDirMinus = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirAxis, localCoordinates); - float lenDirPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneX, localCoordinates)/ scale_factor; - float lenDirMinusPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneX, localCoordinates)/ scale_factor; + float lenDirPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneX, localCoordinates); + float lenDirMinusPlaneX = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneX, localCoordinates); - float lenDirPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneY, localCoordinates)/ scale_factor; - float lenDirMinusPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneY, localCoordinates)/ scale_factor; - - std::cout << lenDir << " " << lenDirMinus << " " << lenDirPlaneX << " " << lenDirMinusPlaneX << " " << lenDirPlaneY << " " << lenDirMinusPlaneY << std::endl; + float lenDirPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirPlaneY, localCoordinates); + float lenDirMinusPlaneY = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirPlaneY, localCoordinates); // For readability bool & allowFlip = gContext.mAllowAxisFlip; float mulAxis = (allowFlip && lenDir < lenDirMinus&& fabsf(lenDir - lenDirMinus) > FLT_EPSILON) ? -1.f : 1.f; float mulAxisX = (allowFlip && lenDirPlaneX < lenDirMinusPlaneX&& fabsf(lenDirPlaneX - lenDirMinusPlaneX) > FLT_EPSILON) ? -1.f : 1.f; float mulAxisY = (allowFlip && lenDirPlaneY < lenDirMinusPlaneY&& fabsf(lenDirPlaneY - lenDirMinusPlaneY) > FLT_EPSILON) ? -1.f : 1.f; - dirAxis *= mulAxis; - dirPlaneX *= mulAxisX; - dirPlaneY *= mulAxisY; + dirAxis *= mulAxis / scale_factor; + dirPlaneX *= mulAxisX / scale_factor; + dirPlaneY *= mulAxisY / scale_factor; + + std::cout << gContext.mScreenFactor << std::endl; // for axis float axisLengthInClipSpace = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis * gContext.mScreenFactor, localCoordinates); From 439ed1e9b1867c98bfd8d2c55cce4829fd96b91c Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Tue, 28 Mar 2023 19:19:02 +0800 Subject: [PATCH 04/21] Update: update scaling --- ImGuizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 2eb14b94..238b2af3 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1150,7 +1150,7 @@ namespace IMGUIZMO_NAMESPACE else { // new method - float scale_factor = (gContext.mViewMat.m16)[0]; + float scale_factor = std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 0], std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 1], (gContext.mViewMat.m16)[axisIndex * 4 + 2])); float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates); float lenDirMinus = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirAxis, localCoordinates); From 0c95d606bbc385d752bf417900daff85d42e885e Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Tue, 28 Mar 2023 19:38:05 +0800 Subject: [PATCH 05/21] Add: control flag --- ImGuizmo.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 238b2af3..1d7e984f 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1150,7 +1150,12 @@ namespace IMGUIZMO_NAMESPACE else { // new method - float scale_factor = std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 0], std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 1], (gContext.mViewMat.m16)[axisIndex * 4 + 2])); + float scale_factor = 1.0f; + if (constancy == DISPLAY_CONST) + { + float scale_factor = std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 0], std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 1], (gContext.mViewMat.m16)[axisIndex * 4 + 2])); + } + float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates); float lenDirMinus = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), -dirAxis, localCoordinates); @@ -1169,8 +1174,6 @@ namespace IMGUIZMO_NAMESPACE dirPlaneX *= mulAxisX / scale_factor; dirPlaneY *= mulAxisY / scale_factor; - std::cout << gContext.mScreenFactor << std::endl; - // for axis float axisLengthInClipSpace = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis * gContext.mScreenFactor, localCoordinates); @@ -1227,7 +1230,7 @@ namespace IMGUIZMO_NAMESPACE return angle; } - static void DrawRotationGizmo(OPERATION op, int type) + static void DrawRotationGizmo(OPERATION op, int type, CONSTANCY constancy = SCALE_CONST) { if(!Intersects(op, ROTATE)) { @@ -1333,7 +1336,7 @@ namespace IMGUIZMO_NAMESPACE } } - static void DrawScaleGizmo(OPERATION op, int type) + static void DrawScaleGizmo(OPERATION op, int type, CONSTANCY constancy = SCALE_CONST) { ImDrawList* drawList = gContext.mDrawList; @@ -1365,7 +1368,7 @@ namespace IMGUIZMO_NAMESPACE { vec_t dirPlaneX, dirPlaneY, dirAxis; bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); + ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true, constancy); // draw axis if (belowAxisLimit) @@ -1421,7 +1424,7 @@ namespace IMGUIZMO_NAMESPACE } - static void DrawScaleUniveralGizmo(OPERATION op, int type) + static void DrawScaleUniveralGizmo(OPERATION op, int type, CONSTANCY constancy = SCALE_CONST) { ImDrawList* drawList = gContext.mDrawList; @@ -1453,7 +1456,7 @@ namespace IMGUIZMO_NAMESPACE { vec_t dirPlaneX, dirPlaneY, dirAxis; bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); + ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true, constancy); // draw axis if (belowAxisLimit) @@ -1505,7 +1508,7 @@ namespace IMGUIZMO_NAMESPACE } } - static void DrawTranslationGizmo(OPERATION op, int type, CONSTANCY constancy) + static void DrawTranslationGizmo(OPERATION op, int type, CONSTANCY constancy = SCALE_CONST) { ImDrawList* drawList = gContext.mDrawList; if (!drawList) @@ -1530,7 +1533,7 @@ namespace IMGUIZMO_NAMESPACE for (int i = 0; i < 3; ++i) { vec_t dirPlaneX, dirPlaneY, dirAxis; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit); + ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, false, constancy); if (!gContext.mbUsing || (gContext.mbUsing && type == MT_MOVE_X + i)) { @@ -2526,10 +2529,10 @@ namespace IMGUIZMO_NAMESPACE gContext.mOperation = operation; if (!gContext.mbUsingBounds) { - DrawRotationGizmo(operation, type); + DrawRotationGizmo(operation, type, constancy); DrawTranslationGizmo(operation, type, constancy); - DrawScaleGizmo(operation, type); - DrawScaleUniveralGizmo(operation, type); + DrawScaleGizmo(operation, type, constancy); + DrawScaleUniveralGizmo(operation, type, constancy); } return manipulated; } From 9473652edddde72fe8a0366fa122b90f90b59d94 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Tue, 28 Mar 2023 19:40:09 +0800 Subject: [PATCH 06/21] Bugfix: variable not set right --- ImGuizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 1d7e984f..54c48ac5 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1153,7 +1153,7 @@ namespace IMGUIZMO_NAMESPACE float scale_factor = 1.0f; if (constancy == DISPLAY_CONST) { - float scale_factor = std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 0], std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 1], (gContext.mViewMat.m16)[axisIndex * 4 + 2])); + scale_factor = std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 0], std::hypot((gContext.mViewMat.m16)[axisIndex * 4 + 1], (gContext.mViewMat.m16)[axisIndex * 4 + 2])); } float lenDir = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis, localCoordinates); From aafd84fc0cbad85bfa9228fa4374b0845b95b19a Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Wed, 29 Mar 2023 11:05:20 +0800 Subject: [PATCH 07/21] Update: selecting --- ImGuizmo.cpp | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 54c48ac5..cc0369b0 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -779,9 +779,9 @@ namespace IMGUIZMO_NAMESPACE /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // - static int GetMoveType(OPERATION op, vec_t* gizmoHitProportion); - static int GetRotateType(OPERATION op); - static int GetScaleType(OPERATION op); + static int GetMoveType(OPERATION op, vec_t* gizmoHitProportion, CONSTANCY constancy = SCALE_CONST); + static int GetRotateType(OPERATION op, CONSTANCY constancy = SCALE_CONST); + static int GetScaleType(OPERATION op, CONSTANCY constancy = SCALE_CONST); Style& GetStyle() { @@ -987,28 +987,28 @@ namespace IMGUIZMO_NAMESPACE return (gContext.mbUsing && (gContext.mActualID == -1 || gContext.mActualID == gContext.mEditingID)) || gContext.mbUsingBounds; } - bool IsOver() + bool IsOver(CONSTANCY constancy = SCALE_CONST) { - return (Intersects(gContext.mOperation, TRANSLATE) && GetMoveType(gContext.mOperation, NULL) != MT_NONE) || - (Intersects(gContext.mOperation, ROTATE) && GetRotateType(gContext.mOperation) != MT_NONE) || - (Intersects(gContext.mOperation, SCALE) && GetScaleType(gContext.mOperation) != MT_NONE) || IsUsing(); + return (Intersects(gContext.mOperation, TRANSLATE) && GetMoveType(gContext.mOperation, NULL, constancy) != MT_NONE) || + (Intersects(gContext.mOperation, ROTATE) && GetRotateType(gContext.mOperation, constancy) != MT_NONE) || + (Intersects(gContext.mOperation, SCALE) && GetScaleType(gContext.mOperation, constancy) != MT_NONE) || IsUsing(); } - bool IsOver(OPERATION op) + bool IsOver(OPERATION op, CONSTANCY constancy = SCALE_CONST) { if(IsUsing()) { return true; } - if(Intersects(op, SCALE) && GetScaleType(op) != MT_NONE) + if(Intersects(op, SCALE) && GetScaleType(op, constancy) != MT_NONE) { return true; } - if(Intersects(op, ROTATE) && GetRotateType(op) != MT_NONE) + if(Intersects(op, ROTATE) && GetRotateType(op, constancy) != MT_NONE) { return true; } - if(Intersects(op, TRANSLATE) && GetMoveType(op, NULL) != MT_NONE) + if(Intersects(op, TRANSLATE) && GetMoveType(op, NULL, constancy) != MT_NONE) { return true; } @@ -1613,7 +1613,7 @@ namespace IMGUIZMO_NAMESPACE return false; } - static void HandleAndDrawLocalBounds(const float* bounds, matrix_t* matrix, const float* snapValues, OPERATION operation) + static void HandleAndDrawLocalBounds(const float* bounds, matrix_t* matrix, const float* snapValues, OPERATION operation, CONSTANCY constancy = SCALE_CONST) { ImGuiIO& io = ImGui::GetIO(); ImDrawList* drawList = gContext.mDrawList; @@ -1733,15 +1733,15 @@ namespace IMGUIZMO_NAMESPACE if(Intersects(operation, TRANSLATE)) { - type = GetMoveType(operation, &gizmoHitProportion); + type = GetMoveType(operation, &gizmoHitProportion, constancy); } if(Intersects(operation, ROTATE) && type == MT_NONE) { - type = GetRotateType(operation); + type = GetRotateType(operation, constancy); } if(Intersects(operation, SCALE) && type == MT_NONE) { - type = GetScaleType(operation); + type = GetScaleType(operation, constancy); } if (type != MT_NONE) @@ -1877,7 +1877,7 @@ namespace IMGUIZMO_NAMESPACE /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // - static int GetScaleType(OPERATION op) + static int GetScaleType(OPERATION op, CONSTANCY constancy) { if (gContext.mbUsing) { @@ -1903,7 +1903,7 @@ namespace IMGUIZMO_NAMESPACE } vec_t dirPlaneX, dirPlaneY, dirAxis; bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); + ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true, constancy); dirAxis.TransformVector(gContext.mModelLocal); dirPlaneX.TransformVector(gContext.mModelLocal); dirPlaneY.TransformVector(gContext.mModelLocal); @@ -1943,7 +1943,7 @@ namespace IMGUIZMO_NAMESPACE vec_t dirPlaneX, dirPlaneY, dirAxis; bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); + ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true, constancy); // draw axis if (belowAxisLimit) @@ -1964,7 +1964,7 @@ namespace IMGUIZMO_NAMESPACE return type; } - static int GetRotateType(OPERATION op) + static int GetRotateType(OPERATION op, CONSTANCY constancy) { if (gContext.mbUsing) { @@ -2022,7 +2022,7 @@ namespace IMGUIZMO_NAMESPACE return type; } - static int GetMoveType(OPERATION op, vec_t* gizmoHitProportion) + static int GetMoveType(OPERATION op, vec_t* gizmoHitProportion, CONSTANCY constancy) { if(!Intersects(op, TRANSLATE) || gContext.mbUsing || !gContext.mbMouseOver) { @@ -2046,7 +2046,7 @@ namespace IMGUIZMO_NAMESPACE { vec_t dirPlaneX, dirPlaneY, dirAxis; bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit); + ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, false, constancy); dirAxis.TransformVector(gContext.mModel); dirPlaneX.TransformVector(gContext.mModel); dirPlaneY.TransformVector(gContext.mModel); @@ -2078,7 +2078,7 @@ namespace IMGUIZMO_NAMESPACE return type; } - static bool HandleTranslation(float* matrix, float* deltaMatrix, OPERATION op, int& type, const float* snap) + static bool HandleTranslation(float* matrix, float* deltaMatrix, OPERATION op, int& type, const float* snap, CONSTANCY constancy = SCALE_CONST) { if(!Intersects(op, TRANSLATE) || type != MT_NONE) { @@ -2163,7 +2163,7 @@ namespace IMGUIZMO_NAMESPACE { // find new possible way to move vec_t gizmoHitProportion; - type = GetMoveType(op, &gizmoHitProportion); + type = GetMoveType(op, &gizmoHitProportion, constancy); if (type != MT_NONE) { #if IMGUI_VERSION_NUM >= 18723 @@ -2200,7 +2200,7 @@ namespace IMGUIZMO_NAMESPACE return modified; } - static bool HandleScale(float* matrix, float* deltaMatrix, OPERATION op, int& type, const float* snap) + static bool HandleScale(float* matrix, float* deltaMatrix, OPERATION op, int& type, const float* snap, CONSTANCY constancy = SCALE_CONST) { if((!Intersects(op, SCALE) && !Intersects(op, SCALEU)) || type != MT_NONE || !gContext.mbMouseOver) { @@ -2212,7 +2212,7 @@ namespace IMGUIZMO_NAMESPACE if (!gContext.mbUsing) { // find new possible way to scale - type = GetScaleType(op); + type = GetScaleType(op, constancy); if (type != MT_NONE) { #if IMGUI_VERSION_NUM >= 18723 @@ -2321,7 +2321,7 @@ namespace IMGUIZMO_NAMESPACE return modified; } - static bool HandleRotation(float* matrix, float* deltaMatrix, OPERATION op, int& type, const float* snap) + static bool HandleRotation(float* matrix, float* deltaMatrix, OPERATION op, int& type, const float* snap, CONSTANCY constancy = SCALE_CONST) { if(!Intersects(op, ROTATE) || type != MT_NONE || !gContext.mbMouseOver) { @@ -2333,7 +2333,7 @@ namespace IMGUIZMO_NAMESPACE if (!gContext.mbUsing) { - type = GetRotateType(op); + type = GetRotateType(op, constancy); if (type != MT_NONE) { @@ -2515,15 +2515,15 @@ namespace IMGUIZMO_NAMESPACE { if (!gContext.mbUsingBounds) { - manipulated = HandleTranslation(matrix, deltaMatrix, operation, type, snap) || - HandleScale(matrix, deltaMatrix, operation, type, snap) || - HandleRotation(matrix, deltaMatrix, operation, type, snap); + manipulated = HandleTranslation(matrix, deltaMatrix, operation, type, snap, constancy) || + HandleScale(matrix, deltaMatrix, operation, type, snap, constancy) || + HandleRotation(matrix, deltaMatrix, operation, type, snap, constancy); } } if (localBounds && !gContext.mbUsing) { - HandleAndDrawLocalBounds(localBounds, (matrix_t*)matrix, boundsSnap, operation); + HandleAndDrawLocalBounds(localBounds, (matrix_t*)matrix, boundsSnap, operation, constancy); } gContext.mOperation = operation; From 54caff96d6f6d13cda56d4b3c000ff495aac4844 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Wed, 29 Mar 2023 17:56:32 +0800 Subject: [PATCH 08/21] Update: debug --- ImGuizmo.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index cc0369b0..b6cb123d 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2065,6 +2065,12 @@ namespace IMGUIZMO_NAMESPACE const float dx = dirPlaneX.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); const float dy = dirPlaneY.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); + + std::cout << dirPlaneX.x << " " << dirPlaneX.y << " " << dirPlaneX.z << std::endl; + std::cout << dirPlaneY.x << " " << dirPlaneY.y << " " << dirPlaneY.z << std::endl; + std::cout <<(posOnPlan - gContext.mModel.v.position).x << " " << (posOnPlan - gContext.mModel.v.position).y << " " << (posOnPlan - gContext.mModel.v.position).z << std::endl; + std::cout << dx << " " << dy << std::endl << "---------" << std::endl; + if (belowPlaneLimit && dx >= quadUV[0] && dx <= quadUV[4] && dy >= quadUV[1] && dy <= quadUV[3] && Contains(op, TRANSLATE_PLANS[i])) { type = MT_MOVE_YZ + i; From de71341bb2fd6d872b6dbef41ad112363f1cab5b Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Wed, 29 Mar 2023 18:19:25 +0800 Subject: [PATCH 09/21] Update: axis --- ImGuizmo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index b6cb123d..48a967a7 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2063,8 +2063,8 @@ namespace IMGUIZMO_NAMESPACE type = MT_MOVE_X + i; } - const float dx = dirPlaneX.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); - const float dy = dirPlaneY.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); + const float dx = dirPlaneX.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); + const float dy = dirPlaneY.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); std::cout << dirPlaneX.x << " " << dirPlaneX.y << " " << dirPlaneX.z << std::endl; std::cout << dirPlaneY.x << " " << dirPlaneY.y << " " << dirPlaneY.z << std::endl; From f50ef53c82d953cbd76f3b45d45d9d03c90d43ae Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Wed, 29 Mar 2023 18:23:33 +0800 Subject: [PATCH 10/21] update: ratio --- ImGuizmo.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 48a967a7..6beb3a66 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2063,8 +2063,10 @@ namespace IMGUIZMO_NAMESPACE type = MT_MOVE_X + i; } - const float dx = dirPlaneX.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); - const float dy = dirPlaneY.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); + float ratio_x = dirPlaneX.Length(); + float ratio_y = dirPlaneY.Length(); + const float dx = dirPlaneX.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / (gContext.mScreenFactor * ratio_x))); + const float dy = dirPlaneY.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / (gContext.mScreenFactor * ratio_y))); std::cout << dirPlaneX.x << " " << dirPlaneX.y << " " << dirPlaneX.z << std::endl; std::cout << dirPlaneY.x << " " << dirPlaneY.y << " " << dirPlaneY.z << std::endl; From c3aa496a4362ac37ae6cefd58926c03668b1efeb Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Wed, 29 Mar 2023 18:27:13 +0800 Subject: [PATCH 11/21] Update: set correct place for selecting plane --- ImGuizmo.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 6beb3a66..bc2e7e08 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2063,16 +2063,12 @@ namespace IMGUIZMO_NAMESPACE type = MT_MOVE_X + i; } + // Reverse the ratio of dirPlane by 1 so that selected point could be at the right place. float ratio_x = dirPlaneX.Length(); float ratio_y = dirPlaneY.Length(); - const float dx = dirPlaneX.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / (gContext.mScreenFactor * ratio_x))); - const float dy = dirPlaneY.Normalize().Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / (gContext.mScreenFactor * ratio_y))); + const float dx = dirPlaneX.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / (gContext.mScreenFactor * ratio_x * ratio_x))); + const float dy = dirPlaneY.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / (gContext.mScreenFactor * ratio_y * ratio_y))); - std::cout << dirPlaneX.x << " " << dirPlaneX.y << " " << dirPlaneX.z << std::endl; - std::cout << dirPlaneY.x << " " << dirPlaneY.y << " " << dirPlaneY.z << std::endl; - std::cout <<(posOnPlan - gContext.mModel.v.position).x << " " << (posOnPlan - gContext.mModel.v.position).y << " " << (posOnPlan - gContext.mModel.v.position).z << std::endl; - std::cout << dx << " " << dy << std::endl << "---------" << std::endl; - if (belowPlaneLimit && dx >= quadUV[0] && dx <= quadUV[4] && dy >= quadUV[1] && dy <= quadUV[3] && Contains(op, TRANSLATE_PLANS[i])) { type = MT_MOVE_YZ + i; From 612511df1c35a71dc9e075afe58dea90fa50480e Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 17:46:30 +0800 Subject: [PATCH 12/21] Update: rotation drawing --- ImGuizmo.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index bc2e7e08..64fb34ad 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1268,6 +1268,12 @@ namespace IMGUIZMO_NAMESPACE const bool usingAxis = (gContext.mbUsing && type == MT_ROTATE_Z - axis); const int circleMul = (hasRSC && !usingAxis ) ? 1 : 2; + float scale_factor = 1.0f; + if (constancy == DISPLAY_CONST) + { + scale_factor = std::hypot((gContext.mViewMat.m16)[axis * 4 + 0], std::hypot((gContext.mViewMat.m16)[axis * 4 + 1], (gContext.mViewMat.m16)[axis * 4 + 2])); + } + ImVec2* circlePos = (ImVec2*)alloca(sizeof(ImVec2) * (circleMul * halfCircleSegmentCount + 1)); float angleStart = atan2f(cameraToModelNormalized[(4 - axis) % 3], cameraToModelNormalized[(3 - axis) % 3]) + ZPI * 0.5f; @@ -1275,7 +1281,7 @@ namespace IMGUIZMO_NAMESPACE for (int i = 0; i < circleMul * halfCircleSegmentCount + 1; i++) { float ng = angleStart + (float)circleMul * ZPI * ((float)i / (float)halfCircleSegmentCount); - vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f); + vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f) * scale_factor; vec_t pos = makeVect(axisPos[axis], axisPos[(axis + 1) % 3], axisPos[(axis + 2) % 3]) * gContext.mScreenFactor * rotationDisplayFactor; circlePos[i] = worldToPos(pos, gContext.mMVP); } From 078c0efd6e28fb45ead42750a590b898f50840ef Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 17:50:53 +0800 Subject: [PATCH 13/21] Bugfix: symbol not correct --- ImGuizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 64fb34ad..563045fa 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1281,7 +1281,7 @@ namespace IMGUIZMO_NAMESPACE for (int i = 0; i < circleMul * halfCircleSegmentCount + 1; i++) { float ng = angleStart + (float)circleMul * ZPI * ((float)i / (float)halfCircleSegmentCount); - vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f) * scale_factor; + vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f) / scale_factor; vec_t pos = makeVect(axisPos[axis], axisPos[(axis + 1) % 3], axisPos[(axis + 2) % 3]) * gContext.mScreenFactor * rotationDisplayFactor; circlePos[i] = worldToPos(pos, gContext.mMVP); } From 0d5f16507db3d3ca9a996e588fc8926b605f25ae Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 17:52:06 +0800 Subject: [PATCH 14/21] Bugfix: symbol not exist --- ImGuizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 563045fa..d089effe 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -1281,7 +1281,7 @@ namespace IMGUIZMO_NAMESPACE for (int i = 0; i < circleMul * halfCircleSegmentCount + 1; i++) { float ng = angleStart + (float)circleMul * ZPI * ((float)i / (float)halfCircleSegmentCount); - vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f) / scale_factor; + vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f) * (1.0f / scale_factor); vec_t pos = makeVect(axisPos[axis], axisPos[(axis + 1) % 3], axisPos[(axis + 2) % 3]) * gContext.mScreenFactor * rotationDisplayFactor; circlePos[i] = worldToPos(pos, gContext.mMVP); } From 284f8baf97576be2a58d28295204050cd4e2cf28 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 17:56:53 +0800 Subject: [PATCH 15/21] Update: debug --- ImGuizmo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index d089effe..890477d1 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2017,6 +2017,7 @@ namespace IMGUIZMO_NAMESPACE //gContext.mDrawList->AddCircle(idealPosOnCircleScreen, 5.f, IM_COL32_WHITE); const ImVec2 distanceOnScreen = idealPosOnCircleScreen - io.MousePos; + std::cout << distanceOnScreen.x << " " << distanceOnScreen.y << std::endl; const float distance = makeVect(distanceOnScreen).Length(); if (distance < 8.f) // pixel size From 699b81541cd309db805f129f43fe304f45e52bc0 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 18:04:07 +0800 Subject: [PATCH 16/21] update: debugs --- ImGuizmo.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 890477d1..c466de21 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2017,9 +2017,15 @@ namespace IMGUIZMO_NAMESPACE //gContext.mDrawList->AddCircle(idealPosOnCircleScreen, 5.f, IM_COL32_WHITE); const ImVec2 distanceOnScreen = idealPosOnCircleScreen - io.MousePos; - std::cout << distanceOnScreen.x << " " << distanceOnScreen.y << std::endl; - const float distance = makeVect(distanceOnScreen).Length(); + float scale_factor = 1.0f; + if (constancy == DISPLAY_CONST) + { + scale_factor = std::hypot((gContext.mViewMat.m16)[i * 4 + 0], std::hypot((gContext.mViewMat.m16)[i * 4 + 1], (gContext.mViewMat.m16)[i * 4 + 2])); + } + + const float distance = makeVect(distanceOnScreen).Length() / (scale_factor * scale_factor); + std::cout << distance << std::endl; if (distance < 8.f) // pixel size { type = MT_ROTATE_X + i; From 1a113afaa0a2f5c6c01ed1d1701715548218874c Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 18:06:19 +0800 Subject: [PATCH 17/21] Update: scaling --- ImGuizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index c466de21..807f4645 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2024,7 +2024,7 @@ namespace IMGUIZMO_NAMESPACE scale_factor = std::hypot((gContext.mViewMat.m16)[i * 4 + 0], std::hypot((gContext.mViewMat.m16)[i * 4 + 1], (gContext.mViewMat.m16)[i * 4 + 2])); } - const float distance = makeVect(distanceOnScreen).Length() / (scale_factor * scale_factor); + const float distance = makeVect(distanceOnScreen).Length() * scale_factor; std::cout << distance << std::endl; if (distance < 8.f) // pixel size { From 90e9369ab0e36b3562b6f3c1c87f323a607e3a86 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 18:08:16 +0800 Subject: [PATCH 18/21] Update: Debug --- ImGuizmo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 807f4645..6f575870 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2024,7 +2024,7 @@ namespace IMGUIZMO_NAMESPACE scale_factor = std::hypot((gContext.mViewMat.m16)[i * 4 + 0], std::hypot((gContext.mViewMat.m16)[i * 4 + 1], (gContext.mViewMat.m16)[i * 4 + 2])); } - const float distance = makeVect(distanceOnScreen).Length() * scale_factor; + const float distance = makeVect(distanceOnScreen).Length(); std::cout << distance << std::endl; if (distance < 8.f) // pixel size { From 04cd00b2a4c1ab9647bd44b367c8f9cf1e0fd7bd Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 18:10:57 +0800 Subject: [PATCH 19/21] Update: debug --- ImGuizmo.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 6f575870..17141950 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -2010,22 +2010,21 @@ namespace IMGUIZMO_NAMESPACE continue; } + float scale_factor = 1.0f; + if (constancy == DISPLAY_CONST) + { + scale_factor = std::hypot((gContext.mViewMat.m16)[i * 4 + 0], std::hypot((gContext.mViewMat.m16)[i * 4 + 1], (gContext.mViewMat.m16)[i * 4 + 2])); + } + const vec_t localPos = intersectWorldPos - gContext.mModel.v.position; vec_t idealPosOnCircle = Normalized(localPos); idealPosOnCircle.TransformVector(gContext.mModelInverse); - const ImVec2 idealPosOnCircleScreen = worldToPos(idealPosOnCircle * rotationDisplayFactor * gContext.mScreenFactor, gContext.mMVP); + const ImVec2 idealPosOnCircleScreen = worldToPos(idealPosOnCircle * rotationDisplayFactor * gContext.mScreenFactor * (1.0f / scale_factor), gContext.mMVP); //gContext.mDrawList->AddCircle(idealPosOnCircleScreen, 5.f, IM_COL32_WHITE); const ImVec2 distanceOnScreen = idealPosOnCircleScreen - io.MousePos; - float scale_factor = 1.0f; - if (constancy == DISPLAY_CONST) - { - scale_factor = std::hypot((gContext.mViewMat.m16)[i * 4 + 0], std::hypot((gContext.mViewMat.m16)[i * 4 + 1], (gContext.mViewMat.m16)[i * 4 + 2])); - } - const float distance = makeVect(distanceOnScreen).Length(); - std::cout << distance << std::endl; if (distance < 8.f) // pixel size { type = MT_ROTATE_X + i; From f82528de57ae83d5a646b9b856b46b12331e76c1 Mon Sep 17 00:00:00 2001 From: yuchenliu Date: Thu, 30 Mar 2023 18:12:26 +0800 Subject: [PATCH 20/21] Update: remove debugs --- ImGuizmo.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 17141950..19d82354 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -24,8 +24,6 @@ // SOFTWARE. // -#include - #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif From c926ed32e653a8f6f0c77fd6dcca8853291d346d Mon Sep 17 00:00:00 2001 From: Feej <33738007+yc-feej@users.noreply.github.com> Date: Wed, 12 Jul 2023 00:30:55 +0000 Subject: [PATCH 21/21] Update interface --- ImGuizmo.cpp | 4 ++-- ImGuizmo.h | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ImGuizmo.cpp b/ImGuizmo.cpp index 19d82354..a74c303f 100755 --- a/ImGuizmo.cpp +++ b/ImGuizmo.cpp @@ -985,14 +985,14 @@ namespace IMGUIZMO_NAMESPACE return (gContext.mbUsing && (gContext.mActualID == -1 || gContext.mActualID == gContext.mEditingID)) || gContext.mbUsingBounds; } - bool IsOver(CONSTANCY constancy = SCALE_CONST) + bool IsOver(CONSTANCY constancy) { return (Intersects(gContext.mOperation, TRANSLATE) && GetMoveType(gContext.mOperation, NULL, constancy) != MT_NONE) || (Intersects(gContext.mOperation, ROTATE) && GetRotateType(gContext.mOperation, constancy) != MT_NONE) || (Intersects(gContext.mOperation, SCALE) && GetScaleType(gContext.mOperation, constancy) != MT_NONE) || IsUsing(); } - bool IsOver(OPERATION op, CONSTANCY constancy = SCALE_CONST) + bool IsOver(OPERATION op, CONSTANCY constancy) { if(IsUsing()) { diff --git a/ImGuizmo.h b/ImGuizmo.h index 35b9662b..f162ed08 100644 --- a/ImGuizmo.h +++ b/ImGuizmo.h @@ -117,6 +117,12 @@ void EditTransform(const Camera& camera, matrix_t& matrix) namespace IMGUIZMO_NAMESPACE { + enum CONSTANCY + { + SCALE_CONST = (1u << 0), + DISPLAY_CONST + }; + // call inside your own window and before Manipulate() in order to draw gizmo to that window. // Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()). IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr); @@ -131,7 +137,7 @@ namespace IMGUIZMO_NAMESPACE IMGUI_API void SetImGuiContext(ImGuiContext* ctx); // return true if mouse cursor is over any gizmo control (axis, plan or screen component) - IMGUI_API bool IsOver(); + IMGUI_API bool IsOver(CONSTANCY constancy = SCALE_CONST); // return true if mouse IsOver or if the gizmo is in moving state IMGUI_API bool IsUsing(); @@ -202,12 +208,6 @@ namespace IMGUIZMO_NAMESPACE WORLD }; - enum CONSTANCY - { - SCALE_CONST = (1u << 0), - DISPLAY_CONST - }; - IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL, CONSTANCY constancy = SCALE_CONST); // // Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en @@ -222,7 +222,7 @@ namespace IMGUIZMO_NAMESPACE IMGUI_API void SetID(int id); // return true if the cursor is over the operation's gizmo - IMGUI_API bool IsOver(OPERATION op); + IMGUI_API bool IsOver(OPERATION op, CONSTANCY constancy = SCALE_CONST); IMGUI_API void SetGizmoSizeClipSpace(float value); // Allow axis to flip