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

Function GetAxesParameters

implot3d.cpp:1228–1326  ·  view source on GitHub ↗

Function to get axes parameters which can then be used later down the line

Source from the content-addressed store, hash-verified

1226
1227// Function to get axes parameters which can then be used later down the line
1228void GetAxesParameters(const ImPlot3DPlot& plot, bool* active_faces, ImVec2* corners_pix, ImPlot3DPoint* corners, int& plane_2d,
1229 int axis_corners[3][2]) {
1230 // Get plot parameters
1231 const ImPlot3DQuat& rotation = plot.Rotation;
1232 ImPlot3DPoint range_min = plot.RangeMin();
1233 ImPlot3DPoint range_max = plot.RangeMax();
1234
1235 // Compute active faces
1236 ComputeActiveFaces(active_faces, rotation, plot.Axes, &plane_2d);
1237 bool is_2d = plane_2d != -1;
1238
1239 // Compute box corners in plot space
1240 ComputeBoxCorners(corners, range_min, range_max);
1241
1242 // Compute box corners in pixel space
1243 ComputeBoxCornersPix(plot, corners_pix, corners);
1244
1245 // Compute axes start and end corners (given current rotation)
1246 if (is_2d) {
1247 int face = plane_2d + 3 * active_faces[plane_2d]; // Face of the 2D plot
1248 int common_edges[2] = {-1, -1}; // Edges shared by the 3 faces
1249
1250 // Find the common edges between the 3 faces
1251 for (int i = 0; i < 4; i++) {
1252 int edge = face_edges[face][i];
1253 for (int j = 0; j < 2; j++) {
1254 int axis = (plane_2d + 1 + j) % 3;
1255 int face_idx = axis + active_faces[axis] * 3;
1256 for (int k = 0; k < 4; k++) {
1257 if (face_edges[face_idx][k] == edge) {
1258 common_edges[j] = edge;
1259 break;
1260 }
1261 }
1262 }
1263 }
1264
1265 // Get corners from 2 edges (origin is the corner in common)
1266 int origin_corner = -1;
1267 int x_corner = -1;
1268 int y_corner = -1;
1269 for (int i = 0; i < 2; i++)
1270 for (int j = 0; j < 2; j++)
1271 if (edges[common_edges[0]][i] == edges[common_edges[1]][j]) {
1272 origin_corner = edges[common_edges[0]][i];
1273 x_corner = edges[common_edges[0]][!i];
1274 y_corner = edges[common_edges[1]][!j];
1275 }
1276
1277 // Swap x and y if they are flipped
1278 ImVec2 x_vec = corners_pix[x_corner] - corners_pix[origin_corner];
1279 ImVec2 y_vec = corners_pix[y_corner] - corners_pix[origin_corner];
1280 if (y_vec.x > x_vec.x)
1281 ImSwap(x_corner, y_corner);
1282
1283 // Check which 3d axis the 2d axis refers to
1284 ImPlot3DPoint origin_3d = corners[origin_corner];
1285 ImPlot3DPoint x_3d = (corners[x_corner] - origin_3d).Normalized();

Callers 3

RenderPlotBoxFunction · 0.85
HandleInputFunction · 0.85
ShowMetricsWindowMethod · 0.85

Calls 7

ComputeActiveFacesFunction · 0.85
ComputeBoxCornersFunction · 0.85
ComputeBoxCornersPixFunction · 0.85
RangeMinMethod · 0.80
RangeMaxMethod · 0.80
NormalizedMethod · 0.80

Tested by

no test coverage detected