| 640 | int this_vertex(reading_face *f, int v) { return f->face_verts[v]; } |
| 641 | |
| 642 | int compute_faces_mapping(reading_face *f, vector *out_norm, float *out_d) { |
| 643 | int i; |
| 644 | float ut, vt, len; |
| 645 | vector point, u, v; |
| 646 | vector normal; |
| 647 | |
| 648 | vm_MakeZero(&point); |
| 649 | vm_MakeZero(&normal); |
| 650 | |
| 651 | ut = vt = 0.0f; |
| 652 | |
| 653 | for (i = 0; i < f->num_verts; i++) { |
| 654 | u.x = f->face_uvls[i].u; |
| 655 | u.y = f->face_uvls[i].v; |
| 656 | u.z = 1.0f; |
| 657 | |
| 658 | v.x = f->face_uvls[(i + 1) % f->num_verts].u; |
| 659 | v.y = f->face_uvls[(i + 1) % f->num_verts].v; |
| 660 | v.z = 1.0f; |
| 661 | |
| 662 | ut += (float)fabs(u.x - v.x); |
| 663 | vt += (float)fabs(u.y - v.y); |
| 664 | |
| 665 | normal.x += (u.y - v.y) * (u.z + v.z); |
| 666 | normal.y += (u.z - v.z) * (u.x + v.x); |
| 667 | normal.z += (u.x - v.x) * (u.y + v.y); |
| 668 | point += u; |
| 669 | } |
| 670 | |
| 671 | len = vm_GetMagnitude(&normal); |
| 672 | |
| 673 | out_norm->x = normal.x / len; |
| 674 | out_norm->y = normal.y / len; |
| 675 | out_norm->z = normal.z / len; |
| 676 | len *= f->num_verts; |
| 677 | *out_d = (vm_DotProduct(&point, &normal) / len); |
| 678 | point.x /= f->num_verts; |
| 679 | point.y /= f->num_verts; |
| 680 | point.z /= f->num_verts; |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | // Returns 1 if the uv's match |
| 686 | int uvs_match(reading_face *a, int va, reading_face *b, int vb) { |
no test coverage detected