Example #1
0
    /// <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);
    }
Example #2
0
    public static QuaternionL RotateTowards(QuaternionL from, QuaternionL to, FloatL maxDegreesDelta)
    {
        FloatL num = QuaternionL.Angle(from, to);

        if (num == 0f)
        {
            return(to);
        }
        FloatL t = FixPointMath.Min(1f, maxDegreesDelta / num);

        return(QuaternionL.SlerpUnclamped(from, to, 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);
    }
Example #6
0
 public static Vector2L Min(Vector2L lhs, Vector2L rhs)
 {
     return(new Vector2L(FixPointMath.Min(lhs.x, rhs.x), FixPointMath.Min(lhs.y, rhs.y)));
 }
 public static Vector3L Min(Vector3L lhs, Vector3L rhs)
 {
     return(new Vector3L(FixPointMath.Min(lhs.x, rhs.x), FixPointMath.Min(lhs.y, rhs.y), FixPointMath.Min(lhs.z, rhs.z)));
 }
Example #8
0
    public static FloatL Angle(QuaternionL a, QuaternionL b)
    {
        FloatL f = QuaternionL.Dot(a, b);

        return(FixPointMath.Acos(FixPointMath.Min(FixPointMath.Abs(f), 1f)) * 2f * 57.29578d);
    }