Esempio n. 1
0
        public float getLength(int index)
        {
            index = Mathf.Clamp(index, 0, this.joints.Count - 1);
            RoadJoint roadJoint = this.joints[index];
            RoadJoint roadJoint2;

            if (index == this.joints.Count - 1)
            {
                roadJoint2 = this.joints[0];
            }
            else
            {
                roadJoint2 = this.joints[index + 1];
            }
            return(BezierTool.getLength(roadJoint.vertex, roadJoint.vertex + roadJoint.getTangent(1), roadJoint2.vertex + roadJoint2.getTangent(0), roadJoint2.vertex));
        }
Esempio n. 2
0
        // Token: 0x0600266B RID: 9835 RVA: 0x000E1CC0 File Offset: 0x000E00C0
        public Vector3 getVelocity(int index, float t)
        {
            index = Mathf.Clamp(index, 0, this.joints.Count - 1);
            t     = Mathf.Clamp01(t);
            RoadJoint roadJoint = this.joints[index];
            RoadJoint roadJoint2;

            if (index == this.joints.Count - 1)
            {
                roadJoint2 = this.joints[0];
            }
            else
            {
                roadJoint2 = this.joints[index + 1];
            }
            return(BezierTool.getVelocity(roadJoint.vertex, roadJoint.vertex + roadJoint.getTangent(1), roadJoint2.vertex + roadJoint2.getTangent(0), roadJoint2.vertex, t));
        }
Esempio n. 3
0
        // Token: 0x060033C9 RID: 13257 RVA: 0x001506DC File Offset: 0x0014EADC
        public static float getLengthBruteForce(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float uniformInterval, float intervalTolerance, int attempts)
        {
            float lengthEstimate = BezierTool.getLengthEstimate(a, b, c, d);

            attempts = Mathf.Max(1, attempts);
            int     num    = Mathf.CeilToInt(lengthEstimate / uniformInterval);
            float   num2   = 1f / (float)num;
            float   num3   = num2;
            float   num4   = uniformInterval;
            Vector3 vector = a;
            double  num5   = 0.0;
            double  num6   = 0.0;

            while (num6 < 1.0)
            {
                Vector3 vector2 = vector;
                for (int i = 0; i < attempts; i++)
                {
                    float t = (float)(num6 + (double)num3);
                    vector2 = BezierTool.getPosition(a, a + b, d + c, d, t);
                    num4    = (vector2 - vector).magnitude;
                    if (i < attempts - 1)
                    {
                        float num7 = Mathf.Abs(num4 - uniformInterval);
                        if (num7 < intervalTolerance)
                        {
                            break;
                        }
                        if (i < attempts - 1)
                        {
                            num3 *= intervalTolerance / num4;
                        }
                    }
                }
                Debug.Log(num4);
                vector = vector2;
                num5  += (double)num4;
                num6  += (double)num3;
                num3   = num2;
            }
            return((float)num5);
        }
Esempio n. 4
0
        // Token: 0x0600266D RID: 9837 RVA: 0x000E1DBC File Offset: 0x000E01BC
        public float getLengthEstimate(int index)
        {
            index = Mathf.Clamp(index, 0, this.joints.Count - 1);
            RoadJoint roadJoint = this.joints[index];
            RoadJoint roadJoint2;

            if (index == this.joints.Count - 1)
            {
                roadJoint2 = this.joints[0];
            }
            else
            {
                roadJoint2 = this.joints[index + 1];
            }
            Vector3 tangent  = roadJoint.getTangent(1);
            Vector3 tangent2 = roadJoint2.getTangent(0);

            if (Vector3.Dot(tangent.normalized, tangent2.normalized) < -0.999f)
            {
                return((roadJoint2.vertex - roadJoint.vertex).magnitude);
            }
            return(BezierTool.getLengthEstimate(roadJoint.vertex, roadJoint.vertex + tangent, roadJoint2.vertex + tangent2, roadJoint2.vertex));
        }
Esempio n. 5
0
        // Token: 0x06002669 RID: 9833 RVA: 0x000E1B74 File Offset: 0x000DFF74
        public Vector3 getPosition(int index, float t)
        {
            index = Mathf.Clamp(index, 0, this.joints.Count - 1);
            t     = Mathf.Clamp01(t);
            RoadJoint roadJoint = this.joints[index];
            RoadJoint roadJoint2;

            if (index == this.joints.Count - 1)
            {
                roadJoint2 = this.joints[0];
            }
            else
            {
                roadJoint2 = this.joints[index + 1];
            }
            Vector3 tangent  = roadJoint.getTangent(1);
            Vector3 tangent2 = roadJoint2.getTangent(0);

            if (Vector3.Dot(tangent.normalized, tangent2.normalized) < -0.999f)
            {
                return(Vector3.Lerp(roadJoint.vertex, roadJoint2.vertex, t));
            }
            return(BezierTool.getPosition(roadJoint.vertex, roadJoint.vertex + tangent, roadJoint2.vertex + tangent2, roadJoint2.vertex, t));
        }
Esempio n. 6
0
        // Token: 0x060033C8 RID: 13256 RVA: 0x00150500 File Offset: 0x0014E900
        public static float getTFromDistance(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float distance, float uniformInterval, float intervalTolerance, int attempts, float cachedLength = -1f)
        {
            if (distance < 0f)
            {
                return(0f);
            }
            float num;

            if (cachedLength < 0f)
            {
                num = BezierTool.getLengthEstimate(a, b, c, d);
            }
            else
            {
                num = cachedLength;
            }
            if (distance >= num)
            {
                return(1f);
            }
            attempts = Mathf.Max(1, attempts);
            int     num2   = Mathf.CeilToInt(num / uniformInterval);
            float   num3   = 1f / (float)num2;
            float   num4   = num3;
            float   num5   = uniformInterval;
            Vector3 vector = a;
            double  num6   = 0.0;
            double  num7   = 0.0;

            while (num7 < 1.0)
            {
                Vector3 vector2 = vector;
                for (int i = 0; i < attempts; i++)
                {
                    float t = (float)(num7 + (double)num4);
                    vector2 = BezierTool.getPosition(a, a + b, d + c, d, t);
                    num5    = (vector2 - vector).magnitude;
                    if (i < attempts - 1)
                    {
                        float num8 = Mathf.Abs(num5 - uniformInterval);
                        if (num8 < intervalTolerance)
                        {
                            break;
                        }
                        num4 *= intervalTolerance / num5;
                    }
                }
                double num9 = num6 + (double)num5;
                if ((double)distance >= num6 && (double)distance <= num9)
                {
                    float num10 = (float)(((double)distance - num6) / (double)num5);
                    num10 *= num4;
                    return((float)(num7 + (double)num10));
                }
                vector = vector2;
                num6  += (double)num5;
                num7  += (double)num4;
                num4   = num3;
            }
            Debug.LogWarning(string.Concat(new object[]
            {
                "Failed to find T along curve from distance!\nDistance: ",
                distance,
                " Length: ",
                num,
                "\nInterval: ",
                uniformInterval,
                " Tolerance: ",
                intervalTolerance,
                " Attempts: ",
                attempts
            }));
            return(0.5f);
        }