1- // --------------------------------------------------
1+ // SPDX-License-Identifier: MIT
2+ // SPDX-FileCopyrightText: 2024-2025 Breno Cunha Queiroz
3+
24// ImPlot3D v0.3 WIP
3- // implot3d.cpp
4- // Date: 2024-11-16
5- // Author: Breno Cunha Queiroz (brenocq.com)
6- //
5+
76// Acknowledgments:
87// ImPlot3D is heavily inspired by ImPlot
98// (https://github.com/epezent/implot) by Evan Pezent,
109// and follows a similar code style and structure to
1110// maintain consistency with ImPlot's API.
12- // --------------------------------------------------
1311
1412// Table of Contents:
1513// [SECTION] Includes
4038// [SECTION] ImPlot3DPlot
4139// [SECTION] ImPlot3DStyle
4240// [SECTION] Metrics
41+ // [SECTION] Obsolete API
4342
4443/*
4544API BREAKING CHANGES
@@ -49,6 +48,8 @@ Below is a change-log of API breaking changes only. If you are using one of the
4948When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all
5049implot3d files. You can read releases logs https://github.com/brenocq/implot3d/releases for more details.
5150
51+ - 2025/11/15 (0.3) - Renamed GetPlotPos() -> GetPlotRectPos() and GetPlotSize() -> GetPlotRectSize() for clarity in 3D context.
52+ Old functions are marked as deprecated and will be removed in v1.0.
5253- 2025/10/22 (0.3) - **IMPORTANT** All plot coordinate types migrated from float to double precision to fix sorting issues with large values:
5354 - ImPlot3DPoint members (x, y, z): float -> double
5455 - ImPlot3DPoint operators: float parameters -> double parameters
@@ -78,8 +79,8 @@ implot3d files. You can read releases logs https://github.com/brenocq/implot3d/r
7879#endif
7980
8081// We define this to avoid accidentally using the deprecated API
81- #ifndef IMPLOT_DISABLE_OBSOLETE_FUNCTIONS
82- #define IMPLOT_DISABLE_OBSOLETE_FUNCTIONS
82+ #ifndef IMPLOT3D_DISABLE_OBSOLETE_FUNCTIONS
83+ #define IMPLOT3D_DISABLE_OBSOLETE_FUNCTIONS
8384#endif
8485
8586#include " implot3d.h"
@@ -1696,14 +1697,14 @@ void SetupAxisLimitsConstraints(ImAxis3D idx, double v_min, double v_max) {
16961697 axis.ConstraintRange .Max = (float )v_max;
16971698}
16981699
1699- void SetupAxisZoomConstraints (ImAxis3D idx, double z_min , double z_max ) {
1700+ void SetupAxisZoomConstraints (ImAxis3D idx, double zoom_min , double zoom_max ) {
17001701 ImPlot3DContext& gp = *GImPlot3D;
17011702 IM_ASSERT_USER_ERROR (gp.CurrentPlot != nullptr && !gp.CurrentPlot ->SetupLocked ,
17021703 " Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!" );
17031704 ImPlot3DPlot& plot = *gp.CurrentPlot ;
17041705 ImPlot3DAxis& axis = plot.Axes [idx];
1705- axis.ConstraintZoom .Min = (float )z_min ;
1706- axis.ConstraintZoom .Max = (float )z_max ;
1706+ axis.ConstraintZoom .Min = (float )zoom_min ;
1707+ axis.ConstraintZoom .Max = (float )zoom_max ;
17071708}
17081709
17091710void SetupAxes (const char * x_label, const char * y_label, const char * z_label, ImPlot3DAxisFlags x_flags, ImPlot3DAxisFlags y_flags,
@@ -1896,16 +1897,16 @@ ImPlot3DPoint PixelsToPlotPlane(const ImVec2& pix, ImPlane3D plane, bool mask) {
18961897
18971898ImPlot3DPoint PixelsToPlotPlane (double x, double y, ImPlane3D plane, bool mask) { return PixelsToPlotPlane (ImVec2 ((float )x, (float )y), plane, mask); }
18981899
1899- ImVec2 GetPlotPos () {
1900+ ImVec2 GetPlotRectPos () {
19001901 ImPlot3DContext& gp = *GImPlot3D;
1901- IM_ASSERT_USER_ERROR (gp.CurrentPlot != nullptr , " GetPlotPos () needs to be called between BeginPlot() and EndPlot()!" );
1902+ IM_ASSERT_USER_ERROR (gp.CurrentPlot != nullptr , " GetPlotRectPos () needs to be called between BeginPlot() and EndPlot()!" );
19021903 SetupLock ();
19031904 return gp.CurrentPlot ->PlotRect .Min ;
19041905}
19051906
1906- ImVec2 GetPlotSize () {
1907+ ImVec2 GetPlotRectSize () {
19071908 ImPlot3DContext& gp = *GImPlot3D;
1908- IM_ASSERT_USER_ERROR (gp.CurrentPlot != nullptr , " GetPlotSize () needs to be called between BeginPlot() and EndPlot()!" );
1909+ IM_ASSERT_USER_ERROR (gp.CurrentPlot != nullptr , " GetPlotRectSize () needs to be called between BeginPlot() and EndPlot()!" );
19091910 SetupLock ();
19101911 return gp.CurrentPlot ->PlotRect .GetSize ();
19111912}
@@ -1972,8 +1973,8 @@ ImPlot3DRay PixelsToNDCRay(const ImVec2& pix) {
19721973 float y = -(pix.y - center.y ) / zoom; // Invert y-axis
19731974
19741975 // Define near and far points in NDC space along the z-axis
1975- ImPlot3DPoint ndc_near = plot.Rotation .Inverse () * ImPlot3DPoint (x, y, - 10 .0f );
1976- ImPlot3DPoint ndc_far = plot.Rotation .Inverse () * ImPlot3DPoint (x, y, 10 .0f );
1976+ ImPlot3DPoint ndc_near = plot.Rotation .Inverse () * ImPlot3DPoint (x, y, 10 .0f );
1977+ ImPlot3DPoint ndc_far = plot.Rotation .Inverse () * ImPlot3DPoint (x, y, - 10 .0f );
19771978
19781979 // Create the ray in NDC space
19791980 ImPlot3DRay ndc_ray;
@@ -2625,6 +2626,37 @@ void StyleColorsClassic(ImPlot3DStyle* dst) {
26252626 colors[ImPlot3DCol_AxisTick] = IMPLOT3D_AUTO_COL;
26262627}
26272628
2629+ bool ShowStyleSelector (const char * label) {
2630+ static int style_idx = -1 ;
2631+ if (ImGui::Combo (label, &style_idx, " Auto\0 Classic\0 Dark\0 Light\0 " )) {
2632+ switch (style_idx) {
2633+ case 0 : StyleColorsAuto (); break ;
2634+ case 1 : StyleColorsClassic (); break ;
2635+ case 2 : StyleColorsDark (); break ;
2636+ case 3 : StyleColorsLight (); break ;
2637+ }
2638+ return true ;
2639+ }
2640+ return false ;
2641+ }
2642+
2643+ bool ShowColormapSelector (const char * label) {
2644+ ImPlot3DContext& gp = *GImPlot3D;
2645+ bool set = false ;
2646+ if (ImGui::BeginCombo (label, gp.ColormapData .GetName (gp.Style .Colormap ))) {
2647+ for (int i = 0 ; i < gp.ColormapData .Count ; ++i) {
2648+ const char * name = gp.ColormapData .GetName (i);
2649+ if (ImGui::Selectable (name, gp.Style .Colormap == i)) {
2650+ gp.Style .Colormap = i;
2651+ BustItemCache ();
2652+ set = true ;
2653+ }
2654+ }
2655+ ImGui::EndCombo ();
2656+ }
2657+ return set;
2658+ }
2659+
26282660void PushStyleColor (ImPlot3DCol idx, ImU32 col) {
26292661 ImPlot3DContext& gp = *GImPlot3D;
26302662 ImGuiColorMod backup;
@@ -3929,4 +3961,20 @@ void ImPlot3D::ShowMetricsWindow(bool* p_popen) {
39293961 ImGui::End ();
39303962}
39313963
3964+ // -----------------------------------------------------------------------------
3965+ // [SECTION] Obsolete API
3966+ // -----------------------------------------------------------------------------
3967+
3968+ #ifndef IMPLOT3D_DISABLE_OBSOLETE_FUNCTIONS
3969+
3970+ namespace ImPlot3D {
3971+
3972+ // OBSOLETED in v0.3
3973+ ImVec2 GetPlotPos () { return GetPlotRectPos (); }
3974+ ImVec2 GetPlotSize () { return GetPlotRectSize (); }
3975+
3976+ } // namespace ImPlot3D
3977+
3978+ #endif // #ifndef IMPLOT3D_DISABLE_OBSOLETE_FUNCTIONS
3979+
39323980#endif // #ifndef IMGUI_DISABLE
0 commit comments