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

Function MatchPortalFaces

editor/HRoom.cpp:1107–1221  ·  view source on GitHub ↗

Takes two faces which are going to be made into a portal and makes them match exactly Alternatively, checks if the two faces can be matched After this function the two faces will have exactly the same vertices Parameters: rp0,facenum0 - one of the faces rp1,facenum1 - the other face check_only - if set, doesn't change anything; just checks the faces Returns the number of points added to the faces

Source from the content-addressed store, hash-verified

1105// Returns the number of points added to the faces
1106// If just_checking set, returns true if faces match, else false
1107int MatchPortalFaces(room *rp0, int facenum0, room *rp1, int facenum1, bool check_only) {
1108 face *fp0 = &rp0->faces[facenum0];
1109 face *fp1 = &rp1->faces[facenum1];
1110 vector *v0, *v1, *prev_v0, *prev_v1;
1111 int n0, n1, i, j, prev_vn0, prev_vn1, max_nv;
1112 int points_added = 0;
1113
1114check_faces:;
1115
1116 // First, find one point in common
1117 for (i = 0; i < fp0->num_verts; i++) {
1118 for (j = 0; j < fp1->num_verts; j++)
1119 if (PointsAreSame(&rp0->verts[fp0->face_verts[i]], &rp1->verts[fp1->face_verts[j]]))
1120 break;
1121 if (j < fp1->num_verts)
1122 break;
1123 }
1124 if (i >= fp0->num_verts) {
1125 if (!check_only)
1126 Int3(); // Counldn't find common point! This is very bad. Get Matt.
1127 return 0; // no match
1128 }
1129
1130 prev_vn0 = fp0->face_verts[i];
1131 prev_vn1 = fp1->face_verts[j];
1132 prev_v0 = &rp0->verts[prev_vn0];
1133 prev_v1 = &rp1->verts[prev_vn1];
1134
1135 // Make starting points identical
1136 if (!check_only)
1137 *prev_v0 = *prev_v1;
1138
1139 // Use the larger number of vert
1140 max_nv = __max(fp0->num_verts, fp1->num_verts);
1141
1142 // Trace through faces, adding points where needed
1143 for (n0 = n1 = 1; n0 < max_nv && n1 < max_nv; n0++, n1++) {
1144 int vn0, vn1;
1145
1146 recheck:;
1147
1148 vn0 = fp0->face_verts[(i + n0) % fp0->num_verts];
1149 vn1 = fp1->face_verts[(j - n1 + fp1->num_verts) % fp1->num_verts];
1150
1151 v0 = &rp0->verts[vn0];
1152 v1 = &rp1->verts[vn1];
1153
1154 if (PointsAreSame(v0, v1)) { // Points are at least very close.
1155 if (!check_only)
1156 *v0 = *v1; // Make the points identical
1157 } else { // The points are not the same, so we check for an extra (colinear) point
1158
1159 float d0, d1;
1160
1161 // One of these points should lie along the edge of the other. Find which is which
1162 d0 = vm_VectorDistance(v0, prev_v0);
1163 d1 = vm_VectorDistance(v1, prev_v1);
1164

Callers 7

AttachGroupFunction · 0.85
AttachRoomFunction · 0.85
BuildBridgeFunction · 0.85
JoinRoomsFunction · 0.85
JoinRoomsExactFunction · 0.85
JoinAllOverlappingFacesFunction · 0.85
FixCracksFunction · 0.85

Calls 4

PointsAreSameFunction · 0.85
CheckPointAgainstEdgeFunction · 0.85
AddPointToAllEdgesFunction · 0.85
vm_VectorDistanceFunction · 0.50

Tested by

no test coverage detected