Example #1
0
    public static VInt3 Transform(VInt3 point, VInt3 forward, VInt3 trans, VInt3 scale)
    {
        VInt3 up   = VInt3.up;
        VInt3 vInt = VInt3.Cross(VInt3.up, forward);

        return(IntMath.Transform(ref point, ref vInt, ref up, ref forward, ref trans, ref scale));
    }
Example #2
0
    public static VInt3 Transform(VInt3 point, VInt3 forward, VInt3 trans, VInt3 scale)
    {
        VInt3 up   = VInt3.up;
        VInt3 num2 = VInt3.Cross(VInt3.up, forward);

        return(Transform(ref point, ref num2, ref up, ref forward, ref trans, ref scale));
    }
Example #3
0
        static int rayTriSpecial(VInt3 orig, VInt3 dir, VInt3 vert0, VInt3 edge1, VInt3 edge2, ref VFixedPoint t, ref VFixedPoint u, ref VFixedPoint v)
        {
            VInt3       pvec = VInt3.Cross(dir, edge2);
            VFixedPoint det  = VInt3.Dot(edge1, pvec);

            //triangle lies in plane of triangle
            if (det > -Globals.EPS && det < Globals.EPS)
            {
                return(0);
            }

            VFixedPoint oneOverDet = VFixedPoint.One / det;

            VInt3 tvec = orig - vert0;

            u = VInt3.Dot(tvec, pvec) * oneOverDet;

            VInt3 qvec = VInt3.Cross(tvec, edge1);

            v = VInt3.Dot(dir, qvec) * oneOverDet;

            if (u < VFixedPoint.Zero || u > VFixedPoint.One)
            {
                return(1);
            }
            if (v < VFixedPoint.Zero || u + v > VFixedPoint.One)
            {
                return(1);
            }

            t = VInt3.Dot(edge2, qvec) * oneOverDet;
            return(2);
        }
    // Token: 0x06000FDF RID: 4063 RVA: 0x0005706C File Offset: 0x0005526C
    public static VInt3 Transform(ref VInt3 point, ref VInt3 forward, ref VInt3 trans)
    {
        VInt3 up   = VInt3.up;
        VInt3 vint = VInt3.Cross(VInt3.up, forward);

        return(IntMath.Transform(ref point, ref vint, ref up, ref forward, ref trans));
    }
Example #5
0
        public bool isValid2(int i0, int i1, int i2, VInt3[] aBuf, VInt3[] bBuf, VFixedPoint lower, VFixedPoint upper)
        {
            VInt3 pa0 = aBuf[i0];
            VInt3 pa1 = aBuf[i1];
            VInt3 pa2 = aBuf[i2];

            VInt3 pb0 = bBuf[i0];
            VInt3 pb1 = bBuf[i1];
            VInt3 pb2 = bBuf[i2];

            VInt3 p0 = pa0 - pb0;
            VInt3 p1 = pa1 - pb1;
            VInt3 p2 = pa2 - pb2;

            VInt3 v1 = p1 - p0;
            VInt3 v2 = p2 - p0;

            VInt3 denormalizedNormal = VInt3.Cross(v1, v2);

            VInt3       planeNormal = denormalizedNormal.Normalize();
            VFixedPoint planeDist   = VInt3.Dot(planeNormal, p0);

            m_planeNormal = planeNormal;
            m_planeDist   = planeDist;

            return(planeDist >= lower && upper >= planeDist);
        }
Example #6
0
            public static VIntQuaternion FromToRotation(VInt3 from, VInt3 to)
            {
                VInt3       axis  = VInt3.Cross(from, to);
                VFixedPoint angle = FMath.Trig.acos(VInt3.Dot(from, to));

                return(AngleAxis(angle, axis));
            }
Example #7
0
        static bool expandSegment(CollisionShape a, CollisionShape b, VIntTransform transformA, VIntTransform transformB, ref int numVerts, VFixedPoint lowerBound, VFixedPoint upperBound)
        {
            VInt3 q0   = aBuf[0] - bBuf[0];
            VInt3 q1   = aBuf[1] - bBuf[1];
            VInt3 v    = q1 - q0;
            VInt3 absV = v.Abs();

            VFixedPoint x = absV.x, y = absV.y, z = absV.z;

            VInt3 axis = VInt3.right;

            if (x > y && z > y)
            {
                axis = VInt3.up;
            }
            else if (x > z)
            {
                axis = VInt3.forward;
            }

            VInt3 n = VInt3.Cross(axis, v).Normalize();
            VInt3 q2;

            doSupport(a, b, transformA, transformB, n, out aBuf[2], out bBuf[2], out q2);

            return(expandTriangle(a, b, transformA, transformB, ref numVerts, lowerBound, upperBound));
        }
Example #8
0
        // 0 p is inside abcd, 1 p is outside abcd
        public static int pointOutsideOfPlane(VInt3 p, VInt3 a, VInt3 b, VInt3 c, VInt3 d)
        {
            VInt3       normal = VInt3.Cross(b - a, c - a);
            VFixedPoint signp  = VInt3.Dot(p - a, normal); // [AP AB AC]
            VFixedPoint signd  = VInt3.Dot(d - a, normal); // [AD AB AC]
            VFixedPoint dp     = signd * signd;

            return((signp * signd > Globals.EPS)? 1 : 0);
        }
Example #9
0
            public static VIntQuaternion operator *(VIntQuaternion lhs, VIntQuaternion rhs)
            {
                VInt3       lvirtual    = new VInt3(lhs.x, lhs.y, lhs.z);
                VFixedPoint lreal       = lhs.w;
                VInt3       rvirtual    = new VInt3(rhs.x, rhs.y, rhs.z);
                VFixedPoint rreal       = rhs.w;
                VInt3       virtualPart = VInt3.Cross(lvirtual, rvirtual) + rvirtual * lreal + lvirtual * rreal;
                VFixedPoint realPart    = lreal * rreal - VInt3.Dot(lvirtual, rvirtual);

                return(new VIntQuaternion(virtualPart.x, virtualPart.y, virtualPart.z, realPart));
            }
Example #10
0
        /** Unwraps the funnel portals from 3D space to 2D space.
         * The result is stored in the \a left and \a right arrays which must be at least as large as the funnel.left and funnel.right lists.
         *
         * The input is a funnel like in the image below. It may be rotated and twisted.
         * \shadowimage{funnel_unwrap_input.png}
         * The output will be a funnel in 2D space like in the image below. All twists and bends will have been straightened out.
         * \shadowimage{funnel_unwrap_output.png}
         *
         * \see #Calculate(FunnelPortals,bool,bool)
         */
        //Good Game
        //public static void Unwrap (FunnelPortals funnel, Vector2[] left, Vector2[] right) {
        public static void Unwrap(FunnelPortals funnel, VInt2[] left, VInt2[] right)
        {
            int startingIndex = 1;
            //Good Game
            //var normal = Vector3.Cross(funnel.right[1] - funnel.left[0], funnel.left[1] - funnel.left[0]);
            var normal = VInt3.Cross(funnel.right[1] - funnel.left[0], funnel.left[1] - funnel.left[0]);

            // This handles the case when the starting point is colinear with the first portal.
            // Note that left.Length is only guaranteed to be at least as large as funnel.left.Count, it may be larger.
            //Good Game
            //while (normal.sqrMagnitude <= 0.00000001f && startingIndex + 1 < funnel.left.Count) {
            while (normal.sqrMagnitude <= 0.000001 && startingIndex + 1 < funnel.left.Count)
            {
                startingIndex++;
                //Good Game
                //normal = Vector3.Cross(funnel.right[startingIndex] - funnel.left[0], funnel.left[startingIndex] - funnel.left[0]);
                normal = VInt3.Cross(funnel.right[startingIndex] - funnel.left[0], funnel.left[startingIndex] - funnel.left[0]);
            }

            left[0] = right[0] = VInt2.zero;

            var portalLeft  = funnel.left[1];
            var portalRight = funnel.right[1];
            var prevPoint   = funnel.left[0];

            // The code below is equivalent to this matrix (but a lot faster)
            // This represents a rotation around a line in 3D space
            // Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, Quaternion.FromToRotation(normal, Vector3.forward), Vector3.one) * Matrix4x4.TRS(-funnel.right[0], Quaternion.identity, Vector3.one);
            Quaternion mRot    = Quaternion.FromToRotation((Vector3)normal, Vector3.forward);
            Vector3    mOffset = mRot * (-(Vector3)funnel.right[0]);

            for (int i = 1; i < funnel.left.Count; i++)
            {
                //Good Game
                //if (UnwrapHelper((Vector3)portalLeft, (Vector3)portalRight, (Vector3)prevPoint, (Vector3)funnel.left[i], ref mRot, ref mOffset)) {
                if (UnwrapHelper((Vector3)portalLeft, (Vector3)portalRight, (Vector3)prevPoint, (Vector3)funnel.left[i], ref mRot, ref mOffset))
                {
                    prevPoint  = portalLeft;
                    portalLeft = funnel.left[i];
                }

                left[i] = VInt2.FromInt3XZ((VInt3)(mRot * (Vector3)funnel.left[i] + mOffset));

                //Good Game
                //if (UnwrapHelper(portalLeft, portalRight, prevPoint, funnel.right[i], ref mRot, ref mOffset)) {
                if (UnwrapHelper((Vector3)portalLeft, (Vector3)portalRight, (Vector3)prevPoint, (Vector3)funnel.right[i], ref mRot, ref mOffset))
                {
                    prevPoint   = portalRight;
                    portalRight = funnel.right[i];
                }

                right[i] = VInt2.FromInt3XZ((VInt3)(mRot * (Vector3)funnel.right[i] + mOffset));
            }
        }
 public override void UpdateShape(VInt3 location, VInt3 forward)
 {
     this.axis[2]        = forward;
     this.axis[0]        = VInt3.Cross(ref this.axis[1], ref this.axis[2]);
     this.worldPos       = IntMath.Transform(ref this.localPos, ref this.axis[0], ref this.axis[1], ref this.axis[2], ref location);
     this.worldExtends.x = this.size.x >> 1;
     this.worldExtends.y = this.size.y >> 1;
     this.worldExtends.z = this.size.z >> 1;
     this.worldRadius    = Mathf.Max(this.worldExtends.x, Mathf.Max(this.worldExtends.y, this.worldExtends.z));
     this.dirty          = false;
 }
Example #12
0
 public static void UpdatePosition(ref VInt3 worldPos, ref VInt3 localPos, ref VInt3 location, ref VInt3 forward)
 {
     if (localPos.x == 0 && localPos.z == 0)
     {
         worldPos.x = localPos.x + location.x;
         worldPos.y = localPos.y + location.y;
         worldPos.z = localPos.z + location.z;
     }
     else
     {
         VInt3 up    = VInt3.up;
         VInt3 vInt  = forward;
         VInt3 vInt2 = VInt3.Cross(ref up, ref vInt);
         VInt3 vInt3 = location;
         worldPos = IntMath.Transform(ref localPos, ref vInt2, ref up, ref vInt, ref vInt3);
     }
 }
Example #13
0
 public override void UpdateShape(VInt3 location, VInt3 forward)
 {
     if ((this.localPos.x == 0) && (this.localPos.z == 0))
     {
         this.worldPos.x = this.localPos.x + location.x;
         this.worldPos.y = this.localPos.y + location.y;
         this.worldPos.z = this.localPos.z + location.z;
     }
     else
     {
         VInt3 up    = VInt3.up;
         VInt3 rhs   = forward;
         VInt3 num3  = VInt3.Cross(ref up, ref rhs);
         VInt3 trans = location;
         this.worldPos = IntMath.Transform(ref this.localPos, ref num3, ref up, ref rhs, ref trans);
     }
     this.worldRadius = this.localRadius;
     base.dirty       = false;
 }
Example #14
0
        static VFixedPoint calculatePlaneDist(int i0, int i1, int i2, VInt3[] aBuf, VInt3[] bBuf)
        {
            VInt3 pa0 = aBuf[i0];
            VInt3 pa1 = aBuf[i1];
            VInt3 pa2 = aBuf[i2];

            VInt3 pb0 = bBuf[i0];
            VInt3 pb1 = bBuf[i1];
            VInt3 pb2 = bBuf[i2];

            VInt3 p0 = pa0 - pb0;
            VInt3 p1 = pa1 - pb1;
            VInt3 p2 = pa2 - pb2;
            VInt3 v1 = p1 - p0;
            VInt3 v2 = p2 - p0;

            VInt3 planeNormal = VInt3.Cross(v1, v2).Normalize();

            return(VInt3.Dot(planeNormal, p0));
        }
Example #15
0
        //Good Game
        //public override bool GetPortal (GraphNode other, List<Vector3> left, List<Vector3> right, bool backwards) {
        public override bool GetPortal(GraphNode other, List <VInt3> left, List <VInt3> right, bool backwards)
        {
            if (backwards)
            {
                return(true);
            }

            GridGraph gg = GetGridGraph(GraphIndex);

            int[]      neighbourOffsets = gg.neighbourOffsets;
            GridNode[] nodes            = gg.nodes;

            for (int i = 0; i < 4; i++)
            {
                if (HasConnectionInDirection(i) && other == nodes[NodeInGridIndex + neighbourOffsets[i]])
                {
                    //Good Game

                    /*Vector3 middle = ((Vector3)(position + other.position))*0.5f;
                     *                  Vector3 cross = Vector3.Cross(gg.collision.up, (Vector3)(other.position-position));*/
                    VInt3 middle = ((position + other.position)) / 2;
                    VInt3 cross  = VInt3.Cross((VInt3)gg.collision.up, (other.position - position));
                    cross.Normalize();
                    cross *= gg.nodeSize * 0.5f;
                    left.Add(middle - cross);
                    right.Add(middle + cross);
                    return(true);
                }
            }

            for (int i = 4; i < 8; i++)
            {
                if (HasConnectionInDirection(i) && other == nodes[NodeInGridIndex + neighbourOffsets[i]])
                {
                    bool rClear = false;
                    bool lClear = false;
                    if (HasConnectionInDirection(i - 4))
                    {
                        GridNode n2 = nodes[NodeInGridIndex + neighbourOffsets[i - 4]];
                        if (n2.Walkable && n2.HasConnectionInDirection((i - 4 + 1) % 4))
                        {
                            rClear = true;
                        }
                    }

                    if (HasConnectionInDirection((i - 4 + 1) % 4))
                    {
                        GridNode n2 = nodes[NodeInGridIndex + neighbourOffsets[(i - 4 + 1) % 4]];
                        if (n2.Walkable && n2.HasConnectionInDirection(i - 4))
                        {
                            lClear = true;
                        }
                    }

                    //Good Game

                    /*Vector3 middle = ((Vector3)(position + other.position))*0.5f;
                     *                  Vector3 cross = Vector3.Cross(gg.collision.up, (Vector3)(other.position-position));*/
                    VInt3 middle = ((position + other.position)) / 2;
                    VInt3 cross  = VInt3.Cross((VInt3)gg.collision.up, (other.position - position));
                    cross.Normalize();
                    cross *= gg.nodeSize * 1.4142f;

                    /*left.Add(middle - (lClear ? cross : Vector3.zero));
                     *                  right.Add(middle + (rClear ? cross : Vector3.zero));*/
                    left.Add(middle - (lClear ? cross : VInt3.zero));
                    right.Add(middle + (rClear ? cross : VInt3.zero));
                    return(true);
                }
            }

            return(false);
        }
 public void Enter(Action _action)
 {
     this.skillContext = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext");
     this.lastTime     = 0;
     this.lastVelocity = (this.lastLerpVelocity = this.velocity);
     this.stopCondtion = false;
     this.moveActor    = _action.GetActorHandle(this.targetId);
     if (!this.moveActor)
     {
         return;
     }
     this.gravityControler = new AccelerateMotionControler();
     this.xControler       = new xAxisAccelerateMotionControler();
     this.moveActor.handle.ObjLinker.AddCustomMoveLerp(new CustomMoveLerpFunc(this.ActionMoveLerp));
     if (this.MoveType == ActorMoveType.Target)
     {
         if (this.bFindTargetByRotateBodyBullet)
         {
             _action.refParams.GetRefParam("FindEnemyActor", ref this.tarActor);
         }
         else
         {
             this.tarActor = _action.GetActorHandle(this.destId);
         }
         if (!this.tarActor)
         {
             return;
         }
         this.destPosition = this.tarActor.handle.location;
         CActorInfo charInfo = this.tarActor.handle.CharInfo;
         if (charInfo != null)
         {
             this.hitHeight = charInfo.iBulletHeight;
             VInt3 a = this.moveActor.handle.location - this.destPosition;
             a.y = 0;
             a   = a.NormalizeTo(1000);
             this.destPosition += IntMath.Divide(a, (long)charInfo.iCollisionSize.x, 1000L);
         }
         this.destPosition.y = this.destPosition.y + this.hitHeight;
     }
     else if (this.MoveType == ActorMoveType.Directional)
     {
         VInt3 vInt = VInt3.one;
         if (this.skillContext == null)
         {
             return;
         }
         PoolObjHandle <ActorRoot> originator = this.skillContext.Originator;
         if (!originator)
         {
             return;
         }
         if (this.bBulletUseDir)
         {
             _action.refParams.GetRefParam("_BulletUseDir", ref vInt);
         }
         else if (this.bUseIndicatorDir)
         {
             SkillUseContext refParamObject = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext");
             VInt3           vInt2;
             if (refParamObject != null && refParamObject.CalcAttackerDir(out vInt2, originator))
             {
                 vInt = vInt2;
             }
             else
             {
                 vInt = originator.handle.forward;
             }
         }
         else
         {
             vInt = originator.handle.forward;
         }
         this.moveActor.handle.forward  = vInt;
         this.moveActor.handle.rotation = Quaternion.LookRotation((Vector3)vInt);
         vInt = vInt.RotateY(this.offsetDir.y);
         if (this.bResetMoveDistance)
         {
             int num = 0;
             _action.refParams.GetRefParam("_BulletRealFlyingTime", ref num);
             int num2 = num * this.velocity / 1000;
             this.distance = ((num2 > 0) ? num2 : this.distance);
         }
         this.destPosition   = this.moveActor.handle.location + vInt.NormalizeTo(this.distance);
         this.destPosition.y = this.moveActor.handle.location.y;
     }
     else if (this.MoveType == ActorMoveType.Position)
     {
         if (this.bReachDestStop)
         {
             this.destPosition = this.targetPosition;
         }
         else
         {
             VInt3 lhs = this.targetPosition - this.moveActor.handle.location;
             lhs.y             = 0;
             lhs               = lhs.NormalizeTo(1000);
             this.destPosition = this.moveActor.handle.location + lhs * (this.length * this.velocity / 1000);
             VInt vInt3;
             if (PathfindingUtility.GetGroundY(this.destPosition, out vInt3))
             {
                 this.destPosition.y = vInt3.i;
             }
         }
     }
     else if (this.MoveType == ActorMoveType.RotateBody)
     {
         this.originateActor = this.skillContext.Originator;
         if (!this.originateActor)
         {
             DebugHelper.Assert(false, "产生子弹的originateActor不能为空!!!");
             return;
         }
         this.rotateBodyBulletCount       = Mathf.Clamp(this.rotateBodyBulletCount, 1, 360);
         this.rotateBodyCurDirDegreeAngle = 360 / this.rotateBodyBulletCount * this.skillContext.BulletPos.x;
         VInt3 vInt4 = this.moveActor.handle.forward.RotateY(-this.rotateBodyCurDirDegreeAngle);
         this.moveActor.handle.forward  = vInt4;
         this.moveActor.handle.rotation = Quaternion.LookRotation((Vector3)vInt4);
     }
     if (this.bAdjustSpeed)
     {
         VInt3 vInt5 = this.destPosition - this.moveActor.handle.location;
         int   num3  = this.length - 100;
         num3          = ((num3 <= 0) ? this.length : num3);
         this.velocity = (int)IntMath.Divide((long)vInt5.magnitude2D * 1000L, (long)num3);
     }
     if (this.gravity < 0)
     {
         if (this.velocity == 0)
         {
             this.stopCondtion = true;
             return;
         }
         VInt3 vInt6 = this.destPosition - this.moveActor.handle.location;
         int   num4;
         if (!this.shouldUseAcceleration)
         {
             num4 = (int)IntMath.Divide((long)vInt6.magnitude2D * 1000L, (long)this.velocity);
         }
         else
         {
             long num5 = (long)this.velocity;
             long num6 = (long)this.acceleration;
             long num7 = (long)vInt6.magnitude2D;
             long a2   = num5 * num5 + 2L * num6 * num7;
             num4 = (int)IntMath.Divide(((long)IntMath.Sqrt(a2) - num5) * 1000L, num6);
             this.lastVelocity = (this.lastLerpVelocity = this.velocity);
         }
         if (num4 == 0)
         {
             this.stopCondtion = true;
             return;
         }
         VInt vInt7;
         if (PathfindingUtility.GetGroundY(this.destPosition, out vInt7))
         {
             this.gravityControler.InitMotionControler(num4, vInt7.i - this.moveActor.handle.location.y, this.gravity);
         }
         else
         {
             this.gravityControler.InitMotionControler(num4, 0, this.gravity);
         }
     }
     if (this.bMoveOnXAxis)
     {
         this.zDirection   = this.destPosition - this.moveActor.handle.location;
         this.xDirection   = VInt3.Cross(VInt3.up, this.zDirection);
         this.zCurPosition = this.moveActor.handle.location;
         if (this.bReachDestStop)
         {
             int[]   array  = new int[3];
             VInt3[] array2 = new VInt3[]
             {
                 default(VInt3),
                 default(VInt3),
                 this.destPosition - this.moveActor.handle.location
             };
             array2[0] = array2[2];
             array2[1] = array2[2];
             array2[0].NormalizeTo(this.distanceZ0);
             array2[1].NormalizeTo(this.distanceZ1);
             for (int i = 0; i < array.Length; i++)
             {
                 if (!this.shouldUseAcceleration)
                 {
                     array[i] = (int)IntMath.Divide((long)array2[i].magnitude2D * 1000L, (long)this.velocity);
                 }
                 else
                 {
                     long num8  = (long)this.velocity;
                     long num9  = (long)this.acceleration;
                     long num10 = (long)array2[i].magnitude2D;
                     long a3    = num8 * num8 + 2L * num9 * num10;
                     array[i] = (int)IntMath.Divide(((long)IntMath.Sqrt(a3) - num8) * 1000L, num9);
                 }
             }
             if (array[2] > array[1] && array[1] > array[0] && array[0] > 0)
             {
                 this.xControler.InitMotionControler(array[0], array[1], array[2], this.distanceZ0, this.distanceZ1, this.distanceX);
                 int desPostion = this.xControler.getDesPostion();
                 this.xDestPosition = this.xDirection;
                 this.xDestPosition.NormalizeTo(Math.Abs(desPostion));
                 if (desPostion < 0)
                 {
                     this.xDestPosition = -this.xDestPosition;
                 }
             }
             else
             {
                 this.bMoveOnXAxis = false;
             }
         }
     }
 }
