PeriDyno 1.0.0
Loading...
Searching...
No Matches
ImGuizmo.h
Go to the documentation of this file.
1// https://github.com/CedricGuillemet/ImGuizmo
2// v 1.83
3//
4// The MIT License(MIT)
5//
6// Copyright(c) 2021 Cedric Guillemet
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files(the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions :
14//
15// The above copyright notice and this permission notice shall be included in all
16// copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24// SOFTWARE.
25//
26// -------------------------------------------------------------------------------------------
27// History :
28// 2019/11/03 View gizmo
29// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode.
30// 2016/09/09 Hatched negative axis. Snapping. Documentation update.
31// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved
32// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results.
33// 2016/08/31 First version
34//
35// -------------------------------------------------------------------------------------------
36// Future (no order):
37//
38// - Multi view
39// - display rotation/translation/scale infos in local/world space and not only local
40// - finish local/world matrix application
41// - OPERATION as bitmask
42//
43// -------------------------------------------------------------------------------------------
44// Example
45#if 0
46void EditTransform(const Camera& camera, matrix_t& matrix)
47{
48 static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
49 static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
50 if (ImGui::IsKeyPressed(90))
51 mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
52 if (ImGui::IsKeyPressed(69))
53 mCurrentGizmoOperation = ImGuizmo::ROTATE;
54 if (ImGui::IsKeyPressed(82)) // r Key
55 mCurrentGizmoOperation = ImGuizmo::SCALE;
56 if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
57 mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
58 ImGui::SameLine();
59 if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
60 mCurrentGizmoOperation = ImGuizmo::ROTATE;
61 ImGui::SameLine();
62 if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
63 mCurrentGizmoOperation = ImGuizmo::SCALE;
64 float matrixTranslation[3], matrixRotation[3], matrixScale[3];
65 ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
66 ImGui::InputFloat3("Tr", matrixTranslation, 3);
67 ImGui::InputFloat3("Rt", matrixRotation, 3);
68 ImGui::InputFloat3("Sc", matrixScale, 3);
69 ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
70
71 if (mCurrentGizmoOperation != ImGuizmo::SCALE)
72 {
73 if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
74 mCurrentGizmoMode = ImGuizmo::LOCAL;
75 ImGui::SameLine();
76 if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
77 mCurrentGizmoMode = ImGuizmo::WORLD;
78 }
79 static bool useSnap(false);
80 if (ImGui::IsKeyPressed(83))
81 useSnap = !useSnap;
82 ImGui::Checkbox("", &useSnap);
83 ImGui::SameLine();
84 vec_t snap;
85 switch (mCurrentGizmoOperation)
86 {
88 snap = config.mSnapTranslation;
89 ImGui::InputFloat3("Snap", &snap.x);
90 break;
92 snap = config.mSnapRotation;
93 ImGui::InputFloat("Angle Snap", &snap.x);
94 break;
95 case ImGuizmo::SCALE:
96 snap = config.mSnapScale;
97 ImGui::InputFloat("Scale Snap", &snap.x);
98 break;
99 }
100 ImGuiIO& io = ImGui::GetIO();
101 ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
102 ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
103}
104#endif
105#pragma once
106
107#ifdef USE_IMGUI_API
108#include "imconfig.h"
109#endif
110#ifndef IMGUI_API
111#define IMGUI_API
112#endif
113
114namespace ImGuizmo
115{
116 // call inside your own window and before Manipulate() in order to draw gizmo to that window.
117 // Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()).
118 IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr);
119
120 // call BeginFrame right after ImGui_XXXX_NewFrame();
121 IMGUI_API void BeginFrame();
122
123 // this is necessary because when imguizmo is compiled into a dll, and imgui into another
124 // globals are not shared between them.
125 // More details at https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam
126 // expose method to set imgui context
127 IMGUI_API void SetImGuiContext(ImGuiContext* ctx);
128
129 // return true if mouse cursor is over any gizmo control (axis, plan or screen component)
130 IMGUI_API bool IsOver();
131
132 // return true if mouse IsOver or if the gizmo is in moving state
133 IMGUI_API bool IsUsing();
134
135 // enable/disable the gizmo. Stay in the state until next call to Enable.
136 // gizmo is rendered with gray half transparent color when disabled
137 IMGUI_API void Enable(bool enable);
138
139 // helper functions for manualy editing translation/rotation/scale with an input float
140 // translation, rotation and scale float points to 3 floats each
141 // Angles are in degrees (more suitable for human editing)
142 // example:
143 // float matrixTranslation[3], matrixRotation[3], matrixScale[3];
144 // ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
145 // ImGui::InputFloat3("Tr", matrixTranslation, 3);
146 // ImGui::InputFloat3("Rt", matrixRotation, 3);
147 // ImGui::InputFloat3("Sc", matrixScale, 3);
148 // ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
149 //
150 // These functions have some numerical stability issues for now. Use with caution.
151 IMGUI_API void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale);
152 IMGUI_API void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix);
153
154 IMGUI_API void SetRect(float x, float y, float width, float height);
155 // default is false
156 IMGUI_API void SetOrthographic(bool isOrthographic);
157
158 // Render a cube with face color corresponding to face normal. Usefull for debug/tests
159 IMGUI_API void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount);
160 IMGUI_API void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize);
161
162 // call it when you want a gizmo
163 // Needs view and projection matrices.
164 // matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional
165 // translation is applied in world space
167 {
168 TRANSLATE_X = (1u << 0),
169 TRANSLATE_Y = (1u << 1),
170 TRANSLATE_Z = (1u << 2),
171 ROTATE_X = (1u << 3),
172 ROTATE_Y = (1u << 4),
173 ROTATE_Z = (1u << 5),
174 ROTATE_SCREEN = (1u << 6),
175 SCALE_X = (1u << 7),
176 SCALE_Y = (1u << 8),
177 SCALE_Z = (1u << 9),
178 BOUNDS = (1u << 10),
182 };
183
185 {
186 return static_cast<OPERATION>(static_cast<int>(lhs) | static_cast<int>(rhs));
187 }
188
189 enum MODE
190 {
193 };
194
195 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);
196 //
197 // Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
198 // It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
199 // other software are using the same mechanics. But just in case, you are now warned!
200 //
201 IMGUI_API void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
202
203 IMGUI_API void SetID(int id);
204
205 // return true if the cursor is over the operation's gizmo
206 IMGUI_API bool IsOver(OPERATION op);
207 IMGUI_API void SetGizmoSizeClipSpace(float value);
208
209 // Allow axis to flip
210 // When true (default), the guizmo axis flip for better visibility
211 // When false, they always stay along the positive world/local axis
212 IMGUI_API void AllowAxisFlip(bool value);
213}
#define IMGUI_API
Definition ImGuizmo.h:111
void SetGizmoSizeClipSpace(float value)
bool IsOver()
Definition ImGuizmo.cpp:941
void SetRect(float x, float y, float width, float height)
Definition ImGuizmo.cpp:886
void SetID(int id)
void AllowAxisFlip(bool 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)
@ TRANSLATE_Y
Definition ImGuizmo.h:169
@ ROTATE_SCREEN
Definition ImGuizmo.h:174
@ TRANSLATE
Definition ImGuizmo.h:179
@ TRANSLATE_Z
Definition ImGuizmo.h:170
@ TRANSLATE_X
Definition ImGuizmo.h:168
void SetImGuiContext(ImGuiContext *ctx)
Definition ImGuizmo.cpp:907
bool IsUsing()
Definition ImGuizmo.cpp:936
void SetOrthographic(bool isOrthographic)
Definition ImGuizmo.cpp:897
void Enable(bool enable)
Definition ImGuizmo.cpp:969
void DrawCubes(const float *view, const float *projection, const float *matrices, int matrixCount)
void DrawGrid(const float *view, const float *projection, const float *matrix, const float gridSize)
OPERATION operator|(OPERATION lhs, OPERATION rhs)
Definition ImGuizmo.h:184
void BeginFrame()
Definition ImGuizmo.cpp:912
void DecomposeMatrixToComponents(const float *matrix, float *translation, float *rotation, float *scale)
void RecomposeMatrixFromComponents(const float *translation, const float *rotation, const float *scale, float *matrix)
void SetDrawlist(ImDrawList *drawlist)
Definition ImGuizmo.cpp:902
void ViewManipulate(float *view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor)