Ejemplo n.º 1
0
        //Get the coordinates of the specified jump arc where it lines up with one of the edges of a given rigidbody
        public Tuple <Tuple <Vector2D, Vector2D, Vector2D, Vector2D>, Tuple <Vector2D, Vector2D, Vector2D, Vector2D> > GetBoxCollisionPoints(RigidBody RB, Vector2D source, float accelerationTime, float totalJumpTime, Vector2D gravity)
        {
            if (float.IsNaN(accelerationTime))
            {
                return(null);
            }

            //force acceleration time to be positive (negative times are not valid)
            int sign = (int)(accelerationTime / (float)Math.Abs(accelerationTime));

            accelerationTime *= sign;


            //calculate the possible collision locations during acceleration
            Vector2D acceleration    = new Vector2D(GetHorizontalAcceleration() * sign, gravity.Y);
            Vector2D velocity        = new Vector2D(playerBody.LinearVelocity.X, jumpInitialVelocity);
            Vector2D initialPosition = new Vector2D(source);

            Tuple <Vector2D, Vector2D, Vector2D, Vector2D> resultsDuringAcc = UsefulMathsFunctions.GetArcPosAtBoxEdges(RB, initialPosition, velocity, acceleration, accelerationTime);


            //calculate the possible collision locations after acceleration
            float YatAccEnd = SuvatEquations.SfromUAT(velocity.Y, acceleration.Y, accelerationTime);
            float XatAccEnd = SuvatEquations.SfromUAT(velocity.X, acceleration.X, accelerationTime);

            initialPosition.Y += YatAccEnd;
            initialPosition.X += XatAccEnd;

            velocity.X = SuvatEquations.VfromUAT(velocity.X, acceleration.X, accelerationTime);
            velocity.Y = SuvatEquations.VfromUAT(velocity.Y, acceleration.Y, accelerationTime);

            acceleration.X = 0;

            Tuple <Vector2D, Vector2D, Vector2D, Vector2D> resultsAftergAcc = UsefulMathsFunctions.GetArcPosAtBoxEdges(RB, initialPosition, velocity, acceleration, totalJumpTime - accelerationTime);

            //return the two sets of coordinates
            return(new Tuple <Tuple <Vector2D, Vector2D, Vector2D, Vector2D>, Tuple <Vector2D, Vector2D, Vector2D, Vector2D> >(resultsDuringAcc, resultsAftergAcc));
        }
Ejemplo n.º 2
0
        //Get the Y coordinates of an input jump at the specified X coordinate
        public Tuple <Vector2D, Vector2D> GetJumpYFromX(Vector2D source, float accelerationTime, float totalJumpTime, Vector2D gravity, float destX)
        {
            if (float.IsNaN(accelerationTime))
            {
                return(new Tuple <Vector2D, Vector2D>(null, null));
            }

            //setup the required variables
            int sign = (int)(accelerationTime / (float)Math.Abs(accelerationTime));

            accelerationTime *= sign;

            Vector2D acceleration    = new Vector2D(GetHorizontalAcceleration() * sign, gravity.Y);
            Vector2D velocity        = new Vector2D(playerBody.LinearVelocity.X, jumpInitialVelocity);
            Vector2D initialPosition = new Vector2D(source);

            //get the XY coordinates from the curve during acceleration
            Tuple <Vector2D, Vector2D> possiblePositions1 = UsefulMathsFunctions.GetWorldspacePointAlongCurve(source, velocity, acceleration, accelerationTime, destX, float.NaN);

            //update the variables to the second half of the jump (post acceleration)
            float YatAccEnd = SuvatEquations.SfromUAT(velocity.Y, acceleration.Y, accelerationTime);
            float XatAccEnd = SuvatEquations.SfromUAT(velocity.X, acceleration.X, accelerationTime);

            initialPosition.Y += YatAccEnd;
            initialPosition.X += XatAccEnd;

            velocity.X = SuvatEquations.VfromUAT(velocity.X, acceleration.X, accelerationTime);
            velocity.Y = SuvatEquations.VfromUAT(velocity.Y, acceleration.Y, accelerationTime);

            acceleration.X = 0;

            //get the XY coordinates from the curve after acceleration
            Tuple <Vector2D, Vector2D> possiblePositions2 = UsefulMathsFunctions.GetWorldspacePointAlongCurve(initialPosition, velocity, acceleration, totalJumpTime - accelerationTime, destX, float.NaN);

            //Finally, select which results are to be returned (max of 2 valid results are assumed)
            if (possiblePositions1.Item1 != null && possiblePositions1.Item2 != null && possiblePositions1.Item1 != possiblePositions1.Item2)
            {
                return(possiblePositions1);
            }
            if (possiblePositions2.Item1 != null && possiblePositions2.Item2 != null && possiblePositions2.Item1 != possiblePositions2.Item2)
            {
                return(possiblePositions2);
            }

            if (possiblePositions1.Item1 != null && possiblePositions2.Item1 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions1.Item1, possiblePositions2.Item1));
            }
            if (possiblePositions1.Item2 != null && possiblePositions2.Item2 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions1.Item2, possiblePositions2.Item2));
            }

            if (possiblePositions1.Item1 != null && possiblePositions2.Item2 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions1.Item1, possiblePositions2.Item2));
            }
            if (possiblePositions1.Item2 != null && possiblePositions2.Item1 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions1.Item2, possiblePositions2.Item1));
            }

            if (possiblePositions1.Item1 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions1.Item1, possiblePositions1.Item1));
            }
            if (possiblePositions1.Item2 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions1.Item2, possiblePositions2.Item2));
            }

            if (possiblePositions2.Item1 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions2.Item1, possiblePositions2.Item1));
            }
            if (possiblePositions2.Item2 != null)
            {
                return(new Tuple <Vector2D, Vector2D>(possiblePositions2.Item2, possiblePositions2.Item2));
            }

            return(new Tuple <Vector2D, Vector2D>(null, null));
        }