Example #17
0
        public static bool sweepCapsuleCapsule(CapsuleShape lss0, VIntTransform transform0, VInt3 toPos, CapsuleShape lss1, VIntTransform transform1, ref VFixedPoint dist, ref VInt3 hitNormal)
        {
            VInt3       FromPos   = transform0.position;
            VFixedPoint radiusSun = lss0.getRadius() + lss1.getRadius();
            VFixedPoint length    = (toPos - FromPos).magnitude;
            VInt3       dir       = (toPos - FromPos) / length;

            VInt3 lss0p0 = transform0.TransformPoint(lss0.getUpAxis() * lss0.getHalfHeight()), lss0p1 = transform0.TransformPoint(lss0.getUpAxis() * -lss0.getHalfHeight());
            VInt3 lss1p0 = transform1.TransformPoint(lss1.getUpAxis() * lss1.getHalfHeight()), lss1p1 = transform1.TransformPoint(lss1.getUpAxis() * -lss1.getHalfHeight());

            bool        initialOverlapStatus = false;
            VFixedPoint tmp = VFixedPoint.Zero;

            if (lss0.getHalfHeight() < Globals.EPS)
            {
                initialOverlapStatus = Distance.distancePointSegmentSquared(lss1p0, lss1p1, lss0p0, ref tmp) < radiusSun * radiusSun;
            }
            else if (lss1.getHalfHeight() < Globals.EPS)
            {
                initialOverlapStatus = Distance.distancePointSegmentSquared(lss0p0, lss0p1, lss1p0, ref tmp) < radiusSun * radiusSun;
            }
            else
            {
                VInt3 x, y;
                initialOverlapStatus = Distance.SegmentSegmentDist2(lss0p0, lss0p1 - lss0p0, lss1p0, lss1p1 - lss1p0, out x, out y) < radiusSun * radiusSun;
            }

            if (initialOverlapStatus)
            {
                dist      = VFixedPoint.Zero;
                hitNormal = (FromPos - toPos).Normalize();
                return(true);
            }

            // 1. Extrude lss0 by lss1's length
            // 2. Inflate extruded shape by lss1's radius
            // 3. Raycast against resulting quad
            VInt3 D = (lss0p1 - lss0p0) * VFixedPoint.Half;
            VInt3 p0 = lss1p0 - D, p1 = lss1p1 - D, p0b = lss1p0 + D, p1b = lss1p1 + D;
            VInt3 normal = VInt3.Cross(p1b - p0b, p1 - p0b); normal = normal.Normalize();

            dist = VFixedPoint.One; bool status = false;

            VInt3 pa, pb, pc;

            if (VInt3.Dot(normal, dir) >= VFixedPoint.Zero)
            {
                pc = p0 - normal * radiusSun;
                pa = p1 - normal * radiusSun;
                pb = p1b - normal * radiusSun;
            }
            else
            {
                pc = p0 + normal * radiusSun;
                pa = p1 + normal * radiusSun;
                pb = p1b + normal * radiusSun;
            }
            VFixedPoint t = VFixedPoint.Zero, u = VFixedPoint.Zero, v = VFixedPoint.Zero;

            if (rayQuad(transform1.position, dir, pa, pb, pc, ref t, ref u, ref v, true) && t >= VFixedPoint.Zero && t < length)
            {
                dist   = t / length;
                status = true;
            }

            if (!status)
            {
                VInt3[] caps = new VInt3[]
                {
                    p0, p1, p1, p1b, p1b, p0b, p0b, p0
                };
                VInt3 tmpNormal = VInt3.zero;
                for (int i = 0; i < 4; i++)
                {
                    VFixedPoint s = VFixedPoint.Zero;
                    if (CapsuleRaytestAlgorithm.raycastCapsule(FromPos, toPos, caps[i * 2], caps[i * 2 + 1], radiusSun, ref tmpNormal, ref s))
                    {
                        if (s > VFixedPoint.Zero && s < dist)
                        {
                            dist   = s;
                            status = true;
                        }
                    }
                }
            }

            if (status)
            {
                VInt3 x, y;
                Distance.SegmentSegmentDist2(lss0p0 + dir * length * dist, lss0p1 - lss0p0, lss1p0, lss1p1 - lss1p0, out x, out y);
                hitNormal = (x - y).Normalize();
            }
            return(status);
        }
