MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / check_point_to_face

Function check_point_to_face

physics/findintersection.cpp:1093–1166  ·  view source on GitHub ↗

see if a point in inside a face by projecting into 2d

Source from the content-addressed store, hash-verified

1091
1092// see if a point in inside a face by projecting into 2d
1093uint32_t check_point_to_face(vector *colp, vector *face_normal, int nv, vector **vertex_ptr_list) {
1094 vector_array *colp_array; // Axis-independant version of the collision point
1095 vector_array *norm; // Axis-independant version of the plane's normal
1096 vector t; // Temporary vector that holds the magnatude of the normal's x,y,z components (ABS)
1097 int biggest; // Index of the largest of the three components (0-x, 1-y, 2-z) Axis to ignore :)
1098 int i, j, edge; // Index for i-axis, Index for j-axis, and the current edge
1099 uint32_t edgemask; // Bit-field for which side we are outside of
1100 float check_i, check_j; // (i,j) checkpoint for 2d in/out test
1101 vector_array *v0, *v1; // Vertices of the current line segment in the 2d in/out check loop
1102
1103 // Lets look at these vectors as arrays :)
1104 norm = (vector_array *)face_normal;
1105 colp_array = (vector_array *)colp;
1106
1107 // now do 2d check to see if point is in side
1108
1109 // Get x,y,z components of the normal and put them in array form (so we can pick any two for i,j)
1110 t.x = fabs(norm->xyz[0]);
1111 t.y = fabs(norm->xyz[1]);
1112 t.z = fabs(norm->xyz[2]);
1113
1114 // Determine which axis will be normal to the plane the points are projected onto
1115 if (t.x > t.y)
1116 if (t.x > t.z)
1117 biggest = 0;
1118 else
1119 biggest = 2;
1120 else if (t.y > t.z)
1121 biggest = 1;
1122 else
1123 biggest = 2;
1124
1125 // For a plane with a normal that is in the opposite direction of the axis,
1126 // we should circle the other direction -- i.e. always circle in clockwise direction with normal (left-handed)
1127 if (norm->xyz[biggest] > 0) {
1128 i = ij_table[biggest][0];
1129 j = ij_table[biggest][1];
1130 } else {
1131 i = ij_table[biggest][1];
1132 j = ij_table[biggest][0];
1133 }
1134
1135 // now do the 2d problem in the i,j plane
1136
1137 // Get the i,j check point
1138 check_i = colp_array->xyz[i];
1139 check_j = colp_array->xyz[j];
1140
1141 // Do a simple 2d cross-product between each line segment and the start point to the check point
1142 // Go in a clockwise direction, if determinant is negative then point is outside of this multi-
1143 // side polygon. :) Only works for concave polygons.
1144 for (edge = edgemask = 0; edge < nv; edge++) {
1145 vec2d edgevec, checkvec;
1146 float d;
1147
1148 // v0 = (vector_array *)&Vertices[vertex_list[facenum*3+edge]];
1149 // v1 = (vector_array *)&Vertices[vertex_list[facenum*3+((edge+1)%nv)]];
1150 v0 = (vector_array *)vertex_ptr_list[edge];

Callers 6

check_sphere_to_faceFunction · 0.85
LookForFVICracksFunction · 0.85
DrawRoomVisPntsFunction · 0.85
BSPPointInPolygonFunction · 0.85
MakeBOAVisTableFunction · 0.85
goal_do_avoid_wallsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected