Important - vertnum is the index into the face_verts[] array in the face structure, not an index into the verts[] array of the room structure
| 1391 | // Important - vertnum is the index into the face_verts[] array in the face structure, |
| 1392 | // not an index into the verts[] array of the room structure |
| 1393 | void BuildElementListForRoomFace(int roomnum, int facenum, rad_surface *surf) { |
| 1394 | matrix face_matrix, trans_matrix; |
| 1395 | vector fvec; |
| 1396 | vector avg_vert; |
| 1397 | vector verts[MAX_VERTS_PER_FACE * 5]; |
| 1398 | vector rot_vert; |
| 1399 | vector vert; |
| 1400 | int i, t; |
| 1401 | int xres, yres; |
| 1402 | int lmi_handle; |
| 1403 | int x1 = surf->x1; |
| 1404 | int y1 = surf->y1; |
| 1405 | |
| 1406 | xres = surf->xresolution; |
| 1407 | yres = surf->yresolution; |
| 1408 | |
| 1409 | ASSERT(Rooms[roomnum].used); |
| 1410 | ASSERT(Rooms[roomnum].faces[facenum].num_verts >= 3); |
| 1411 | ASSERT(Rooms[roomnum].faces[facenum].lmi_handle != BAD_LMI_INDEX); |
| 1412 | |
| 1413 | lmi_handle = Rooms[roomnum].faces[facenum].lmi_handle; |
| 1414 | avg_vert = ScratchCenters[lmi_handle]; |
| 1415 | |
| 1416 | // Make the orientation matrix |
| 1417 | // Reverse the normal because we're looking "at" the face, not from it |
| 1418 | fvec = -LightmapInfo[lmi_handle].normal; |
| 1419 | |
| 1420 | vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL); |
| 1421 | // Make the transformation matrix |
| 1422 | |
| 1423 | angvec avec; |
| 1424 | vm_ExtractAnglesFromMatrix(&avec, &face_matrix); |
| 1425 | vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b); |
| 1426 | |
| 1427 | // Rotate all the points |
| 1428 | for (i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) { |
| 1429 | vert = Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[i]]; |
| 1430 | |
| 1431 | vert -= avg_vert; |
| 1432 | vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix); |
| 1433 | |
| 1434 | verts[i] = rot_vert; |
| 1435 | } |
| 1436 | |
| 1437 | // Find a base vector |
| 1438 | vector base_vector; |
| 1439 | vector xdiff, ydiff; |
| 1440 | |
| 1441 | vm_MakeZero(&xdiff); |
| 1442 | vm_MakeZero(&ydiff); |
| 1443 | |
| 1444 | // Rotate our upper left point into our 2d space |
| 1445 | vert = LightmapInfo[lmi_handle].upper_left - avg_vert; |
| 1446 | vm_MatrixMulVector(&base_vector, &vert, &trans_matrix); |
| 1447 | |
| 1448 | xdiff.x = LightmapInfo[lmi_handle].xspacing; |
| 1449 | ydiff.y = LightmapInfo[lmi_handle].yspacing; |
| 1450 |
no test coverage detected