Example #18
0
        public static bool rayQuad(VInt3 orig, VInt3 dir, VInt3 vert0, VInt3 vert1, VInt3 vert2, ref VFixedPoint t, ref VFixedPoint u, ref VFixedPoint v, bool cull)
        {
            VInt3       edge1 = vert1 - vert0;
            VInt3       edge2 = vert2 - vert0;
            VInt3       pvec  = VInt3.Cross(dir, edge2);
            VFixedPoint det   = VInt3.Dot(edge1, pvec);

            if (cull)
            {
                if (det < Globals.EPS)
                {
                    return(false);
                }

                VInt3 tvec = orig - vert0;
                u = VInt3.Dot(tvec, pvec);
                if (u < VFixedPoint.Zero || u > det)
                {
                    return(false);
                }

                VInt3 qvec = VInt3.Cross(tvec, edge1);

                v = VInt3.Dot(dir, qvec);
                if (v < VFixedPoint.Zero || v > det)
                {
                    return(false);
                }

                t = VInt3.Dot(edge2, qvec);
                VFixedPoint oneOverDet = VFixedPoint.One / det;
                t *= oneOverDet;
                u *= oneOverDet;
                v *= oneOverDet;
            }
            else
            {
                if (det > -Globals.EPS && det < Globals.EPS)
                {
                    return(false);
                }

                VFixedPoint oneOverDet = VFixedPoint.One / det;
                VInt3       tvec       = orig - vert0;

                u = VInt3.Dot(tvec, pvec) * oneOverDet;
                if (u < VFixedPoint.Zero || u > VFixedPoint.One)
                {
                    return(false);
                }

                VInt3 qvec = VInt3.Cross(tvec, edge1);
                v = VInt3.Dot(dir, qvec) * oneOverDet;
                if (v < VFixedPoint.Zero || v > VFixedPoint.One)
                {
                    return(false);
                }

                t = (VInt3.Dot(edge2, qvec)) * oneOverDet;
            }
            return(true);
        }
