| 1088 | } |
| 1089 | |
| 1090 | void RenderAxisLabels(ImDrawList* draw_list, const ImPlot3DPlot& plot, const ImPlot3DPoint*, const ImVec2* corners_pix, |
| 1091 | const int axis_corners[3][2]) { |
| 1092 | ImU32 col_ax_txt = GetStyleColorU32(ImPlot3DCol_AxisText); |
| 1093 | |
| 1094 | for (int a = 0; a < 3; a++) { |
| 1095 | const ImPlot3DAxis& axis = plot.Axes[a]; |
| 1096 | if (!axis.HasLabel()) |
| 1097 | continue; |
| 1098 | |
| 1099 | const char* label = axis.GetLabel(); |
| 1100 | |
| 1101 | // Corner indices |
| 1102 | int idx0 = axis_corners[a][0]; |
| 1103 | int idx1 = axis_corners[a][1]; |
| 1104 | |
| 1105 | // If normal to the 2D plot, ignore axis label |
| 1106 | if (idx0 == idx1) |
| 1107 | continue; |
| 1108 | |
| 1109 | ImVec2 axis_start_pix = corners_pix[idx0]; |
| 1110 | ImVec2 axis_end_pix = corners_pix[idx1]; |
| 1111 | |
| 1112 | // Screen space axis direction (normalized), needed for text angle |
| 1113 | ImVec2 axis_screen_dir = axis_end_pix - axis_start_pix; |
| 1114 | float axis_length = ImSqrt(ImLengthSqr(axis_screen_dir)); |
| 1115 | axis_screen_dir = (axis_length > 0.0f) ? axis_screen_dir / axis_length : ImVec2(1.0f, 0.0f); |
| 1116 | |
| 1117 | // Outward perpendicular and total offset: |
| 1118 | // tick labels are centered at (max_tick_extent + AXIS_TICK_INNER_PAD) from the axis edge, |
| 1119 | // so the axis label sits one more max_tick_extent + AXIS_LABEL_PAD beyond that. |
| 1120 | ImVec2 outward_dir = ComputeEdgeOutwardDir(axis_start_pix, axis_end_pix, PlotToPixels(plot.RangeCenter())); |
| 1121 | float max_tick_extent = ComputeMaxTickLabelExtent(axis); |
| 1122 | float tick_label_center = max_tick_extent + AXIS_TICK_INNER_PAD; |
| 1123 | float total_offset = tick_label_center + max_tick_extent + AXIS_LABEL_PAD; |
| 1124 | |
| 1125 | ImVec2 axis_center_pix = (axis_start_pix + axis_end_pix) * 0.5f; |
| 1126 | ImVec2 label_pos_pix = axis_center_pix + outward_dir * total_offset; |
| 1127 | |
| 1128 | // Compute text angle |
| 1129 | float angle = atan2f(-axis_screen_dir.y, axis_screen_dir.x); |
| 1130 | if (angle > IM_PI * 0.5f) |
| 1131 | angle -= IM_PI; |
| 1132 | if (angle < -IM_PI * 0.5f) |
| 1133 | angle += IM_PI; |
| 1134 | |
| 1135 | AddTextRotated(draw_list, label_pos_pix, angle, col_ax_txt, label); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | // Function to compute active faces based on the rotation |
| 1140 | // If the plot is close to 2D, plane_2d is set to the plane index (0 -> YZ, 1 -> XZ, 2 -> XY) |
no test coverage detected