diff --git a/implot3d.cpp b/implot3d.cpp index d1dc73a..69b8ee2 100644 --- a/implot3d.cpp +++ b/implot3d.cpp @@ -987,7 +987,7 @@ void ComputeBoxCorners(ImPlot3DPoint* corners, const ImPlot3DPoint& range_min, c // Convert a position in the plot's NDC to pixels ImVec2 NDCToPixels(const ImPlot3DPlot& plot, const ImPlot3DPoint& point) { ImVec2 center = plot.PlotRect.GetCenter(); - ImPlot3DPoint point_pix = plot.GetBoxZoom() * (plot.Rotation * point); + ImPlot3DPoint point_pix = plot.GetViewScale() * (plot.Rotation * point); point_pix.y *= -1.0f; // Invert y-axis point_pix.x += center.x; point_pix.y += center.y; @@ -1887,7 +1887,7 @@ ImPlot3DRay PixelsToNDCRay(const ImVec2& pix) { SetupLock(); // Calculate zoom factor and plot center - float zoom = plot.GetBoxZoom(); + float zoom = plot.GetViewScale(); ImVec2 center = plot.PlotRect.GetCenter(); // Undo screen transformations to get back to NDC space @@ -2038,7 +2038,7 @@ void HandleInput(ImPlot3DPlot& plot) { ImPlot3DPoint delta_pixels(delta.x, -delta.y, 0.0f); // Convert delta to NDC space - float zoom = plot.GetBoxZoom(); + float zoom = plot.GetViewScale(); ImPlot3DPoint delta_NDC = plot.Rotation.Inverse() * (delta_pixels / zoom); // Convert delta to plot space @@ -2294,7 +2294,7 @@ void SetupLock() { for (int i = 0; i < 3; i++) { ImPlot3DAxis& axis = plot.Axes[i]; if (axis.ShowDefaultTicks) { - float pixels = plot.GetBoxZoom() * plot.BoxScale[i]; + float pixels = plot.GetViewScale() * plot.BoxScale[i]; axis.Locator(axis.Ticker, axis.Range, pixels, axis.Formatter, axis.FormatterData); } } @@ -2363,6 +2363,9 @@ static const ImPlot3DStyleVarInfo GPlot3DStyleVarInfo[] = { {ImGuiDataType_Float, 2, (ImU32)offsetof(ImPlot3DStyle, LegendPadding)}, // ImPlot3DStyleVar_LegendPadding {ImGuiDataType_Float, 2, (ImU32)offsetof(ImPlot3DStyle, LegendInnerPadding)}, // ImPlot3DStyleVar_LegendInnerPadding {ImGuiDataType_Float, 2, (ImU32)offsetof(ImPlot3DStyle, LegendSpacing)}, // ImPlot3DStyleVar_LegendSpacing + + // View style + {ImGuiDataType_Float, 1, (ImU32)offsetof(ImPlot3DStyle, ViewScaleFactor)}, // ImPlot3DStyleVar_ViewScaleFactor }; static const ImPlot3DStyleVarInfo* GetPlotStyleVarInfo(ImPlot3DStyleVar idx) { @@ -3391,7 +3394,9 @@ void ImPlot3DPlot::SetRange(const ImPlot3DPoint& min, const ImPlot3DPoint& max) Axes[2].SetRange(min.z, max.z); } -float ImPlot3DPlot::GetBoxZoom() const { return ImMin(PlotRect.GetWidth(), PlotRect.GetHeight()) / 1.8f; } +float ImPlot3DPlot::GetViewScale() const { + return ImMin(PlotRect.GetWidth(), PlotRect.GetHeight()) / 2.2f * ImPlot3D::GImPlot3D->Style.ViewScaleFactor; +} //----------------------------------------------------------------------------- // [SECTION] ImPlot3DStyle @@ -3413,6 +3418,8 @@ ImPlot3DStyle::ImPlot3DStyle() { LegendPadding = ImVec2(10, 10); LegendInnerPadding = ImVec2(5, 5); LegendSpacing = ImVec2(5, 0); + // View style + ViewScaleFactor = 1.0f; // Colors ImPlot3D::StyleColorsAuto(this); Colormap = ImPlot3DColormap_Deep; @@ -3689,7 +3696,7 @@ void ImPlot3D::ShowMetricsWindow(bool* p_popen) { ImGui::BulletText("Animation: Time=%.4f RotationEnd=[%.2f,%.2f,%.2f,%.2f]", plot.AnimationTime, plot.RotationAnimationEnd.x, plot.RotationAnimationEnd.y, plot.Rotation.z, plot.RotationAnimationEnd.w); ImGui::BulletText("BoxScale: [%.2f,%.2f,%.2f]", plot.BoxScale.x, plot.BoxScale.y, plot.BoxScale.z); - ImGui::BulletText("BoxZoom: %.2f", plot.GetBoxZoom()); + ImGui::BulletText("ViewScale: %.2f", plot.GetViewScale()); ImGui::TreePop(); } diff --git a/implot3d.h b/implot3d.h index d0e9f08..9868c75 100644 --- a/implot3d.h +++ b/implot3d.h @@ -156,6 +156,8 @@ enum ImPlot3DStyleVar_ { ImPlot3DStyleVar_LegendPadding, // ImVec2, legend padding from plot edges ImPlot3DStyleVar_LegendInnerPadding, // ImVec2, legend inner padding from legend edges ImPlot3DStyleVar_LegendSpacing, // ImVec2, spacing between legend entries + // View style + ImPlot3DStyleVar_ViewScaleFactor, // float, scale factor for 3D view/plot box ImPlot3DStyleVar_COUNT }; @@ -818,6 +820,8 @@ struct ImPlot3DStyle { ImVec2 LegendPadding; // Legend padding from plot edges ImVec2 LegendInnerPadding; // Legend inner padding from legend edges ImVec2 LegendSpacing; // Spacing between legend entries + // View style + float ViewScaleFactor; // Scale factor for 3D view/plot box // Colors ImVec4 Colors[ImPlot3DCol_COUNT]; inline ImVec4 GetColor(ImPlot3DCol idx) const { return Colors[idx]; } diff --git a/implot3d_internal.h b/implot3d_internal.h index d1a22be..feb2531 100644 --- a/implot3d_internal.h +++ b/implot3d_internal.h @@ -684,7 +684,7 @@ struct ImPlot3DPlot { ImPlot3DPoint RangeMax() const; ImPlot3DPoint RangeCenter() const; void SetRange(const ImPlot3DPoint& min, const ImPlot3DPoint& max); - float GetBoxZoom() const; + float GetViewScale() const; }; struct ImPlot3DContext {