Exemplo n.º 1
0
        public void CalculateCollision(PhysicalObject po1, PhysicalObject po2)
        {
            m1 = po1.Mass;
            m2 = po2.Mass;

            v1 = po1.Speed;
            v2 = po2.Speed;

            alpha = po1.Angle; //in deg
            beta  = po2.Angle; //in deg

            //Console.WriteLine("\nAlpha: " + alpha);
            //Console.WriteLine("Beta: " + beta);

            inclineAngle = GetInclineAngle(po1.CenterX, po2.CenterX, po1.CenterY, po2.CenterY);
            //Console.WriteLine("Incline: " + inclineAngle);

            ShiftAngles();
            //Console.WriteLine("Alpha after shift: " + alpha);
            //Console.WriteLine("Beta after shift: " + beta);

            po1.SetAxisSpeeds(alpha, v1);
            po2.SetAxisSpeeds(beta, v2);

            //Console.WriteLine("InitSpeed1: " + v1);
            //Console.WriteLine("InitSpeed2: " + v2);

            //Momentum must be calculated after angle shift
            CalculateMomentum();
            //Console.WriteLine("Momentum: " + momentum);

            CalculateEnergy();
            //Console.WriteLine("Energy: " + energy);

            CalculateU2();
            //Console.WriteLine("u2: " + u2);

            FindU1();
            //Console.WriteLine("u1: " + u1);

            //find new speeds and calculate new angles
            newSpeed1 = CalculateNewSpeed(u1, alpha, v1);
            //Console.WriteLine("New Speed 1: " + newSpeed1);

            newSpeed2 = CalculateNewSpeed(u2, beta, v2);
            //Console.WriteLine("New Speed 2: " + newSpeed2);

            newAlpha = CalculateNewAngle(newSpeed1, u1, po1.SpeedY);
            //Console.WriteLine("New Alpha: " + newAlpha);

            newBeta = CalculateNewAngle(newSpeed2, u2, po2.SpeedY);
            //Console.WriteLine("New Beta: " + newBeta);

            RestoreAngles();
            //Console.WriteLine("New Alpha after restore: " + newAlpha);
            //Console.WriteLine("New Beta after restore: " + newBeta);

            po1.SetAxisSpeeds(newAlpha, Math.Abs(newSpeed1)); //spped should be positive
            po2.SetAxisSpeeds(newBeta, Math.Abs(newSpeed2));  //speed should be positive
        }
Exemplo n.º 2
0
 public void ApplyGravityOn(PhysicalObject po)
 {
     for (int i = 0; i < list.Count; ++i)
     {
         //Console.WriteLine("grav force " + CalculateGravitationalForce(po, list[i]));
         //Console.WriteLine("grav force angle " + CalculateForceAngle(po, list[i]));
         AddToVector(CalculateGravitationalForce(po, list[i]) / po.Mass, CalculateForceAngle(po, list[i]));
     }
     //Console.WriteLine("force size  " + vector.Item1);
     //Console.WriteLine("force angle " + vector.Item2);
     AddToVector(po.Speed, po.Angle);
     po.SetAxisSpeeds(vector.Item2, vector.Item1);
     //Console.WriteLine("New Speed " + vector.Item1);
     //Console.WriteLine("New Angle " + vector.Item2);
     vector = new Tuple <float, float>(0, 0);//nullify vector
 }
Exemplo n.º 3
0
 private void BounceOffVerticalWall(PhysicalObject po)
 {
     po.SetAxisSpeeds((540 - po.Angle) % 360, po.Speed);
 }
Exemplo n.º 4
0
 private void BounceOffHorizontalWall(PhysicalObject po)
 {
     po.SetAxisSpeeds(360 - po.Angle, po.Speed);
 }