returns the index in the face_verts array for the most point on this face
| 738 | |
| 739 | // returns the index in the face_verts array for the most point on this face |
| 740 | int HTextureGetBottomVertexForFace(int roomnum, int facenum) { |
| 741 | matrix face_matrix, trans_matrix; |
| 742 | vector fvec; |
| 743 | vector avg_vert; |
| 744 | vector verts[MAX_VERTS_PER_FACE]; |
| 745 | |
| 746 | ASSERT(Rooms[roomnum].used); |
| 747 | ASSERT(Rooms[roomnum].faces[facenum].num_verts >= 3); |
| 748 | |
| 749 | // find the center point of this face |
| 750 | vm_MakeZero(&avg_vert); |
| 751 | for (int i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) |
| 752 | avg_vert += Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[i]]; |
| 753 | |
| 754 | avg_vert /= i; |
| 755 | |
| 756 | // Make the orientation matrix |
| 757 | fvec = Rooms[roomnum].faces[facenum].normal; |
| 758 | |
| 759 | vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL); |
| 760 | // Make the transformation matrix |
| 761 | |
| 762 | angvec avec; |
| 763 | vm_ExtractAnglesFromMatrix(&avec, &face_matrix); |
| 764 | vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b); |
| 765 | |
| 766 | // Rotate all the points |
| 767 | for (i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) { |
| 768 | vector vert = Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[i]]; |
| 769 | vector rot_vert; |
| 770 | |
| 771 | vert -= avg_vert; |
| 772 | vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix); |
| 773 | |
| 774 | verts[i] = rot_vert; |
| 775 | } |
| 776 | |
| 777 | // Find bottom most point |
| 778 | int bottommost_point = -1; |
| 779 | float bottommost_y = 900000.0f; // a big number |
| 780 | |
| 781 | for (i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) { |
| 782 | if (verts[i].y < bottommost_y) { |
| 783 | bottommost_point = i; |
| 784 | bottommost_y = verts[i].y; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | ASSERT(bottommost_point != -1); |
| 789 | |
| 790 | return bottommost_point; |
| 791 | } |
| 792 | |
| 793 | /*void HTextureGetBoxUVLForFace (room *rp,facenum) |
| 794 | { |
nothing calls this directly
no test coverage detected