Esempio n. 1
0
        static void DrawPathFencesOnMap(TerrainMap map, IPathway path)
        {
            float   xs       = map.XSize / map.Resolution;
            float   zs       = map.ZSize / map.Resolution;
            Vector3 alongRow = new Vector3(xs, 0, 0);
            Vector3 nextRow  = new Vector3(-map.XSize, 0, zs);
            Vector3 g        = new Vector3((map.XSize - xs) / -2, 0, (map.ZSize - zs) / -2);

            for (int j = 0; j < map.Resolution; j++)
            {
                for (int i = 0; i < map.Resolution; i++)
                {
                    float       outside        = path.HowFarOutsidePath(g);
                    const float WALL_THICKNESS = 1.0f;

                    // set map cells adjacent to the outside edge of the path
                    if ((outside > 0) && (outside < WALL_THICKNESS))
                    {
                        map.SetMapBit(i, j, true);
                    }

                    // clear all other off-path map cells
                    if (outside > WALL_THICKNESS)
                    {
                        map.SetMapBit(i, j, false);
                    }

                    g += alongRow;
                }
                g += nextRow;
            }
        }
Esempio n. 2
0
        public void Update(float dt)
        {
            const float PREDICTION = 3;

            //Avoid other vehicles, and follow the path
            var avoid = SteerToAvoidCloseNeighbors(0.25f, _vehicles.Except(new[] { this }));

            if (avoid != Vector3.Zero)
            {
                ApplySteeringForce(avoid, dt);
            }
            else
            {
                var f = SteerToFollowPath(true, PREDICTION, Path);
                ApplySteeringForce(f, dt);
            }

            //If the vehicle leaves the path, penalise it by applying a braking force
            if (Path.HowFarOutsidePath(Position) > 0)
            {
                ApplyBrakingForce(0.3f, dt);
            }

            _time += dt;
            _trail.Record(_time, Position);

            annotation.VelocityAcceleration(this);
        }
Esempio n. 3
0
        static void DrawPathFencesOnMap(TerrainMap map, IPathway path)
		{
			float xs = map.XSize / map.Resolution;
			float zs = map.ZSize / map.Resolution;
			Vector3 alongRow = new Vector3(xs, 0, 0);
			Vector3 nextRow = new Vector3(-map.XSize, 0, zs);
			Vector3 g = new Vector3((map.XSize - xs) / -2, 0, (map.ZSize - zs) / -2);
			for (int j = 0; j < map.Resolution; j++)
			{
				for (int i = 0; i < map.Resolution; i++)
				{
					float outside = path.HowFarOutsidePath(g);
					const float WALL_THICKNESS = 1.0f;

					// set map cells adjacent to the outside edge of the path
					if ((outside > 0) && (outside < WALL_THICKNESS))
						map.SetMapBit(i, j, true);

					// clear all other off-path map cells 
					if (outside > WALL_THICKNESS) map.SetMapBit(i, j, false);

					g += alongRow;
				}
				g += nextRow;
			}
		}