예제 #1
0
        public void Paint(PaintEventArgs e)
        {
            for (int i = 0; i < Spheres.Count - 1; i++)
            {
                for (int j = i + 1; j < Spheres.Count; j++)
                {
                    Sphere3d s1 = Spheres[i];
                    Sphere3d s2 = Spheres[j];
                    float?   t  = CollisionSystem.CalculateCollision(s1, s2);

                    if (t.HasValue && t.Value != 0)
                    {
                        s1.Move(t.Value, ref c1);
                        //collp.X = s1.Direction.X * t.Value + s1.Position.X;
                        //collp.Y = s1.Direction.Y * t.Value + s1.Position.Y;
                        e.Graphics.DrawCircle(Pens.Red, c1.Position.X, c1.Position.Y, s1.Radius);
                        s2.Move(t.Value, ref c2);
                        //collp.X = s2.Direction.X * t.Value + s2.Position.X;
                        //collp.Y = s2.Direction.Y * t.Value + s2.Position.Y;
                        e.Graphics.DrawCircle(Pens.Red, c2.Position.X, c2.Position.Y, s2.Radius);
                        e.Graphics.DrawLine(CollisionCirecleCentersPen, c1.Position.X, c1.Position.Y, c2.Position.X, c2.Position.Y);
                        CollisionSystem.CalculateReaction(0, c1, c2);
                        float tx = c1.Position.X + c1.Direction.X;
                        float ty = c1.Position.Y + c1.Direction.Y;
                        e.Graphics.DrawLine(Pens.Black, c1.Position.X, c1.Position.Y, tx, ty);
                    }
                }
            }
        }
예제 #2
0
 private void RecalculateCollisionMatrix()
 {
     for (int i = 0; i < Objects.Count - 1; i++)
     {
         for (int j = i + 1; j < Objects.Count; j++)
         {
             collisionMatrix[i, j] = CollisionSystem.CalculateCollision(Objects[i], Objects[j]);
         }
     }
 }
예제 #3
0
 public void RecalculateCollisions(int sphereIndex)
 {
     for (int i = 0; i < Objects.Count; i++)
     {
         if (i != sphereIndex)
         {
             int a = Math.Min(i, sphereIndex);
             int b = Math.Max(i, sphereIndex);
             collisionMatrix[a, b] = CollisionSystem.CalculateCollision(Objects[a], Objects[b]);
         }
     }
 }
예제 #4
0
        public PathfinderScene(int sphereCount, int width, int height, Random random)
        {
            Obstacles = new List <Sphere3d>();

            for (int i = 0; i < sphereCount; i++)
            {
                Obstacles.Add(RandomSphere(random, width, height, dynamic: false));
            }

            Checkpoint = RandomNonCollidingSphere(random, width, height, Obstacles, dynamic: false);
            Vehicle    = new Sphere3dVehicle(RandomNonCollidingSphere(random, width, height, Obstacles, dynamic: true));
            List <Sphere3d> allSpheres = new List <Sphere3d>();

            allSpheres.AddRange(Obstacles);
            allSpheres.Add(Checkpoint);
            allSpheres.Add(Vehicle.Sphere);
            CollisionSystem = new CollisionSystem(allSpheres, new Triangle[] { });
        }
예제 #5
0
        public Race(int numberOfSpheres)
        {
            Spheres      = new List <Sphere3d>();
            PlayerSphere = new Sphere3d(new Vector3d(), 0.2f, new Vector3d());
            Speed        = 0.1f;
            RotationY    = 45;
            Input        = new RaceInputModel();
            Random random = new Random();

            Spheres.Add(PlayerSphere);

            for (int i = 0; i < numberOfSpheres; i++)
            {
                float x = random.Next(100);
                float z = random.Next(100) - 50;
                float r = (float)random.NextDouble() * 2.0f + 0.2f;
                Spheres.Add(new Sphere3d(new Vector3d(x, 0, z), r, new Vector3d()));
            }

            Ground          = new Triangle(new Vector3d(-100, -5, -50), new Vector3d(0, -5, 50), new Vector3d(100, -5, -50));
            collisionSystem = new CollisionSystem(Spheres, new Triangle[] { Ground });
        }