Updated ImGuizmo.
This commit is contained in:
parent
5cc3d866d7
commit
b88b9b89e2
5
3rdparty/ocornut-imgui/widgets/gizmo.h
vendored
5
3rdparty/ocornut-imgui/widgets/gizmo.h
vendored
@ -96,7 +96,8 @@ void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||
break;
|
||||
}
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||
}
|
||||
#endif
|
||||
@ -132,6 +133,8 @@ namespace ImGuizmo
|
||||
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 SetRect(float x, float y, float width, float height);
|
||||
|
||||
// Render a cube with face color corresponding to face normal. Usefull for debug/tests
|
||||
void DrawCube(const float *view, const float *projection, float *matrix);
|
||||
|
||||
|
50
3rdparty/ocornut-imgui/widgets/gizmo.inl
vendored
50
3rdparty/ocornut-imgui/widgets/gizmo.inl
vendored
@ -20,12 +20,19 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
// includes patches for multiview from
|
||||
// https://github.com/CedricGuillemet/ImGuizmo/issues/15
|
||||
|
||||
namespace ImGuizmo
|
||||
{
|
||||
static const float ZPI = 3.14159265358979323846f;
|
||||
static const float RAD2DEG = (180.f / ZPI);
|
||||
static const float DEG2RAD = (ZPI / 180.f);
|
||||
|
||||
const float screenRotateSize = 0.06f;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// utility and math
|
||||
|
||||
@ -551,9 +558,13 @@ namespace ImGuizmo
|
||||
bool mbUsingBounds;
|
||||
matrix_t mBoundsMatrix;
|
||||
|
||||
|
||||
//
|
||||
int mCurrentOperation;
|
||||
|
||||
float mX = 0.f;
|
||||
float mY = 0.f;
|
||||
float mWidth = 0.f;
|
||||
float mHeight = 0.f;
|
||||
};
|
||||
|
||||
static Context gContext;
|
||||
@ -584,16 +595,16 @@ namespace ImGuizmo
|
||||
|
||||
static ImVec2 worldToPos(const vec_t& worldPos, const matrix_t& mat)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
vec_t trans;
|
||||
trans.TransformPoint(worldPos, mat);
|
||||
trans *= 0.5f / trans.w;
|
||||
trans += makeVect(0.5f, 0.5f);
|
||||
trans.y = 1.f - trans.y;
|
||||
trans.x *= io.DisplaySize.x;
|
||||
trans.y *= io.DisplaySize.y;
|
||||
return ImVec2(trans.x, trans.y);
|
||||
trans.x *= gContext.mWidth;
|
||||
trans.y *= gContext.mHeight;
|
||||
trans.x += gContext.mX;
|
||||
trans.y += gContext.mY;
|
||||
return ImVec2(trans.x, trans.y);
|
||||
}
|
||||
|
||||
static void ComputeCameraRay(vec_t &rayOrigin, vec_t &rayDir)
|
||||
@ -603,9 +614,9 @@ namespace ImGuizmo
|
||||
matrix_t mViewProjInverse;
|
||||
mViewProjInverse.Inverse(gContext.mViewMat * gContext.mProjectionMat);
|
||||
|
||||
float mox = (io.MousePos.x / io.DisplaySize.x) * 2.f - 1.f;
|
||||
float moy = (1.f - (io.MousePos.y / io.DisplaySize.y)) * 2.f - 1.f;
|
||||
|
||||
float mox = ((io.MousePos.x - gContext.mX) / gContext.mWidth) * 2.f - 1.f;
|
||||
float moy = (1.f - ((io.MousePos.y - gContext.mY) / gContext.mHeight)) * 2.f - 1.f;
|
||||
|
||||
rayOrigin.Transform(makeVect(mox, moy, 0.f, 1.f), mViewProjInverse);
|
||||
rayOrigin *= 1.f / rayOrigin.w;
|
||||
vec_t rayEnd;
|
||||
@ -625,12 +636,21 @@ namespace ImGuizmo
|
||||
return -(numer / denom);
|
||||
}
|
||||
|
||||
void SetRect(float x, float y, float width, float height)
|
||||
{
|
||||
gContext.mX = x;
|
||||
gContext.mY = y;
|
||||
gContext.mWidth = width;
|
||||
gContext.mHeight = height;
|
||||
}
|
||||
|
||||
void BeginFrame()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui::Begin("gizmo", NULL, io.DisplaySize, 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||
gContext.mDrawList = ImGui::GetWindowDrawList();
|
||||
|
||||
gContext.mDrawList = ImGui::GetWindowDrawList();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
@ -726,6 +746,8 @@ namespace ImGuizmo
|
||||
for (int i = 0; i < 3; i++)
|
||||
colors[i + 1] = (type == (int)(SCALE_X + i)) ? selectionColor : directionColor[i];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -821,7 +843,6 @@ namespace ImGuizmo
|
||||
static void DrawRotationGizmo(int type)
|
||||
{
|
||||
ImDrawList* drawList = gContext.mDrawList;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// colors
|
||||
ImU32 colors[7];
|
||||
@ -845,7 +866,7 @@ namespace ImGuizmo
|
||||
}
|
||||
drawList->AddPolyline(circlePos, halfCircleSegmentCount, colors[3 - axis], false, 2, true);
|
||||
}
|
||||
drawList->AddCircle(worldToPos(gContext.mModel.v.position, gContext.mViewProjection), 0.06f * io.DisplaySize.x, colors[0], 64);
|
||||
drawList->AddCircle(worldToPos(gContext.mModel.v.position, gContext.mViewProjection), screenRotateSize * gContext.mHeight, colors[0], 64);
|
||||
|
||||
if (gContext.mbUsing)
|
||||
{
|
||||
@ -951,6 +972,8 @@ namespace ImGuizmo
|
||||
static void DrawTranslationGizmo(int type)
|
||||
{
|
||||
ImDrawList* drawList = gContext.mDrawList;
|
||||
if (!drawList)
|
||||
return;
|
||||
|
||||
// colors
|
||||
ImU32 colors[7];
|
||||
@ -1226,7 +1249,7 @@ namespace ImGuizmo
|
||||
|
||||
vec_t deltaScreen = { io.MousePos.x - gContext.mScreenSquareCenter.x, io.MousePos.y - gContext.mScreenSquareCenter.y, 0.f, 0.f };
|
||||
float dist = deltaScreen.Length();
|
||||
if (dist >= 0.058f * io.DisplaySize.x && dist < 0.062f * io.DisplaySize.x)
|
||||
if (dist >= (screenRotateSize - 0.002f) * gContext.mHeight && dist < (screenRotateSize + 0.002f) * gContext.mHeight)
|
||||
type = ROTATE_SCREEN;
|
||||
|
||||
const vec_t planNormals[] = { gContext.mModel.v.right, gContext.mModel.v.up, gContext.mModel.v.dir};
|
||||
@ -1688,3 +1711,4 @@ namespace ImGuizmo
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -105,7 +105,7 @@ struct Emitter
|
||||
psUpdateEmitter(m_handle, &m_uniforms);
|
||||
}
|
||||
|
||||
void imgui(const float* _view, const float* _proj)
|
||||
void imgui()
|
||||
{
|
||||
// if (ImGui::CollapsingHeader("General") )
|
||||
{
|
||||
@ -197,9 +197,10 @@ struct Emitter
|
||||
ImGui::ColorEdit4("RGBA3", &m_uniforms.m_rgba[3], true);
|
||||
ImGui::ColorEdit4("RGBA4", &m_uniforms.m_rgba[4], true);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
void gizmo(const float* _view, const float* _proj)
|
||||
{
|
||||
float mtx[16];
|
||||
bx::mtxSRT(mtx
|
||||
, 1.0f, 1.0f, 1.0f
|
||||
@ -207,6 +208,9 @@ struct Emitter
|
||||
, m_uniforms.m_position[0], m_uniforms.m_position[1], m_uniforms.m_position[2]
|
||||
);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
|
||||
ImGuizmo::Manipulate(
|
||||
_view
|
||||
, _proj
|
||||
@ -388,7 +392,11 @@ class Particles : public entry::AppI
|
||||
ImGui::RadioButton(name, ¤tEmitter, ii);
|
||||
}
|
||||
|
||||
m_emitter[currentEmitter].imgui(view, proj);
|
||||
m_emitter[currentEmitter].imgui();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
m_emitter[currentEmitter].gizmo(view, proj);
|
||||
|
||||
imguiEndFrame();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user