private static bool IsSlopeCollisionDetection(VerletSimulator physicSimu, VisualEntity entityTesting, ref BoundingBox playerBoundingBox, ref BoundingBox playerBoundingBox2Evaluate, ref Vector3D newPosition2Evaluate, ref Vector3D previousPosition, ItemOrientation slopeOrientation, bool onSlidingSlope, out bool isSliding)
        {
            isSliding = false;

            Vector3 entityPosition = newPosition2Evaluate.AsVector3();
            float   posi           = 0.0f;

            float L = 0.0f;
            float H = entityTesting.WorldBBox.Maximum.Y - entityTesting.WorldBBox.Minimum.Y;

            switch (slopeOrientation)
            {
            case ItemOrientation.North:
                L    = entityTesting.WorldBBox.Maximum.Z - entityTesting.WorldBBox.Minimum.Z;
                posi = (entityPosition.Z + playerBoundingBox.Maximum.Z) - entityTesting.WorldBBox.Minimum.Z;
                break;

            case ItemOrientation.South:
                L    = entityTesting.WorldBBox.Maximum.Z - entityTesting.WorldBBox.Minimum.Z;
                posi = entityTesting.WorldBBox.Maximum.Z - (entityPosition.Z + playerBoundingBox.Minimum.Z);
                break;

            case ItemOrientation.East:
                L    = entityTesting.WorldBBox.Maximum.X - entityTesting.WorldBBox.Minimum.X;
                posi = entityTesting.WorldBBox.Maximum.X - (entityPosition.X + playerBoundingBox.Minimum.X);
                break;

            case ItemOrientation.West:
                L    = entityTesting.WorldBBox.Maximum.X - entityTesting.WorldBBox.Minimum.X;
                posi = (entityPosition.X + playerBoundingBox.Maximum.X) - entityTesting.WorldBBox.Minimum.X;
                break;

            default:
                break;
            }

            float posiOriginal = posi;

            posi = posi / L;
            float Y = posi * H;

            Y = Math.Min(Math.Max(Y, 0), 1);

            if (onSlidingSlope)
            {
                return(SlidingSlope(physicSimu, entityTesting, Y, ref newPosition2Evaluate, ref previousPosition, slopeOrientation, out isSliding));
            }

            //Apply only if new Y is >= Current Y
            if (entityTesting.WorldBBox.Minimum.Y + Y > newPosition2Evaluate.Y)
            {
                return(NormalSlope(physicSimu, entityTesting, Y, ref newPosition2Evaluate, ref previousPosition));
            }
            else
            {
                physicSimu.AllowJumping = true;
                return(false);
            }
        }
        private static bool SlidingSlope(VerletSimulator physicSimu, VisualEntity entityTesting, float Y, ref Vector3D newPosition2Evaluate, ref Vector3D previousPosition, ItemOrientation slopeOrientation, out bool isSliding)
        {
            isSliding = false;

            if (entityTesting.WorldBBox.Minimum.Y + Y >= newPosition2Evaluate.Y)
            {
                if (((entityTesting.WorldBBox.Minimum.Y + Y) - newPosition2Evaluate.Y) < 0.3f)
                {
                    Y = Y - (float)(newPosition2Evaluate.Y - Math.Floor(newPosition2Evaluate.Y));

                    if (Y < 0.001 || Y >= 0.999)
                    {
                        Y = 0.02f;
                    }

                    newPosition2Evaluate.Y += entityTesting.Entity.Friction;

                    isSliding = true;

                    switch (slopeOrientation)
                    {
                    case ItemOrientation.North:
                        newPosition2Evaluate.Z = newPosition2Evaluate.Z - Y;
                        if (physicSimu.IsSliding == false)
                        {
                            physicSimu.SliddingForce = new Vector3(0, 0, -1);
                        }
                        break;

                    case ItemOrientation.South:

                        newPosition2Evaluate.Z = newPosition2Evaluate.Z + Y;

                        if (physicSimu.IsSliding == false)
                        {
                            physicSimu.SliddingForce = new Vector3(0, 0, 1);
                        }

                        break;

                    case ItemOrientation.East:
                        newPosition2Evaluate.X = newPosition2Evaluate.X + Y;

                        if (physicSimu.IsSliding == false)
                        {
                            physicSimu.SliddingForce = new Vector3(1, 0, 0);
                        }

                        break;

                    case ItemOrientation.West:
                        newPosition2Evaluate.X = newPosition2Evaluate.X - Y;

                        if (physicSimu.IsSliding == false)
                        {
                            physicSimu.SliddingForce = new Vector3(-1, 0, 0);
                        }

                        break;

                    default:
                        break;
                    }

                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                physicSimu.AllowJumping = true;
                return(false);
            }
        }
        private static void SlopeCollisionDetection(VerletSimulator physicSimu, VisualEntity entityTesting, ref BoundingBox playerBoundingBox, ref BoundingBox playerBoundingBox2Evaluate, ref Vector3D newPosition2Evaluate, ref Vector3D previousPosition, ItemOrientation slopeOrientation, bool OnSlidingSlope, out bool isSliding)
        {
            if (IsSlopeCollisionDetection(physicSimu, entityTesting, ref playerBoundingBox, ref playerBoundingBox2Evaluate, ref newPosition2Evaluate, ref previousPosition, slopeOrientation, OnSlidingSlope, out isSliding))
            {
                Vector3D newPositionWithColliding = previousPosition;

                newPositionWithColliding.X = newPosition2Evaluate.X;
                playerBoundingBox2Evaluate = new BoundingBox(playerBoundingBox.Minimum + newPositionWithColliding.AsVector3(), playerBoundingBox.Maximum + newPositionWithColliding.AsVector3());
                if (entityTesting.WorldBBox.Intersects(ref playerBoundingBox2Evaluate))
                {
                    newPositionWithColliding.X = previousPosition.X;
                }

                newPositionWithColliding.Z = newPosition2Evaluate.Z;
                playerBoundingBox2Evaluate = new BoundingBox(playerBoundingBox.Minimum + newPositionWithColliding.AsVector3(), playerBoundingBox.Maximum + newPositionWithColliding.AsVector3());
                if (entityTesting.WorldBBox.Intersects(ref playerBoundingBox2Evaluate))
                {
                    newPositionWithColliding.Z = previousPosition.Z;
                }

                newPosition2Evaluate = newPositionWithColliding;
            }
        }