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

Function ComputeNormal

Descent3/room.cpp:817–846  ·  view source on GitHub ↗

Compute the surface normal from a list of vertices that determine a face Finds the best normal on this face by checking all sets of three vertices IMPORTANT: The caller should really check the return value of this function Parameters: normal - this is filled in with the normal num_verts - how many vertices in the face vertnum_list - a list of vertex numbers for this face. these index into verts

Source from the content-addressed store, hash-verified

815// Returns: true if the normal is ok
816// false if the normal has a very small (pre-normalization) magnitude
817bool ComputeNormal(vector *normal, int num_verts, short *vertnum_list, vector *verts) {
818 int i;
819 float largest_mag;
820
821 i = 0;
822 largest_mag = 0.0;
823
824 for (i = 0; i < num_verts; i++) {
825 vector tnormal;
826 float mag;
827
828 mag = vm_GetNormal(&tnormal, &verts[vertnum_list[i]], &verts[vertnum_list[(i + 1) % num_verts]],
829 &verts[vertnum_list[(i + 2) % num_verts]]);
830
831 if (mag > largest_mag) {
832 *normal = tnormal;
833 largest_mag = mag;
834 }
835 }
836
837 if (largest_mag < MIN_NORMAL_MAG) {
838 mprintf(1, "Warning: Normal has low precision. mag = %f, norm = %f,%f,%f\n",
839 largest_mag,
840 normal->x,
841 normal->y,
842 normal->z);
843 return 0;
844 } else
845 return 1;
846}
847
848// Computes the center point on a face by averaging the points in the portal
849void ComputePortalCenter(vector *vp, room *rp, int portal_index) {

Callers 4

Read3DSMaxFileFunction · 0.85
RotateRoomsFunction · 0.85
CombineFacesFunction · 0.85
ComputeFaceNormalFunction · 0.85

Calls 1

vm_GetNormalFunction · 0.50

Tested by

no test coverage detected