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

Function JoinAllOverlappingFaces

editor/HRoom.cpp:1949–2018  ·  view source on GitHub ↗

Find all the overlapping faces between two rooms and join them Returns the number of new portals created

Source from the content-addressed store, hash-verified

1947// Find all the overlapping faces between two rooms and join them
1948// Returns the number of new portals created
1949int JoinAllOverlappingFaces(room *rp0, room *rp1) {
1950 face *fp0, *fp1;
1951 int f0, f1;
1952 int join_count = 0;
1953
1954 // Check each face in room 0 against each in room 1
1955 for (f0 = 0, fp0 = rp0->faces; f0 < rp0->num_faces; f0++, fp0++) {
1956
1957 // Check if face 0 is already part of portal
1958 if (fp0->portal_num != -1)
1959 continue;
1960
1961 // Check current face against all faces in room 1
1962 for (f1 = 0, fp1 = rp1->faces; f1 < rp1->num_faces; f1++, fp1++) {
1963
1964 // Check if face 1 is already part of portal
1965 if (fp1->portal_num != -1)
1966 continue;
1967
1968 // This used to check if normals the same, but I decided that was bad. -MT, 3/30/99
1969 {
1970 int i;
1971 vector *planepoint, *norm;
1972
1973 // Normals are same, so check if points are all in the same plane
1974 planepoint = &rp1->verts[fp1->face_verts[0]];
1975 norm = &fp1->normal;
1976 for (i = 0; i < fp0->num_verts; i++)
1977 if (CheckPointToPlane(&rp0->verts[fp0->face_verts[i]], planepoint, norm))
1978 break;
1979 if (i < fp0->num_verts)
1980 continue;
1981
1982 planepoint = &rp0->verts[fp0->face_verts[0]];
1983 norm = &fp0->normal;
1984 for (i = 0; i < fp1->num_verts; i++)
1985 if (CheckPointToPlane(&rp1->verts[fp1->face_verts[i]], planepoint, norm))
1986 break;
1987 if (i < fp1->num_verts)
1988 continue;
1989
1990 // Clip the connecting faces against each other
1991 if (ClipFacePair(rp0, f0, rp1, f1)) {
1992
1993 // Make the two faces match exactly
1994 MatchPortalFaces(rp0, f0, rp1, f1);
1995
1996 // Create the portals between the rooms
1997 LinkRoomsSimple(Rooms, ROOMNUM(rp0), f0, ROOMNUM(rp1), f1);
1998
1999 // Reset face pointer, which may have been changed by the clip
2000 fp0 = &rp0->faces[f0];
2001
2002 // Increment count
2003 join_count++;
2004
2005 // Stop checking this face, since we've formed a portal for it
2006 break;

Callers 1

JoinAllAdjacentFacesFunction · 0.85

Calls 3

CheckPointToPlaneFunction · 0.85
ClipFacePairFunction · 0.85
MatchPortalFacesFunction · 0.85

Tested by

no test coverage detected