示例#1
0
        public VFactor GetCosineAngle(VInt3 dest, MoveDirectionState state, out int edgeIndex)
        {
            VInt3 rhs  = this.v1 - this.v0;
            VInt3 num2 = this.v2 - this.v0;
            VInt3 lhs  = dest - this.v0;

            lhs.NormalizeTo(0x3e8);
            rhs.NormalizeTo(0x3e8);
            num2.NormalizeTo(0x3e8);
            long    num4   = VInt3.DotXZLong(ref lhs, ref rhs);
            long    num5   = VInt3.DotXZLong(ref lhs, ref num2);
            VFactor factor = new VFactor {
                den = 0xf4240L
            };

            if (num4 > num5)
            {
                edgeIndex  = this.vi;
                factor.nom = num4;
                return(factor);
            }
            edgeIndex  = (this.vi + 2) % 3;
            factor.nom = num5;
            return(factor);
        }
    private static VInt3 ClosestPoint(ref VInt3 point, ref VInt3 lineStart, ref VInt3 lineDir, int lineLen)
    {
        long num = VInt3.DotXZLong(point - lineStart, lineDir);

        num = IntMath.Clamp(num, 0L, (long)(lineLen * 1000));
        return(IntMath.Divide(lineDir, num, 1000000L) + lineStart);
    }
        public VFactor GetCosineAngle(VInt3 dest, MoveDirectionState state, out int edgeIndex)
        {
            VInt3 vInt  = this.v1 - this.v0;
            VInt3 vInt2 = this.v2 - this.v0;
            VInt3 vInt3 = dest - this.v0;

            vInt3.NormalizeTo(1000);
            vInt.NormalizeTo(1000);
            vInt2.NormalizeTo(1000);
            long    num    = VInt3.DotXZLong(ref vInt3, ref vInt);
            long    num2   = VInt3.DotXZLong(ref vInt3, ref vInt2);
            VFactor result = default(VFactor);

            result.den = 1000000L;
            if (num > num2)
            {
                edgeIndex  = this.vi;
                result.nom = num;
            }
            else
            {
                edgeIndex  = (this.vi + 2) % 3;
                result.nom = num2;
            }
            return(result);
        }
    protected VInt3 CaculateDir(VInt3 currentPosition)
    {
        if (this.path == null || this.path.vectorPath == null || this.path.vectorPath.get_Count() == 0)
        {
            return(VInt3.zero);
        }
        List <VInt3> vectorPath = this.path.vectorPath;

        if (vectorPath.get_Count() == 1)
        {
            vectorPath.Insert(0, currentPosition);
        }
        if (this.currentWaypointIndex >= vectorPath.get_Count())
        {
            this.currentWaypointIndex = vectorPath.get_Count() - 1;
        }
        if (this.currentWaypointIndex <= 1)
        {
            this.currentWaypointIndex = 1;
        }
        while (this.currentWaypointIndex < vectorPath.get_Count() - 1)
        {
            long num = vectorPath.get_Item(this.currentWaypointIndex).XZSqrMagnitude(currentPosition);
            if (num == 0L)
            {
                this.lastFoundWaypointPosition = currentPosition;
                this.lastFoundWaypointTime     = Time.time;
                this.currentWaypointIndex++;
            }
            else
            {
                if (num >= (long)(this.pickNextWaypointDist * this.pickNextWaypointDist))
                {
                    break;
                }
                VInt3 rhs  = vectorPath.get_Item(this.currentWaypointIndex - 1);
                VInt3 lhs  = vectorPath.get_Item(this.currentWaypointIndex);
                VInt3 vInt = lhs - rhs;
                long  num2 = (long)vInt.magnitude2D;
                if (VInt3.DotXZLong(currentPosition - rhs, vInt.NormalizeTo(1000)) < num2 * 1000L)
                {
                    break;
                }
                this.lastFoundWaypointPosition = currentPosition;
                this.lastFoundWaypointTime     = Time.time;
                this.currentWaypointIndex++;
            }
        }
        this.targetPoint       = this.CalculateTargetPoint(currentPosition, vectorPath.get_Item(this.currentWaypointIndex - 1), vectorPath.get_Item(this.currentWaypointIndex));
        this.targetDirection   = this.targetPoint - currentPosition;
        this.targetDirection.y = 0;
        return(this.targetDirection.NormalizeTo(1000));
    }