Example #19
0
        //Good Game
        //public List<Vector3> SmoothOffsetSimple (List<Vector3> path) {
        public List <VInt3> SmoothOffsetSimple(List <VInt3> path)
        {
            if (path.Count <= 2 || iterations <= 0)
            {
                return(path);
            }

            if (iterations > 12)
            {
                Debug.LogWarning("A very high iteration count was passed, won't let this one through");
                return(path);
            }

            int maxLength = (path.Count - 2) * (int)Mathf.Pow(2, iterations) + 2;

            //Good Game

            /*List<Vector3> subdivided = ListPool<Vector3>.Claim(maxLength);
             *          List<Vector3> subdivided2 = ListPool<Vector3>.Claim(maxLength);
             *
             *          for (int i = 0; i < maxLength; i++) { subdivided.Add(Vector3.zero); subdivided2.Add(Vector3.zero); }*/
            List <VInt3> subdivided = ListPool <VInt3> .Claim(maxLength);

            List <VInt3> subdivided2 = ListPool <VInt3> .Claim(maxLength);

            for (int i = 0; i < maxLength; i++)
            {
                subdivided.Add(VInt3.zero); subdivided2.Add(VInt3.zero);
            }

            for (int i = 0; i < path.Count; i++)
            {
                subdivided[i] = path[i];
            }

            for (int iteration = 0; iteration < iterations; iteration++)
            {
                int currentPathLength = (path.Count - 2) * (int)Mathf.Pow(2, iteration) + 2;

                //Switch the arrays
                //Good Game
                //List<Vector3> tmp = subdivided;
                List <VInt3> tmp = subdivided;
                subdivided  = subdivided2;
                subdivided2 = tmp;

                const float nextMultiplier = 1F;

                for (int i = 0; i < currentPathLength - 1; i++)
                {
                    //Good Game

                    /*Vector3 current = subdivided2[i];
                     *                  Vector3 next = subdivided2[i+1];
                     *
                     *                  Vector3 normal = Vector3.Cross(next-current, Vector3.up);*/
                    VInt3 current = subdivided2[i];
                    VInt3 next    = subdivided2[i + 1];

                    VInt3 normal = VInt3.Cross(next - current, VInt3.up);

                    //Good Game
                    //normal = normal.normalized;
                    normal = (VInt3)((Vector3)normal).normalized;

                    bool firstRight  = false;
                    bool secondRight = false;
                    bool setFirst    = false;
                    bool setSecond   = false;
                    if (i != 0 && !VectorMath.IsColinearXZ(current, next, subdivided2[i - 1]))
                    {
                        setFirst   = true;
                        firstRight = VectorMath.RightOrColinearXZ(current, next, subdivided2[i - 1]);
                    }
                    if (i < currentPathLength - 1 && !VectorMath.IsColinearXZ(current, next, subdivided2[i + 2]))
                    {
                        setSecond   = true;
                        secondRight = VectorMath.RightOrColinearXZ(current, next, subdivided2[i + 2]);
                    }

                    if (setFirst)
                    {
                        subdivided[i * 2] = current + (firstRight ? normal * offset * nextMultiplier : -normal * offset * nextMultiplier);
                    }
                    else
                    {
                        subdivided[i * 2] = current;
                    }

                    if (setSecond)
                    {
                        subdivided[i * 2 + 1] = next + (secondRight ? normal * offset * nextMultiplier : -normal * offset * nextMultiplier);
                    }
                    else
                    {
                        subdivided[i * 2 + 1] = next;
                    }
                }

                subdivided[(path.Count - 2) * (int)Mathf.Pow(2, iteration + 1) + 2 - 1] = subdivided2[currentPathLength - 1];
            }

            //Good Game
            //ListPool<Vector3>.Release(ref subdivided2);
            ListPool <VInt3> .Release(ref subdivided2);

            return(subdivided);
        }