Пример #1
0
 protected Point Translation(int frames = 1)
 {
     return((Velocity * frames + Accleration * AdvMath.Factorial(frames)) / Scene.ScaledFPS);
 }
Пример #2
0
        //runs after collisions have been detected
        private void CollideWith(Collider c, Direction side)
        {
            Direction oppositeSide = AdvMath.OppositeDirection(side);

            GameObject.PreCollision(c, side);
            c.GameObject.PreCollision(this, oppositeSide);

            if (c == Ignore)
            {
                return;
            }

            Rect one = GetBounds();
            Rect two = c.GetBounds();

            //if one of the colliders is a trigger
            if (IsTrigger || c.IsTrigger)
            {
                if (IsTrigger)
                {
                    GameObject.OnTrigger(c.GameObject, side);                           //activate collison for this
                }
                if (c.IsTrigger)
                {
                    c.GameObject.OnTrigger(GameObject, oppositeSide);                             //activate collison for other object, but opposite side
                }
            }
            else
            {            //both are normal
                         //use momentum and physics to determine what happens when they both collide:

                //HOWEVER, if one of them Is Kinematic, or has no PhysicsBody, there is no physics collision
                if (c.IsKinematic())
                {
                    FixWith(c, one, two);

                    GameObject.OnCollision(c.GameObject, side);                    //activate collison for this
                    c.GameObject.OnCollision(GameObject, oppositeSide);            //activate collison for other object

                    //ok, done with collisions now
                    return;
                }

                //get the average elasticity to use for the collisions
                double averageElasticity = (body.Elasticity + c.body.Elasticity) / 2;

                //get the system velocity
                Point systemVelocity = (body.Momentum + c.body.Momentum) / (body.Mass + c.body.Mass);

                //get the new velocities based on that, and the average elasticity
                //only do the calculations for the side that the collision is on
                if (side == Direction.Down || side == Direction.Up)
                {                // Y axis
                    body.Velocity   = new Point(body.Velocity.X, (2 * systemVelocity.Y) - (averageElasticity * body.Velocity.Y));
                    c.body.Velocity = new Point(c.body.Velocity.X, (2 * systemVelocity.Y) - (averageElasticity * c.body.Velocity.Y));
                }
                else
                {                //X axis
                    body.Velocity   = new Point((2 * systemVelocity.X) - (averageElasticity * body.Velocity.X), body.Velocity.Y);
                    c.body.Velocity = new Point((2 * systemVelocity.X) - (averageElasticity * c.body.Velocity.X), c.body.Velocity.Y);
                }

                GameObject.OnCollision(c.GameObject, side);                //activate collison for this
                c.GameObject.OnCollision(GameObject, oppositeSide);        //activate collison for other object
            }
        }
Пример #3
0
 /// <summary>
 /// Finds the angle from one Point to another Point.
 /// </summary>
 /// <param name="one">The Point that the angle is measured from.</param>
 /// <param name="two">The Point that the angle is measured to.</param>
 /// <returns>The angle from Point one to Point two, in radians.</returns>
 public static double Angle(Point one, Point two)
 {
     return(Math.Acos(AdvMath.DegreesToRadians(DotProduct(one, two) / (one.Magnitude() * two.Magnitude()))));
 }
Пример #4
0
 /// <summary>
 /// Rounds the Point to the nearest amount of Digits.
 /// </summary>
 /// <param name="digits">The degree the number will be rounded to.</param>
 /// <returns>A new Point with rounded values.</returns>
 public Point Round(int digits = 0)
 {
     return(new Point(AdvMath.Round(X, digits), AdvMath.Round(Y, digits)));
 }
Пример #5
0
 //gets the closest Point on the paremeter to a Point
 public Point Closest(Point point)
 {
     return(new Point(AdvMath.Clamp(point.X, Left, Right), AdvMath.Clamp(point.Y, Bottom, Top)));
 }