Clips a face against another. Produces one polygon that is the intersection of the two input faces, and zero or more extra polygons, which are parts of the input face outside the clipping face. The input face is replaced by the clipped face, and new faces (formed by the parts of the input face outside the clip-against face) are added to the end of the room's facelist. This routine assumes that pa
| 917 | // bfacenum - the face we're clipping against |
| 918 | // Returns: true if the clip was ok, false if there was an error |
| 919 | bool ClipFace(room *arp, int afacenum, room *brp, int bfacenum) { |
| 920 | face *afp = &arp->faces[afacenum]; |
| 921 | face *bfp = &brp->faces[bfacenum]; |
| 922 | int edgenum; |
| 923 | int16_t vbuf0[MAX_VERTS_PER_FACE], vbuf1[MAX_VERTS_PER_FACE]; |
| 924 | int16_t newface_verts[MAX_VERTS_PER_FACE][MAX_VERTS_PER_FACE]; |
| 925 | int newface_nvs[MAX_VERTS_PER_FACE]; |
| 926 | vertex newverts[MAX_VERTS_PER_FACE]; |
| 927 | int newvertnums[MAX_VERTS_PER_FACE]; |
| 928 | int num_newverts; |
| 929 | int num_newfaces = 0; |
| 930 | int16_t *src, *dest; |
| 931 | int nv; |
| 932 | int i; |
| 933 | |
| 934 | // Init some stuff |
| 935 | nv = afp->num_verts; |
| 936 | src = vbuf0; |
| 937 | dest = vbuf1; |
| 938 | |
| 939 | Num_edge_inserts = 0; |
| 940 | |
| 941 | // copy our vertices into one buffer |
| 942 | for (i = 0; i < nv; i++) { |
| 943 | newverts[i].vec = arp->verts[afp->face_verts[i]]; |
| 944 | newverts[i].uvl = afp->face_uvls[i]; |
| 945 | newvertnums[i] = afp->face_verts[i]; |
| 946 | src[i] = i; |
| 947 | } |
| 948 | num_newverts = nv; |
| 949 | |
| 950 | // Clip our polygon against each edge |
| 951 | for (edgenum = 0; edgenum < bfp->num_verts; edgenum++) { |
| 952 | vector *v0, *v1; |
| 953 | int16_t *outbuf = newface_verts[num_newfaces]; |
| 954 | int *onv = &newface_nvs[num_newfaces]; |
| 955 | |
| 956 | v0 = &brp->verts[bfp->face_verts[(bfp->num_verts - edgenum) % bfp->num_verts]]; |
| 957 | v1 = &brp->verts[bfp->face_verts[bfp->num_verts - edgenum - 1]]; |
| 958 | |
| 959 | ClipAgainstEdge(nv, src, newverts, &num_newverts, v0, v1, &afp->normal, dest, &nv, outbuf, onv); |
| 960 | |
| 961 | if (nv <= 2) // no new face -- faces must not overlap |
| 962 | return 0; |
| 963 | |
| 964 | src = dest; |
| 965 | dest = (src == vbuf0) ? vbuf1 : vbuf0; |
| 966 | |
| 967 | if (newface_nvs[num_newfaces]) // is there a new face? |
| 968 | num_newfaces++; //..yes, increment counter |
| 969 | } |
| 970 | |
| 971 | // Now we have the clipped face and the other new faces |
| 972 | // Replace the old face, and add the new faces |
| 973 | int first_new_vert, first_new_face; |
| 974 | face *fp; |
| 975 | |
| 976 | // Allocate space for the new verts |
no test coverage detected