MCPcopy Create free account
hub / github.com/brenocq/implot3d / RenderGrid

Function RenderGrid

implot3d.cpp:809–886  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

807}
808
809void RenderGrid(ImDrawList* draw_list, const ImPlot3DPlot& plot, const ImPlot3DPoint* corners, const bool* active_faces, const int plane_2d) {
810 ImVec4 col_grid = GetStyleColorVec4(ImPlot3DCol_AxisGrid);
811 ImU32 col_grid_minor = ImGui::GetColorU32(col_grid * ImVec4(1, 1, 1, 0.3f));
812 ImU32 col_grid_major = ImGui::GetColorU32(col_grid * ImVec4(1, 1, 1, 0.6f));
813 for (int face = 0; face < 3; face++) {
814 if (plane_2d != -1 && face != plane_2d)
815 continue;
816 int face_idx = face + 3 * active_faces[face];
817 const ImPlot3DAxis& axis_u = plot.Axes[(face + 1) % 3];
818 const ImPlot3DAxis& axis_v = plot.Axes[(face + 2) % 3];
819
820 // Get the two axes (u and v) that define the face plane
821 int idx0 = faces[face_idx][0];
822 int idx1 = faces[face_idx][1];
823 int idx3 = faces[face_idx][3];
824
825 // Corners of the face in plot space
826 ImPlot3DPoint p0 = corners[idx0];
827 ImPlot3DPoint p1 = corners[idx1];
828 ImPlot3DPoint p3 = corners[idx3];
829
830 // Vectors along the edges
831 ImPlot3DPoint u_vec = p1 - p0;
832 ImPlot3DPoint v_vec = p3 - p0;
833
834 // Render grid lines along u axis (axis_u)
835 if (!ImPlot3D::ImHasFlag(axis_u.Flags, ImPlot3DAxisFlags_NoGridLines))
836 for (int t = 0; t < axis_u.Ticker.TickCount(); ++t) {
837 const ImPlot3DTick& tick = axis_u.Ticker.Ticks[t];
838
839 // Compute position along u
840 double t_u = (tick.PlotPos - axis_u.Range.Min) / (axis_u.Range.Max - axis_u.Range.Min);
841
842 // Skip ticks that are out of range
843 if (t_u < 0.0 || t_u > 1.0)
844 continue;
845
846 ImPlot3DPoint p_start = p0 + u_vec * t_u;
847 ImPlot3DPoint p_end = p3 + u_vec * t_u;
848
849 // Convert to pixel coordinates
850 ImVec2 p_start_pix = PlotToPixels(p_start);
851 ImVec2 p_end_pix = PlotToPixels(p_end);
852
853 // Get color
854 ImU32 col_line = tick.Major ? col_grid_major : col_grid_minor;
855
856 // Draw the grid line
857 draw_list->AddLine(p_start_pix, p_end_pix, col_line);
858 }
859
860 // Render grid lines along v axis (axis_v)
861 if (!ImPlot3D::ImHasFlag(axis_v.Flags, ImPlot3DAxisFlags_NoGridLines))
862 for (int t = 0; t < axis_v.Ticker.TickCount(); ++t) {
863 const ImPlot3DTick& tick = axis_v.Ticker.Ticks[t];
864
865 // Compute position along v
866 double t_v = (tick.PlotPos - axis_v.Range.Min) / (axis_v.Range.Max - axis_v.Range.Min);

Callers 1

RenderPlotBoxFunction · 0.85

Calls 4

GetStyleColorVec4Function · 0.85
ImHasFlagFunction · 0.85
PlotToPixelsFunction · 0.85
TickCountMethod · 0.80

Tested by

no test coverage detected