Exemple #1
0
        // Token: 0x06001A06 RID: 6662 RVA: 0x000BA6C0 File Offset: 0x000B88C0
        public static void PreciseAlign(ref GameObject gameObjectInOut, Vector3 alignWithVector, Vector3 alignWithNormal, Vector3 alignWithPosition, Vector3 triangleForward, Vector3 triangleNormal, Vector3 trianglePosition)
        {
            Math3d.LookRotationExtended(ref gameObjectInOut, alignWithVector, alignWithNormal, triangleForward, triangleNormal);
            Vector3 b           = gameObjectInOut.transform.TransformPoint(trianglePosition);
            Vector3 translation = alignWithPosition - b;

            gameObjectInOut.transform.Translate(translation, Space.World);
        }
Exemple #2
0
        /// <summary>
        /// 空间中一个点在一个面上的投影点
        /// </summary>
        /// <param name="face"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static Vector3 ProjectPointOnPlane(Face face, Vector3 point)
        {
            float num = Math3d.SignedDistancePlanePoint(face, point);

            num *= -1f;
            Vector3 b = Math3d.SetVectorLength(face.normal, num);

            return(point + b);
        }
Exemple #3
0
        /// <summary>
        /// 鼠标位置到一条线段的距离
        /// </summary>
        public static float MouseDistanceToLine(Vector3 linePoint1, Vector3 linePoint2)
        {
            Camera  main          = Camera.main;
            Vector3 mousePosition = Input.mousePosition;
            Vector3 linePoint3    = main.WorldToScreenPoint(linePoint1);
            Vector3 linePoint4    = main.WorldToScreenPoint(linePoint2);
            Vector3 a             = Math3d.ProjectPointOnLineSegment(linePoint3, linePoint4, mousePosition);

            a = new Vector3(a.x, a.y, 0f);
            return((a - mousePosition).magnitude);
        }
Exemple #4
0
        /// <summary>
        /// 三个点构造一个平面
        /// </summary>
        public static Face PlaneFrom3Points(Vector3 pointA, Vector3 pointB, Vector3 pointC)
        {
            Vector3 vector      = pointB - pointA;
            Vector3 vector2     = pointC - pointA;
            Vector3 planeNormal = Vector3.Normalize(Vector3.Cross(vector, vector2));
            Vector3 vector3     = pointA + vector / 2f;
            Vector3 vector4     = pointA + vector2 / 2f;
            Vector3 lineVec     = pointC - vector3;
            Vector3 lineVec2    = pointB - vector4;

            Math3d.ClosestPointsOnTwoLines(vector3, lineVec, vector4, lineVec2, out Vector3 planePoint, out Vector3 vector5);
            return(new Face(planePoint, planeNormal));
        }
Exemple #5
0
        // Token: 0x06001A0D RID: 6669 RVA: 0x000BA974 File Offset: 0x000B8B74
        public static bool AreLineSegmentsCrossing(Vector3 pointA1, Vector3 pointA2, Vector3 pointB1, Vector3 pointB2)
        {
            Vector3 vector  = pointA2 - pointA1;
            Vector3 vector2 = pointB2 - pointB1;
            bool    flag    = Math3d.ClosestPointsOnTwoLines(pointA1, vector.normalized, pointB1, vector2.normalized, out Vector3 point, out Vector3 point2);

            if (flag)
            {
                int num  = Math3d.PointOnWhichSideOfLineSegment(pointA1, pointA2, point);
                int num2 = Math3d.PointOnWhichSideOfLineSegment(pointB1, pointB2, point2);
                return(num == 0 && num2 == 0);
            }
            return(false);
        }
Exemple #6
0
        /// <summary>
        /// 线面是否相交
        /// </summary>
        /// <param name="intersection">交点</param>
        /// <param name="linePoint"></param>
        /// <param name="lineVec"></param>
        /// <param name="face"></param>
        /// <returns>是否相交</returns>
        public static bool LinePlaneIntersection(Vector3 linePoint, Vector3 lineVec, Face face, out Vector3 intersection)
        {
            intersection = Vector3.zero;
            float num  = Vector3.Dot(face.point - linePoint, face.normal);
            float num2 = Vector3.Dot(lineVec, face.normal);

            if (num2 != 0f)
            {
                float   size = num / num2;
                Vector3 b    = Math3d.SetVectorLength(lineVec, size);
                intersection = linePoint + b;
                return(true);
            }
            return(false);
        }
Exemple #7
0
        /// <summary>
        /// 判断点point是否在矩形内
        /// </summary>
        public static bool IsPointInRectangle(Vector3 point, Vector3 rectA, Vector3 rectC, Vector3 rectB, Vector3 rectD)
        {
            Vector3 vector = rectC - rectA;
            float   size   = -(vector.magnitude / 2f);

            vector = Math3d.AddVectorLength(vector, size);
            Vector3 linePoint = rectA + vector;
            Vector3 vector2   = rectB - rectA;
            float   num       = vector2.magnitude / 2f;
            Vector3 vector3   = rectD - rectA;
            float   num2      = vector3.magnitude / 2f;
            Vector3 a         = Math3d.ProjectPointOnLine(linePoint, vector2.normalized, point);
            float   magnitude = (a - point).magnitude;

            a = Math3d.ProjectPointOnLine(linePoint, vector3.normalized, point);
            float magnitude2 = (a - point).magnitude;

            return(magnitude2 <= num && magnitude <= num2);
        }
Exemple #8
0
        /// <summary>
        /// 判断线段是否在矩形内
        /// </summary>
        public static bool IsLineInRectangle(Vector3 linePoint1, Vector3 linePoint2, Vector3 rectA, Vector3 rectB, Vector3 rectC, Vector3 rectD)
        {
            bool flag  = false;
            bool flag2 = Math3d.IsPointInRectangle(linePoint1, rectA, rectC, rectB, rectD);

            if (!flag2)
            {
                flag = Math3d.IsPointInRectangle(linePoint2, rectA, rectC, rectB, rectD);
            }
            if (!flag2 && !flag)
            {
                bool flag3 = Math3d.AreLineSegmentsCrossing(linePoint1, linePoint2, rectA, rectB);
                bool flag4 = Math3d.AreLineSegmentsCrossing(linePoint1, linePoint2, rectB, rectC);
                bool flag5 = Math3d.AreLineSegmentsCrossing(linePoint1, linePoint2, rectC, rectD);
                bool flag6 = Math3d.AreLineSegmentsCrossing(linePoint1, linePoint2, rectD, rectA);
                return(flag3 || flag4 || flag5 || flag6);
            }
            return(true);
        }
Exemple #9
0
        /// <summary>
        ///  一个点在一条线段上的投影点
        /// </summary>
        /// <param name="linePoint1"></param>
        /// <param name="linePoint2"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static Vector3 ProjectPointOnLineSegment(Vector3 linePoint1, Vector3 linePoint2, Vector3 point)
        {
            Vector3 vector = Math3d.ProjectPointOnLine(linePoint1, (linePoint2 - linePoint1).normalized, point);
            int     num    = Math3d.PointOnWhichSideOfLineSegment(linePoint1, linePoint2, vector);

            if (num == 0)
            {
                return(vector);
            }
            if (num == 1)
            {
                return(linePoint1);
            }
            if (num == 2)
            {
                return(linePoint2);
            }
            return(Vector3.zero);
        }
Exemple #10
0
        /// <summary>
        /// 获取贝塞尔曲线(3个点为二次,4个点为三次,其他返回空)
        /// </summary>
        /// <param name="_points">控制点集</param>
        /// <param name="_count">曲线段数</param>
        /// <returns></returns>
        public static List <Vector3> GetBezierList(Vector3[] _points, int _count = 10)
        {
            List <Vector3> outList = new List <Vector3>();

            if (_points.Length == 3)
            {
                for (float i = 0; i <= _count; i++)
                {
                    outList.Add(Math3d.GetBezierPoint(i / _count, _points[0], _points[1], _points[2]));
                }
            }
            if (_points.Length == 4)
            {
                for (float i = 0; i <= _count; i++)
                {
                    outList.Add(Math3d.GetBezierPoint(i / _count, _points[0], _points[1], _points[2], _points[3]));
                }
            }
            return(outList);
        }