Пример #1
0
 public override void DetectColission(VirtualEnvironment env)
 {
     // Not important for colission check
     if (_collisionRank < 20 && _collisionDecay < 5)
     {
         _collisionDecay++;
         return;
     }
     _collisionDecay = 0;
     foreach (var obj in env.Objects)
     {
         if (obj.ID != this.ID)
         {
             if (
                 obj.X + obj.Radius >= this.X - this.Radius &&
                 obj.X - obj.Radius <= this.X + this.Radius &&
                 obj.Y + obj.Radius >= this.Y - this.Radius &&
                 obj.Y - obj.Radius <= this.Y + this.Radius
                 )
             {
                 this.collisionDetectedHandler?.Invoke(this, obj);
             }
         }
     }
 }
Пример #2
0
 public override void DetectColission(VirtualEnvironment env)
 {
     foreach (var obj in env.Objects)
     {
         if (obj.ID != this.ID)
         {
             if (
                 obj.X + obj.Radius >= this.X - this.Radius &&
                 obj.X - obj.Radius <= this.X + this.Radius &&
                 obj.Y + obj.Radius >= this.Y - this.Radius &&
                 obj.Y - obj.Radius <= this.Y + this.Radius
                 )
             {
                 this.collisionDetectedHandler?.Invoke(this, obj);
             }
         }
     }
 }
Пример #3
0
        static void RunSimulation(Core.VirtualObject obj1, Core.VirtualObject obj2)
        {
            Core.VirtualEnvironment env = new Core.VirtualEnvironment();
            env.Objects.Add(obj1);
            env.Objects.Add(obj2);

            env.Start();

            for (var i = 0; i < 10; i++)
            {
                env.Update();
                Console.WriteLine(env.CollisionDetected + " / " + env.AverageTimeElapsed.ToString("#.##"));
                if (env.CollisionDetected > 0)
                {
                    break;
                }
            }
        }
 public abstract void DetectColission(VirtualEnvironment env);
 public void Update(VirtualEnvironment env)
 {
     this.X += this.VX;
     this.Y += this.VY;
 }