/// <summary> /// 3d空间中点到直线距离 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="s"></param> /// <returns></returns> // public static FloatL DistanceOfPoint3dWithLine3d(Line3d line3d, Vector3L s) // { // FloatL ab = FixPointMath.Sqrt(FixPointMath.Pow((line3d.m_point1.x - line3d.m_point2.x), 2.0f) + FixPointMath.Pow((line3d.m_point1.y - line3d.m_point2.y), 2.0f) + FixPointMath.Pow((line3d.m_point1.z - line3d.m_point2.z), 2.0f)); // FloatL as2 = FixPointMath.Sqrt(FixPointMath.Pow((line3d.m_point1.x - s.x), 2.0f) + FixPointMath.Pow((line3d.m_point1.y - s.y), 2.0f) + FixPointMath.Pow((line3d.m_point1.z - s.z), 2.0f)); // FloatL bs = FixPointMath.Sqrt(FixPointMath.Pow((s.x - line3d.m_point2.x), 2.0f) + FixPointMath.Pow((s.y - line3d.m_point2.y), 2.0f) + FixPointMath.Pow((s.z - line3d.m_point2.z), 2.0f)); // FloatL cos_A = (FixPointMath.Pow(as2, 2.0f) + FixPointMath.Pow(ab, 2.0f) - FixPointMath.Pow(bs, 2.0f)) / (2 * ab * as2); // FloatL sin_A = FixPointMath.Sqrt(1 - FixPointMath.Pow(cos_A, 2.0f)); // return as2 * sin_A; // } public static Vector3L ClosestPointOfPoint3dWithSegment3d(Vector3L point, Segment3d line) { Vector3L lVec = line.m_point2 - line.m_point1; // Line Vector FloatL t = Vector3L.Dot(point - line.m_point1, lVec) / Vector3L.Dot(lVec, lVec); t = FixPointMath.Max(t, 0.0f); // Clamp to 0 t = FixPointMath.Min(t, 1.0f); // Clamp to 1 return(line.m_point1 + lVec * t); }
public static Vector3L ClosestPointOfPoint3dWithRay3d(Vector3L point, Ray3d ray) { FloatL t = Vector3L.Dot(point - ray.m_rayOrigin, ray.m_rayDir); // We assume the direction of the ray is normalized // If for some reason the direction is not normalized // the below division is needed. So long as the ray // direction is normalized, we don't need this divide // t /= Dot(ray.direction, ray.direction); t = FixPointMath.Max(t, 0.0f); return(ray.m_rayOrigin + ray.m_rayDir * t); }
public AABB3d Merge(AABB3d other) { Vector3L selfMin = GetMin(); Vector3L otherMin = other.GetMin(); Vector3L selfMax = GetMax(); Vector3L otherMax = GetMax(); Vector3L totalMin = new Vector3L(FixPointMath.Min(selfMin.x, otherMin.x), FixPointMath.Min(selfMin.y, otherMin.y), FixPointMath.Min(selfMin.z, otherMin.z)); Vector3L totalMax = new Vector3L(FixPointMath.Max(selfMax.x, otherMax.x), FixPointMath.Max(selfMax.y, otherMax.y), FixPointMath.Max(selfMax.z, otherMax.z)); return(new AABB3d((totalMin + totalMax) / 2, totalMax - totalMin)); }
public void SetContent(Mesh3d mesh) { m_mesh3d = mesh; Vector3L[] vertices = mesh.GetVertices(); Vector3L min = vertices[0]; Vector3L max = vertices[0]; for (int i = 1; i < mesh.m_triangleList.Count * 3; ++i) { min.x = FixPointMath.Min(vertices[i].x, min.x); min.y = FixPointMath.Min(vertices[i].y, min.y); min.z = FixPointMath.Min(vertices[i].z, min.z); max.x = FixPointMath.Max(vertices[i].x, max.x); max.y = FixPointMath.Max(vertices[i].y, max.y); max.z = FixPointMath.Max(vertices[i].z, max.z); } m_aabb = Mesh3d.FromMinMax(min, max); }
public static void AccelerateMesh(Mesh3d mesh) { if (mesh.m_accelerator != null) { return; } Vector3L[] vertices = mesh.GetVertices(); Vector3L min = vertices[0]; Vector3L max = vertices[0]; for (int i = 1; i < mesh.m_triangleList.Count * 3; ++i) { min.x = FixPointMath.Min(vertices[i].x, min.x); min.y = FixPointMath.Min(vertices[i].y, min.y); min.z = FixPointMath.Min(vertices[i].z, min.z); max.x = FixPointMath.Max(vertices[i].x, max.x); max.y = FixPointMath.Max(vertices[i].y, max.y); max.z = FixPointMath.Max(vertices[i].z, max.z); } mesh.m_accelerator = new BVHNode(); mesh.m_accelerator.m_bounds = FromMinMax(min, max); mesh.m_accelerator.m_children = null; // this.m_accelerator.m_triangles = this.m_triangleList.Count; // this.m_accelerator->triangles = new int[mesh.numTriangles]; // for (int i = 0; i < mesh.numTriangles; ++i) { // mesh.accelerator->triangles[i] = i; // } //this.m_accelerator.m_triangles = this.m_triangleList; // for (int i = 0; i < mesh.m_triangleList.Count; ++i) // { // mesh.m_accelerator.m_triangles.Add(mesh.m_triangleList); // } mesh.m_accelerator.m_triangles.AddRange(mesh.m_triangleList); SplitBVHNode(mesh.m_accelerator, mesh, 3); }
public static Vector2L Max(Vector2L lhs, Vector2L rhs) { return(new Vector2L(FixPointMath.Max(lhs.x, rhs.x), FixPointMath.Max(lhs.y, rhs.y))); }
public static Vector3L Max(Vector3L lhs, Vector3L rhs) { return(new Vector3L(FixPointMath.Max(lhs.x, rhs.x), FixPointMath.Max(lhs.y, rhs.y), FixPointMath.Max(lhs.z, rhs.z))); }
// public static UnityEngine.Vector3 Convert(Vector3L vec) // { // return new UnityEngine.Vector3(vec.x.ToFloat(), vec.y.ToFloat(), vec.z.ToFloat()); // } public static FloatL Max(FloatL a, FloatL b, FloatL c) { return(FixPointMath.Max(FixPointMath.Max(a, b), c)); }