Ejemplo n.º 1
0
        private void renderDetectionBox(MovingEntity objVehicle, Graphics objGraphics, Pen objPen)
        {
            List<Vector2D> points = new List<Vector2D>();

            points.Add(new Vector2D(0, objVehicle.BRadius));
            points.Add(new Vector2D(objVehicle.Steering().DBoxLength(), objVehicle.BRadius));
            points.Add(new Vector2D(objVehicle.Steering().DBoxLength(), -objVehicle.BRadius));
            points.Add(new Vector2D(0, -objVehicle.BRadius));

            if (UseSmoothing)
            {
                points = Utils.WorldTransform(points, objVehicle.Pos, objVehicle.SmoothedHeading(), objVehicle.SmoothedHeading().Perp());
            }
            else
            {
                points = Utils.WorldTransform(points, objVehicle.Pos, objVehicle.Heading(), objVehicle.Side());                
            }

            objGraphics.DrawLine(objPen, (PointF)points[0], (PointF)points[1]);
            objGraphics.DrawLine(objPen, (PointF)points[1], (PointF)points[2]);
            objGraphics.DrawLine(objPen, (PointF)points[2], (PointF)points[3]);
        }
Ejemplo n.º 2
0
        public SteeringScenario(int cx, int cy)
        {
            m_cxClient = cx;
            m_cyClient = cy;

            m_Vehicles.Clear();
            m_Obstacles.Clear();
            m_Walls.Clear();

            GameWorld.Instance.cxClient = m_cxClient;
            GameWorld.Instance.cyClient = m_cyClient;

            GameWorld.Instance.Wrap = true;
            GameWorld.Instance.SpacePartitioningOn = true;

            objVehiclePen = new Pen(Color.Black);
            objDarkPen = new Pen(Color.SeaGreen, 2);
            objWallPen = new Pen(Color.DarkOrange);
            objObstaclePen = new Pen(Color.Orange);
            objTargetPen = new Pen(Color.Blue, 1);
            objRedPen = new Pen(Color.Red, 2);
            objCellPen = new Pen(Color.LightSkyBlue, 1);
            objGrayPen = new Pen(Color.LightSlateGray, 2);
            objPathPen = new Pen(Color.Blue, 2);

            objPathPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            objPathPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

            m_pCellSpace = new CellSpacePartition(m_cxClient, m_cyClient, SteerParams.Instance.NumCellsX, SteerParams.Instance.NumCellsY, SteerParams.Instance.NumAgents);

            CreateObstacles();
            CreateWalls();            
            CreateRandomPath();            

            //setup the agents
            for (int a = 0; a < SteerParams.Instance.NumAgents; ++a)
            {
                //determine a random starting position
                Vector2D SpawnPos = new Vector2D(cx / 2.0 + Utils.RandomClamped() * cx / 2.0, cy / 2.0 + Utils.RandomClamped() * cy / 2.0);

                double rotation = Utils.RandFloat() * Utils.TwoPi;

                MovingEntity pVehicle = new MovingEntity(SpawnPos,  //initial position
                                  SteerParams.Instance.VehicleScale,
                                  new Vector2D(0, 0),
                                  SteerParams.Instance.MaxSpeed,
                                  new Vector2D(Math.Sin(rotation), -Math.Cos(rotation)),
                                  SteerParams.Instance.VehicleMass,
                                  new Vector2D(SteerParams.Instance.VehicleScale, SteerParams.Instance.VehicleScale),
                                  SteerParams.Instance.MaxTurnRatePerSecond,
                                  SteerParams.Instance.AppliedMaxSteeringForce());

                pVehicle.Steering().FlockingOn();
                pVehicle.Steering().WallAvoidanceOn();
                pVehicle.Steering().ObstacleAvoidanceOn();

                m_Vehicles.Add(pVehicle);

                //add it to the cell subdivision
                m_pCellSpace.AddEntity(pVehicle);
            }

            // Turn the last one into a shark!
            int sharkie = SteerParams.Instance.NumAgents - 1;

            m_Vehicles[sharkie].Steering().FlockingOff();
            m_Vehicles[sharkie].SetScale(new Vector2D(6, 6));            
            m_Vehicles[sharkie].MaxSpeed = 80;

            m_intSharkieID = m_Vehicles[sharkie].ID();

            setNextPursuitTarget();

            for (int a = 0; a < SteerParams.Instance.NumAgents - 1; ++a)
            {
                m_Vehicles[a].Steering().EvadeOn(m_Vehicles[sharkie]);
            }

            GameWorld.Instance.Agents = m_Vehicles;    
            GameWorld.Instance.Walls = m_Walls;
            GameWorld.Instance.Obstacles = m_Obstacles;
            GameWorld.Instance.CellSpaces = m_pCellSpace;
        }