public void setxyz(float3 xyz) { x = xyz.x; y = xyz.y; z = xyz.z; }
public static float4x4 MatrixTranslation(float3 t) { return(new float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t.x, t.y, t.z, 1)); }
public static float4 Homogenize(float3 v3) { return(Homogenize(v3, 1.0f)); }
//C++ TO C# CONVERTER NOTE: C# does not allow default values for parameters. Overloaded methods are inserted above. //ORIGINAL LINE: float4 Homogenize(const float3 &v3, const float &w =1.0f) public static float4 Homogenize(float3 v3, float w) { return(new float4(v3.x, v3.y, v3.z, w)); }
private static bool lineIntersectsTriangle(float3 rayStart, float3 rayEnd, float3 p1, float3 p2, float3 p3, ref float3 sect) { float3 dir = rayEnd - rayStart; float d = (float)Math.Sqrt(dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]); float r = 1.0f / d; dir *= r; float t; bool ret = rayIntersectsTriangle(rayStart, dir, p1, p2, p3, out t); if (ret) { if (t > d) { sect.x = rayStart.x + dir.x * t; sect.y = rayStart.y + dir.y * t; sect.z = rayStart.z + dir.z * t; } else { ret = false; } } return(ret); }
public Wpoint(float3 p, float w) { mPoint = p; mWeight = w; }
private static bool rayIntersectsTriangle(float3 p, float3 d, float3 v0, float3 v1, float3 v2, out float t) { t = 0f; float3 e1, e2, h, s, q; float a, f, u, v; e1 = v1 - v0; e2 = v2 - v0; h = float3.cross(d, e2); a = float3.dot(e1, h); if (a > -0.00001f && a < 0.00001f) { return(false); } f = 1f / a; s = p - v0; u = f * float3.dot(s, h); if (u < 0.0f || u > 1.0f) { return(false); } q = float3.cross(s, e1); v = f * float3.dot(d, q); if (v < 0.0f || u + v > 1.0f) { return(false); } // at this stage we can compute t to find out where // the intersection point is on the line t = f * float3.dot(e2, q); if (t > 0f) // ray intersection { return(true); } else // this means that there is a line intersection but not a ray intersection { return(false); } }
public bool Concave(float3 p, ref float distance, ref float3 n) { n.NearestPointInTriangle(p, mP1, mP2, mP3); distance = p.Distance(n); return(true); }
public static void calcConvexDecomposition(List <float3> vertices, List <int> indices, ConvexDecompositionCallback callback, float masterVolume, int depth, int maxDepth, float concavePercent, float mergePercent) { float4 plane = new float4(); bool split = false; if (depth < maxDepth) { float volume = 0f; float c = Concavity.computeConcavity(vertices, indices, ref plane, ref volume); if (depth == 0) { masterVolume = volume; } float percent = (c * 100.0f) / masterVolume; if (percent > concavePercent) // if great than 5% of the total volume is concave, go ahead and keep splitting. { split = true; } } if (depth >= maxDepth || !split) { HullResult result = new HullResult(); HullDesc desc = new HullDesc(); desc.SetHullFlag(HullFlag.QF_TRIANGLES); desc.Vertices = vertices; HullError ret = HullUtils.CreateConvexHull(desc, ref result); if (ret == HullError.QE_OK) { ConvexResult r = new ConvexResult(result.OutputVertices, result.Indices); callback(r); } return; } List <int> ifront = new List <int>(); List <int> iback = new List <int>(); VertexPool vfront = new VertexPool(); VertexPool vback = new VertexPool(); // ok..now we are going to 'split' all of the input triangles against this plane! for (int i = 0; i < indices.Count / 3; i++) { int i1 = indices[i * 3 + 0]; int i2 = indices[i * 3 + 1]; int i3 = indices[i * 3 + 2]; FaceTri t = new FaceTri(vertices, i1, i2, i3); float3[] front = new float3[4]; float3[] back = new float3[4]; int fcount = 0; int bcount = 0; PlaneTriResult result = PlaneTri.planeTriIntersection(plane, t, 0.00001f, ref front, out fcount, ref back, out bcount); if (fcount > 4 || bcount > 4) { result = PlaneTri.planeTriIntersection(plane, t, 0.00001f, ref front, out fcount, ref back, out bcount); } switch (result) { case PlaneTriResult.PTR_FRONT: Debug.Assert(fcount == 3); addTri(vfront, ifront, front[0], front[1], front[2]); break; case PlaneTriResult.PTR_BACK: Debug.Assert(bcount == 3); addTri(vback, iback, back[0], back[1], back[2]); break; case PlaneTriResult.PTR_SPLIT: Debug.Assert(fcount >= 3 && fcount <= 4); Debug.Assert(bcount >= 3 && bcount <= 4); addTri(vfront, ifront, front[0], front[1], front[2]); addTri(vback, iback, back[0], back[1], back[2]); if (fcount == 4) { addTri(vfront, ifront, front[0], front[2], front[3]); } if (bcount == 4) { addTri(vback, iback, back[0], back[2], back[3]); } break; } } // ok... here we recursively call if (ifront.Count > 0) { // 20131224 not used int vcount = vfront.GetSize(); List <float3> vertices2 = vfront.GetVertices(); for (int i = 0; i < vertices2.Count; i++) { vertices2[i] = new float3(vertices2[i]); } // 20131224 not used int tcount = ifront.Count / 3; calcConvexDecomposition(vertices2, ifront, callback, masterVolume, depth + 1, maxDepth, concavePercent, mergePercent); } ifront.Clear(); vfront.Clear(); if (iback.Count > 0) { // 20131224 not used int vcount = vback.GetSize(); List <float3> vertices2 = vback.GetVertices(); // 20131224 not used int tcount = iback.Count / 3; calcConvexDecomposition(vertices2, iback, callback, masterVolume, depth + 1, maxDepth, concavePercent, mergePercent); } iback.Clear(); vback.Clear(); }
private static void addTri(VertexPool vl, List <int> list, float3 p1, float3 p2, float3 p3) { int i1 = vl.getIndex(p1); int i2 = vl.getIndex(p2); int i3 = vl.getIndex(p3); // do *not* process degenerate triangles! if (i1 != i2 && i1 != i3 && i2 != i3) { list.Add(i1); list.Add(i2); list.Add(i3); } }
public FaceTri(List <float3> vertices, int i1, int i2, int i3) { P1 = new float3(vertices[i1]); P2 = new float3(vertices[i2]); P3 = new float3(vertices[i3]); }