Splits a face unto triangles, by fanning Parameters: rp,facenum - the face to triangulate vertnum - the vert that is the base of the fan
| 2092 | // Parameters: rp,facenum - the face to triangulate |
| 2093 | // vertnum - the vert that is the base of the fan |
| 2094 | void TriangulateFace(room *rp, int facenum, int vertnum) { |
| 2095 | face *fp = &rp->faces[facenum], *nfp; |
| 2096 | int num_new_faces, first_new_face, i; |
| 2097 | |
| 2098 | if (fp->num_verts == 3) { |
| 2099 | OutrageMessageBox("Face %d has three verts and cannot be split.", facenum); |
| 2100 | return; |
| 2101 | } |
| 2102 | |
| 2103 | if (fp->portal_num != -1) { |
| 2104 | OutrageMessageBox("You cannot split a face that's part of a portal."); |
| 2105 | return; |
| 2106 | } |
| 2107 | |
| 2108 | if (fp->flags & (FF_HAS_TRIGGER + FF_FLOATING_TRIG)) { |
| 2109 | OutrageMessageBox("You cannot split a face that has a trigger."); |
| 2110 | return; |
| 2111 | } |
| 2112 | |
| 2113 | // Add new faces |
| 2114 | num_new_faces = fp->num_verts - 2; |
| 2115 | first_new_face = RoomAddFaces(rp, num_new_faces); |
| 2116 | |
| 2117 | // Reset pointer to our old face |
| 2118 | fp = &rp->faces[facenum]; |
| 2119 | |
| 2120 | // Set up each face |
| 2121 | for (i = 0, nfp = &rp->faces[first_new_face]; i < num_new_faces; i++, nfp++) { |
| 2122 | InitRoomFace(nfp, 3); |
| 2123 | |
| 2124 | // Set verts & uvls for this face |
| 2125 | nfp->face_verts[0] = fp->face_verts[vertnum]; |
| 2126 | nfp->face_uvls[0] = fp->face_uvls[vertnum]; |
| 2127 | for (int v = 1; v < 3; v++) { |
| 2128 | nfp->face_verts[v] = fp->face_verts[(vertnum + i + v) % fp->num_verts]; |
| 2129 | nfp->face_uvls[v] = fp->face_uvls[(vertnum + i + v) % fp->num_verts]; |
| 2130 | } |
| 2131 | |
| 2132 | // Copy other data for this face |
| 2133 | CopyFaceFlags(nfp, fp); |
| 2134 | #ifndef NEWEDITOR |
| 2135 | nfp->tmap = fp->tmap; |
| 2136 | #else |
| 2137 | // Apply texture |
| 2138 | HTextureApplyToRoomFace(rp, first_new_face + i, nfp->tmap); |
| 2139 | #endif |
| 2140 | nfp->light_multiple = fp->light_multiple; |
| 2141 | |
| 2142 | // Compute the normal for this face |
| 2143 | ComputeFaceNormal(rp, first_new_face + i); |
| 2144 | } |
| 2145 | |
| 2146 | // Delete original face |
| 2147 | DeleteRoomFace(rp, facenum); |
| 2148 | |
| 2149 | // Check for degenerate faces (caused by colinear points) and merge with adjacent faces |
| 2150 | first_new_face--; // original face deleted, causing shift |
| 2151 | bool ok; |
no test coverage detected