29 using System.Collections.Generic;
30 using System.Diagnostics;
32 namespace OpenSim.
Region.PhysicsModules.ConvexDecompositionDotNet
41 public static class PlaneTri
43 private static float DistToPt(float3 p, float4 plane)
45 return p.x * plane.x + p.y * plane.y + p.z * plane.z + plane.w;
48 private static PlaneTriResult getSidePlane(float3 p, float4 plane,
float epsilon)
50 float d = DistToPt(p, plane);
52 if ((d + epsilon) > 0f)
53 return PlaneTriResult.PTR_FRONT;
55 return PlaneTriResult.PTR_BACK;
58 private static void add(float3 p, float3[] dest, ref
int pcount)
60 dest[pcount++] =
new float3(p);
61 Debug.Assert(pcount <= 4);
65 private static void intersect(float3 p1, float3 p2, float3 split, float4 plane)
67 float dp1 = DistToPt(p1, plane);
68 float[] dir =
new float[3];
70 dir[0] = p2[0] - p1[0];
71 dir[1] = p2[1] - p1[1];
72 dir[2] = p2[2] - p1[2];
74 float dot1 = dir[0] * plane[0] + dir[1] * plane[1] + dir[2] * plane[2];
75 float dot2 = dp1 - plane[3];
77 float t = -(plane[3] + dot2) / dot1;
79 split.x = (dir[0] * t) + p1[0];
80 split.y = (dir[1] * t) + p1[1];
81 split.z = (dir[2] * t) + p1[2];
84 public static PlaneTriResult planeTriIntersection(float4 plane, FaceTri triangle,
float epsilon, ref float3[] front, out
int fcount, ref float3[] back, out
int bcount)
90 float3 p1 = triangle.P1;
91 float3 p2 = triangle.P2;
92 float3 p3 = triangle.P3;
98 if (r1 == r2 && r1 == r3)
102 add(p1, front, ref fcount);
103 add(p2, front, ref fcount);
104 add(p3, front, ref fcount);
108 add(p1, back, ref bcount);
109 add(p2, back, ref bcount);
110 add(p3, back, ref bcount);
122 add(p1, front, ref fcount);
123 add(p2, front, ref fcount);
127 add(p1, back, ref bcount);
128 add(p2, back, ref bcount);
133 float3 split =
new float3();
134 intersect(p1, p2, split, plane);
139 add(p1, front, ref fcount);
140 add(split, front, ref fcount);
142 add(split, back, ref bcount);
143 add(p2, back, ref bcount);
148 add(p1, back, ref bcount);
149 add(split, back, ref bcount);
151 add(split, front, ref fcount);
152 add(p2, front, ref fcount);
162 add(p3, front, ref fcount);
166 add(p3, back, ref bcount);
171 float3 split =
new float3();
172 intersect(p2, p3, split, plane);
176 add(split, front, ref fcount);
177 add(split, back, ref bcount);
179 add(p3, front, ref fcount);
183 add(split, front, ref fcount);
184 add(split, back, ref bcount);
186 add(p3, back, ref bcount);
193 float3 split =
new float3();
194 intersect(p3, p1, split, plane);
198 add(split, front, ref fcount);
199 add(split, back, ref bcount);
203 add(split, front, ref fcount);
204 add(split, back, ref bcount);
208 return PlaneTriResult.PTR_SPLIT;