29 using System.Collections.Generic;
31 namespace OpenSim.
Region.PhysicsModules.ConvexDecompositionDotNet
35 public float[] mMin =
new float[3];
36 public float[] mMax =
new float[3];
42 public Rect3d(
float[] bmin,
float[] bmax)
67 public void SetMin(
float x,
float y,
float z)
74 public void SetMax(
float x,
float y,
float z)
82 public static class SplitPlane
84 public static bool computeSplitPlane(List<float3> vertices, List<int> indices, ref float4 plane)
86 float[] bmin = { Single.MaxValue, Single.MaxValue, Single.MaxValue };
87 float[] bmax = { Single.MinValue, Single.MinValue, Single.MinValue };
89 for (
int i = 0; i < vertices.Count; i++)
91 float3 p = vertices[i];
108 float dx = bmax[0] - bmin[0];
109 float dy = bmax[1] - bmin[1];
110 float dz = bmax[2] - bmin[2];
122 if (dz > dx && dz > dy)
128 float[] p1 =
new float[3];
129 float[] p2 =
new float[3];
130 float[] p3 =
new float[3];
132 p3[0] = p2[0] = p1[0] = bmin[0] + dx * 0.5f;
133 p3[1] = p2[1] = p1[1] = bmin[1] + dy * 0.5f;
134 p3[2] = p2[2] = p1[2] = bmin[2] + dz * 0.5f;
136 Rect3d b =
new Rect3d(bmin, bmax);
138 Rect3d b1 =
new Rect3d();
139 Rect3d b2 =
new Rect3d();
141 splitRect(axis, b, b1, b2, p1);
195 computePlane(p1, p2, p3, plane);
200 internal static void computePlane(
float[] A,
float[] B,
float[] C, float4 plane)
202 float vx = (B[0] - C[0]);
203 float vy = (B[1] - C[1]);
204 float vz = (B[2] - C[2]);
206 float wx = (A[0] - B[0]);
207 float wy = (A[1] - B[1]);
208 float wz = (A[2] - B[2]);
210 float vw_x = vy * wz - vz * wy;
211 float vw_y = vz * wx - vx * wz;
212 float vw_z = vx * wy - vy * wx;
214 float mag = (float)Math.Sqrt((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z));
225 float x = vw_x * mag;
226 float y = vw_y * mag;
227 float z = vw_z * mag;
229 float D = 0.0f - ((x * A[0]) + (y * A[1]) + (z * A[2]));
237 public static void splitRect(
int axis, Rect3d source, Rect3d b1, Rect3d b2,
float[] midpoint)
242 b1.SetMin(source.mMin);
243 b1.SetMax(midpoint[0], source.mMax[1], source.mMax[2]);
245 b2.SetMin(midpoint[0], source.mMin[1], source.mMin[2]);
246 b2.SetMax(source.mMax);
249 b1.SetMin(source.mMin);
250 b1.SetMax(source.mMax[0], midpoint[1], source.mMax[2]);
252 b2.SetMin(source.mMin[0], midpoint[1], source.mMin[2]);
253 b2.SetMax(source.mMax);
256 b1.SetMin(source.mMin);
257 b1.SetMax(source.mMax[0], source.mMax[1], midpoint[2]);
259 b2.SetMin(source.mMin[0], source.mMin[1], midpoint[2]);
260 b2.SetMax(source.mMax);
void SetMin(float x, float y, float z)
Rect3d(float[] bmin, float[] bmax)
void SetMax(float x, float y, float z)
void SetMax(float[] bmax)
void SetMin(float[] bmin)