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

Function HTextureGetRightVertexForFace

editor/HTexture.cpp:687–737  ·  view source on GitHub ↗

returns the index in the face_verts array for the rightmost point on this face

Source from the content-addressed store, hash-verified

685
686// returns the index in the face_verts array for the rightmost point on this face
687int HTextureGetRightVertexForFace(int roomnum, int facenum) {
688 matrix face_matrix, trans_matrix;
689 vector fvec;
690 vector avg_vert;
691 vector verts[MAX_VERTS_PER_FACE];
692
693 ASSERT(Rooms[roomnum].used);
694 ASSERT(Rooms[roomnum].faces[facenum].num_verts >= 3);
695
696 // find the center point of this face
697 vm_MakeZero(&avg_vert);
698 for (int i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++)
699 avg_vert += Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[i]];
700
701 avg_vert /= i;
702
703 // Make the orientation matrix
704 fvec = Rooms[roomnum].faces[facenum].normal;
705
706 vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL);
707 // Make the transformation matrix
708
709 angvec avec;
710 vm_ExtractAnglesFromMatrix(&avec, &face_matrix);
711 vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b);
712
713 // Rotate all the points
714 for (i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) {
715 vector vert = Rooms[roomnum].verts[Rooms[roomnum].faces[facenum].face_verts[i]];
716 vector rot_vert;
717
718 vert -= avg_vert;
719 vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix);
720
721 verts[i] = rot_vert;
722 }
723
724 // Find right most point
725 int rightmost_point = -1;
726 float rightmost_x = -900000.00f; // a big number
727
728 for (i = 0; i < Rooms[roomnum].faces[facenum].num_verts; i++) {
729 if (verts[i].x > rightmost_x) {
730 rightmost_point = i;
731 rightmost_x = verts[i].x;
732 }
733 }
734
735 ASSERT(rightmost_point != -1);
736 return rightmost_point;
737}
738
739// returns the index in the face_verts array for the most point on this face
740int HTextureGetBottomVertexForFace(int roomnum, int facenum) {

Callers

nothing calls this directly

Calls 5

vm_MakeZeroFunction · 0.85
vm_VectorToMatrixFunction · 0.50
vm_AnglesToMatrixFunction · 0.50
vm_MatrixMulVectorFunction · 0.50

Tested by

no test coverage detected