Open volcoma opened 8 years ago
I had to do much the same to avoid the gizmo stretching strangely when resizing panels. x, y, w, h all need to correspond to the pane, not the window to work properly in a multi-panel UI.
I second the vote to have an API for this.
I'm a bit overwhelm at the moment but you can submit a PR with the modifications
Here you go ~ it's my interpretation of what @volcoma said in the original post. I call SetRect just before Manipulate. https://github.com/CedricGuillemet/ImGuizmo/pull/23
e.g.
auto origin = gui::GetItemRectMin();
auto sz = gui::GetItemRectSize();
ImGuizmo::SetRect(origin.x, origin.y, sz.x, sz.y);
...
ImGuizmo::Manipulate(...
(PS, and thanks again for your lovely library :) )
I believe i have a working multi view version which handles drawing the gizmos in any sized window anywhere on the screen . I suggest change of BeginFrame to SetViewRect
void SetViewRect(float x, float y, float width, float height) { //ImGui::Begin("gizmo", NULL, ImVec2(width, height), 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus); // this should be optional gContext.mX = x; gContext.mY = y; gContext.mWidth = width; gContext.mHeight = height; gContext.mDrawList = ImGui::GetWindowDrawList(); //ImGui::End() this should be optional }
then replace most of the places that used io.DisplaySize with the width and height.In worldToPos function
trans.x *= gContext.mWidth; trans.y *= gContext.mHeight; trans.x += gContext.mX; trans.y += gContext.mY;
In ComputeCameraRay function
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;
In DrawRotationGizmo function
drawList->AddCircle(worldToPos(gContext.mModel.v.position, gContext.mViewProjection), 0.06f * gContext.mWidth, colors[0], 64);
In GetRotateType function
if (dist >= 0.058f * gContext.mWidth && dist < 0.062f * gContext.mWidth) type = ROTATE_SCREEN;
thats pretty much it.