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

Function CombineLightFaces

editor/editor_lighting.cpp:2743–2799  ·  view source on GitHub ↗

Returns number of verts in dest if face a can be safely combined with face b Returns 0 if not

Source from the content-addressed store, hash-verified

2741// Returns number of verts in dest if face a can be safely combined with face b
2742// Returns 0 if not
2743int CombineLightFaces(vector *dest_verts, vector *averts, int nva, vector *norma, vector *bverts, int nvb,
2744 vector *normb, int aroom, int broom) {
2745 int i;
2746
2747 float dp;
2748
2749 dp = vm_DotProduct(normb, norma);
2750
2751 if (dp < LM_ADJACENT_FACE_THRESHOLD)
2752 return 0;
2753
2754 ASSERT(nva > 2);
2755 ASSERT(nvb > 2);
2756
2757 // Go through each vertex and get a match
2758
2759 // If these two faces are in the same room and are on the same plane
2760 // then we should combine them by default
2761
2762 if (1 || (aroom != -1 && aroom == broom)) {
2763 int dnv = 0;
2764 int match = 0;
2765
2766 // Don't go over our point limit
2767 if ((nva + nvb) >= (MAX_VERTS_PER_FACE * 5))
2768 return 0;
2769
2770 // Test to see if any points at all can touch
2771
2772 for (i = 0; i < nva && !match; i++) {
2773 for (int t = 0; t < nvb && !match; t++) {
2774 if (PointsAreSame(&averts[i], &bverts[t]))
2775 match = 1;
2776 }
2777 }
2778
2779 if (!match)
2780 return 0;
2781
2782 // At least one point is the same, so combine them!
2783 for (i = 0; i < nva; i++) {
2784 dest_verts[dnv] = averts[i];
2785 dnv++;
2786 ASSERT(dnv < MAX_VERTS_PER_FACE * 5);
2787 }
2788
2789 for (i = 0; i < nvb; i++) {
2790 dest_verts[dnv] = bverts[i];
2791 dnv++;
2792 ASSERT(dnv < MAX_VERTS_PER_FACE * 5);
2793 }
2794
2795 return dnv;
2796 }
2797
2798 return 0;
2799}
2800

Callers 2

TestObjectLightAdjacencyFunction · 0.85
TestLightAdjacencyFunction · 0.85

Calls 2

PointsAreSameFunction · 0.85
vm_DotProductFunction · 0.50

Tested by 2

TestObjectLightAdjacencyFunction · 0.68
TestLightAdjacencyFunction · 0.68