示例#5
0
    protected VInt3 CaculateDir(VInt3 currentPosition)
    {
        if (this.path == null || this.path.vectorPath == null || this.path.vectorPath.get_Count() == 0)
        {
            return(VInt3.zero);
        }
        List <VInt3> vectorPath = this.path.vectorPath;

        if (vectorPath.get_Count() == 1)
        {
            vectorPath.Insert(0, currentPosition);
        }
        if (this.currentWaypointIndex >= vectorPath.get_Count())
        {
            this.currentWaypointIndex = vectorPath.get_Count() - 1;
        }
        if (this.currentWaypointIndex <= 1)
        {
            this.currentWaypointIndex = 1;
        }
        while (this.currentWaypointIndex < vectorPath.get_Count() - 1)
        {
            long num = vectorPath.get_Item(this.currentWaypointIndex).XZSqrMagnitude(currentPosition);
            if (num != 0L)
            {
                if (num < (long)this.pickNextWaypointDist * (long)this.pickNextWaypointDist)
                {
                    VInt3 vInt  = vectorPath.get_Item(this.currentWaypointIndex - 1);
                    VInt3 vInt2 = vectorPath.get_Item(this.currentWaypointIndex);
                    VInt3 vInt3 = vInt2 - vInt;
                    long  num2  = (long)vInt3.get_magnitude2D();
                    long  num3  = VInt3.DotXZLong(currentPosition - vInt, vInt3.NormalizeTo(1000));
                    if (num3 >= num2 * 1000L)
                    {
                        this.lastFoundWaypointPosition = currentPosition;
                        this.lastFoundWaypointTime     = Time.time;
                        this.currentWaypointIndex++;
                        continue;
                    }
                }
IL_184:
                this.targetPoint       = this.CalculateTargetPoint(currentPosition, vectorPath.get_Item(this.currentWaypointIndex - 1), vectorPath.get_Item(this.currentWaypointIndex));
                this.targetDirection   = this.targetPoint - currentPosition;
                this.targetDirection.y = 0;
                return(this.targetDirection.NormalizeTo(1000));
            }
            this.lastFoundWaypointPosition = currentPosition;
            this.lastFoundWaypointTime     = Time.time;
            this.currentWaypointIndex++;
        }
        goto IL_184;
    }
示例#6
0
    public static VInt3 NearestPointStrictXZ(ref VInt3 lineStart, ref VInt3 lineEnd, ref VInt3 point)
    {
        VInt3 rhs = lineEnd - lineStart;
        long  max = rhs.sqrMagnitudeLong2D;

        if (max == 0)
        {
            return(lineStart);
        }
        long m = IntMath.Clamp(VInt3.DotXZLong(point - lineStart, rhs), 0L, max);

        return(IntMath.Divide(rhs, m, max) + lineStart);
    }
示例#7
0
    protected VInt3 CaculateDir(VInt3 currentPosition)
    {
        if (((this.path == null) || (this.path.vectorPath == null)) || (this.path.vectorPath.Count == 0))
        {
            return(VInt3.zero);
        }
        List <VInt3> vectorPath = this.path.vectorPath;

        if (vectorPath.Count == 1)
        {
            vectorPath.Insert(0, currentPosition);
        }
        if (this.currentWaypointIndex >= vectorPath.Count)
        {
            this.currentWaypointIndex = vectorPath.Count - 1;
        }
        if (this.currentWaypointIndex <= 1)
        {
            this.currentWaypointIndex = 1;
        }
Label_0088:
        if (this.currentWaypointIndex < (vectorPath.Count - 1))
        {
            long num = vectorPath[this.currentWaypointIndex].XZSqrMagnitude(currentPosition);
            if (num == 0)
            {
                this.lastFoundWaypointPosition = currentPosition;
                this.lastFoundWaypointTime     = Time.time;
                this.currentWaypointIndex++;
                goto Label_0088;
            }
            if (num < (this.pickNextWaypointDist * this.pickNextWaypointDist))
            {
                VInt3 num2 = vectorPath[this.currentWaypointIndex - 1];
                VInt3 num3 = vectorPath[this.currentWaypointIndex];
                VInt3 num4 = num3 - num2;
                long  num5 = num4.magnitude2D;
                if (VInt3.DotXZLong(currentPosition - num2, num4.NormalizeTo(0x3e8)) >= (num5 * 0x3e8L))
                {
                    this.lastFoundWaypointPosition = currentPosition;
                    this.lastFoundWaypointTime     = Time.time;
                    this.currentWaypointIndex++;
                    goto Label_0088;
                }
            }
        }
        this.targetPoint       = this.CalculateTargetPoint(currentPosition, vectorPath[this.currentWaypointIndex - 1], vectorPath[this.currentWaypointIndex]);
        this.targetDirection   = this.targetPoint - currentPosition;
        this.targetDirection.y = 0;
        return(this.targetDirection.NormalizeTo(0x3e8));
    }
        public static VInt3 NearestPointStrictXZ(ref VInt3 lineStart, ref VInt3 lineEnd, ref VInt3 point)
        {
            VInt3 vInt = lineEnd - lineStart;
            long  sqrMagnitudeLong2D = vInt.sqrMagnitudeLong2D;

            if (sqrMagnitudeLong2D == 0L)
            {
                return(lineStart);
            }
            long num = VInt3.DotXZLong(point - lineStart, vInt);

            num = IntMath.Clamp(num, 0L, sqrMagnitudeLong2D);
            return(IntMath.Divide(vInt, num, sqrMagnitudeLong2D) + lineStart);
        }