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
| 815 | // Returns: true if the normal is ok |
| 816 | // false if the normal has a very small (pre-normalization) magnitude |
| 817 | bool 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 |
| 849 | void ComputePortalCenter(vector *vp, room *rp, int portal_index) { |
no test coverage detected