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

Function ComputeDebugVisFaceUpperLeft

Descent3/renderobject.cpp:772–858  ·  view source on GitHub ↗

Given a face, computes the upper left corner of the face

Source from the content-addressed store, hash-verified

770}
771// Given a face, computes the upper left corner of the face
772void ComputeDebugVisFaceUpperLeft(room *rp, face *fp, vector *upper_left, float *xdiff, float *ydiff, vector *center) {
773 matrix face_matrix, trans_matrix;
774 vector fvec;
775 vector avg_vert;
776 vector verts[MAX_VERTS_PER_FACE];
777 vector rot_vert;
778 int i;
779
780 // find the center point of this face
781 vm_MakeZero(&avg_vert);
782 for (i = 0; i < fp->num_verts; i++)
783 avg_vert += rp->verts[fp->face_verts[i]];
784 avg_vert /= fp->num_verts;
785 // Make the orientation matrix
786 // Reverse the normal because we're looking "at" the face, not from it
787 fvec = -fp->normal;
788
789 vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL);
790 // Make the transformation matrix
791
792 angvec avec;
793 vm_ExtractAnglesFromMatrix(&avec, &face_matrix);
794 vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b);
795
796 // Rotate all the points
797 for (i = 0; i < fp->num_verts; i++) {
798 vector vert = rp->verts[fp->face_verts[i]];
799
800 vert -= avg_vert;
801 vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix);
802 verts[i] = rot_vert;
803 }
804 // Find left most point
805 int leftmost_point = -1;
806 float leftmost_x = 900000.00f; // a big number
807 for (i = 0; i < fp->num_verts; i++) {
808 if (verts[i].x < leftmost_x) {
809 leftmost_point = i;
810 leftmost_x = verts[i].x;
811 }
812 }
813 ASSERT(leftmost_point != -1);
814 // Find top most point
815 int topmost_point = -1;
816 float topmost_y = -900000.0f; // a big number
817 for (i = 0; i < fp->num_verts; i++) {
818 if (verts[i].y > topmost_y) {
819 topmost_point = i;
820 topmost_y = verts[i].y;
821 }
822 }
823 ASSERT(topmost_point != -1);
824 // Find right most point
825 int rightmost_point = -1;
826 float rightmost_x = -900000.00f; // a big number
827 for (i = 0; i < fp->num_verts; i++) {
828 if (verts[i].x > rightmost_x) {
829 rightmost_point = i;

Callers 1

DrawRoomVisPntsFunction · 0.85

Calls 6

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

Tested by

no test coverage detected