Example #1
0
        // for purposes of demonstration, allow cycling through various
        // types of proximity databases.  this routine is called when the
        // OpenSteerDemo user pushes a function key.
        void NextPD()
        {
            // allocate new PD
            const int TOTAL_PD = 1;

            switch (_cyclePD = (_cyclePD + 1) % TOTAL_PD)
            {
            case 0:
            {
                Vector3     center     = Vector3.Zero;
                const float DIV        = 20.0f;
                Vector3     divisions  = new Vector3(DIV, 1.0f, DIV);
                const float DIAMETER   = 80.0f;                       //XXX need better way to get this
                Vector3     dimensions = new Vector3(DIAMETER, DIAMETER, DIAMETER);
                _pd = new LocalityQueryProximityDatabase <IVehicle>(center, dimensions, divisions);
                break;
            }
            }

            // switch each boid to new PD
            foreach (Pedestrian pedestrian in _crowd)
            {
                pedestrian.NewPD(_pd);
            }
        }
Example #2
0
        public void LocateNeighbours()
        {
            var db = new LocalityQueryProximityDatabase <object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            Dictionary <object, Vector3> positionLookup = new Dictionary <object, Vector3>();

            var xyz000 = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
            var xyz100 = CreateToken(db, new Vector3(1, 0, 0), positionLookup);

            CreateToken(db, new Vector3(3, 0, 0), positionLookup);

            var list = new List <object>();

            xyz000.FindNeighbors(Vector3.Zero, 2, list);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(0, 0, 0)));
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(1, 0, 0)));

            //Check tokens handle being disposed twice
            xyz000.Dispose();
            xyz000.Dispose();

            list.Clear();
            xyz100.FindNeighbors(Vector3.Zero, 1.5f, list);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(new Vector3(1, 0, 0), positionLookup[list[0]]);
        }
        public void LocateNeighbours()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            Dictionary<object, Vector3> positionLookup = new Dictionary<object, Vector3>();

            var xyz000 = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
            var xyz100 = CreateToken(db, new Vector3(1, 0, 0), positionLookup);
            CreateToken(db, new Vector3(3, 0, 0), positionLookup);

            var list = new List<object>();
            xyz000.FindNeighbors(Vector3.Zero, 2, list);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(0, 0, 0)));
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(1, 0, 0)));

            //Check tokens handle being disposed twice
            xyz000.Dispose();
            xyz000.Dispose();

            list.Clear();
            xyz100.FindNeighbors(Vector3.Zero, 1.5f, list);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(new Vector3(1, 0, 0), positionLookup[list[0]]);
        }
		void NextPD()
		{
			// save pointer to old PD
			ProximityDatabase oldPD = pd;

			// allocate new PD
			const int totalPD = 2;
			switch (cyclePD = (cyclePD + 1) % totalPD)
			{
			case 0:
				{
					Vector3 center = Vector3.Zero;
					float div = 20.0f;
					Vector3 divisions = new Vector3(div, 1.0f, div);
					float diameter = 80.0f; //XXX need better way to get this
					Vector3 dimensions = new Vector3(diameter, diameter, diameter);
					pd = new LocalityQueryProximityDatabase<IVehicle>(center, dimensions, divisions);
					break;
				}
			case 1:
				{
					pd = new BruteForceProximityDatabase<IVehicle>();
					break;
				}
			}

			// switch each boid to new PD
			for (int i = 0; i < crowd.Count; i++) crowd[i].NewPD(pd);

			// delete old PD (if any)
			oldPD = null;
		}
Example #5
0
        // for purposes of demonstration, allow cycling through various
        // types of proximity databases.  this routine is called when the
        // Demo user pushes a function key.
        private void NextPD()
        {
            // allocate new PD
            const int TOTAL_PD = 1;

            switch (_cyclePD = (_cyclePD + 1) % TOTAL_PD)
            {
            case 0:
            {
                Vector3     center     = Vector3.Zero;
                const float DIV        = 10.0f;
                Vector3     divisions  = new Vector3(DIV, DIV, DIV);
                const float DIAMETER   = Boid.WORLD_RADIUS * 1.1f * 2;
                Vector3     dimensions = new Vector3(DIAMETER, DIAMETER, DIAMETER);
                _pd = new LocalityQueryProximityDatabase <IVehicle>(center, dimensions, divisions);
                break;
            }
            }

            // switch each boid to new PD
            foreach (Boid boid in _flock)
            {
                boid.NewPD(_pd);
            }

            // delete old PD (if any)
        }
 public SpatialDatabaseSystem(Vector2? dimensions = null, float cellSize = 1000)
 {
     Dimensions = dimensions ?? new Vector2(1e6f, 1e6f);
     CellSize = cellSize;
     Ships = new LocalityQueryProximityDatabase<Entity>(
         System.Numerics.Vector3.Zero,
         new System.Numerics.Vector3(Dimensions.X, Dimensions.Y, 1),
         new System.Numerics.Vector3(Dimensions.X / CellSize, Dimensions.Y / CellSize, 1));
 }
        private ITokenForProximityDatabase<object> CreateToken(LocalityQueryProximityDatabase<object> db, Vector3 position, Dictionary<object, Vector3> lookup)
        {
            var obj = new object();

            if (lookup != null)
                lookup.Add(obj, position);

            var token = db.AllocateToken(obj);
            token.UpdateForNewPosition(position);

            return token;
        }
        public void AllocateToken()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            var obj = new object();
            var token = db.AllocateToken(obj);
            token.UpdateForNewPosition(Vector3.Zero);

            Assert.AreEqual(1, db.Count);

            token.UpdateForNewPosition(Vector3.Zero);
        }
Example #9
0
        public void AllocateToken()
        {
            var db = new LocalityQueryProximityDatabase <object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            var obj   = new object();
            var token = db.AllocateToken(obj);

            token.UpdateForNewPosition(Vector3.Zero);

            Assert.AreEqual(1, db.Count);

            token.UpdateForNewPosition(Vector3.Zero);
        }
Example #10
0
        public void RemoveItem()
        {
            var db = new LocalityQueryProximityDatabase <object>(Vector3.Zero, new Vector3(100, 100, 100), new Vector3(1, 1, 1));

            var a = CreateToken(db, new Vector3(1, 0, 0), null);
            var b = CreateToken(db, new Vector3(2, 0, 0), null);

            Assert.AreEqual(2, db.Count);

            b.Dispose();

            Assert.AreEqual(1, db.Count);

            a.Dispose();

            Assert.AreEqual(0, db.Count);
        }
        public void LocateNeighboursOutsideSuperbrick()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(1, 1, 1), new Vector3(1, 1, 1));

            Dictionary<object, Vector3> positionLookup = new Dictionary<object, Vector3>();

            var token = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
            CreateToken(db, new Vector3(3, 0, 0), positionLookup);
            CreateToken(db, new Vector3(4, 0, 0), positionLookup);

            var list = new List<object>();
            token.FindNeighbors(Vector3.Zero, 2, list);
            Assert.AreEqual(1, list.Count);

            list.Clear();
            token.FindNeighbors(new Vector3(3, 0, 0), 0.1f, list);
            Assert.AreEqual(1, list.Count);

            list.Clear();
            token.FindNeighbors(new Vector3(3, 0, 0),1.1f, list);
            Assert.AreEqual(2, list.Count);
        }
Example #12
0
        // for purposes of demonstration, allow cycling through various
        // types of proximity databases.  this routine is called when the
        // Demo user pushes a function key.
        public void NextPD()
        {
            // save pointer to old PD
            ProximityDatabase oldPD = pd;

            // allocate new PD
            const int totalPD = 2;

            switch (cyclePD = (cyclePD + 1) % totalPD)
            {
            case 0:
            {
                Vector3     center     = Vector3.Zero;
                const float div        = 10.0f;
                Vector3     divisions  = new Vector3(div, div, div);
                float       diameter   = Boid.worldRadius * 1.1f * 2;
                Vector3     dimensions = new Vector3(diameter, diameter, diameter);
                pd = new LocalityQueryProximityDatabase <IVehicle>(center, dimensions, divisions);
                break;
            }

            case 1:
            {
                pd = new BruteForceProximityDatabase <IVehicle>();
                break;
            }
            }

            // switch each boid to new PD
            for (int i = 0; i < flock.Count; i++)
            {
                flock[i].NewPD(pd);
            }

            // delete old PD (if any)
            oldPD = null;
        }
        void NextPD()
        {
            // save pointer to old PD
            ProximityDatabase oldPD = pd;

            // allocate new PD
            const int totalPD = 2;

            switch (cyclePD = (cyclePD + 1) % totalPD)
            {
            case 0:
            {
                Vector3 center     = Vector3.Zero;
                float   div        = 20.0f;
                Vector3 divisions  = new Vector3(div, 1.0f, div);
                float   diameter   = 80.0f;                     //XXX need better way to get this
                Vector3 dimensions = new Vector3(diameter, diameter, diameter);
                pd = new LocalityQueryProximityDatabase <IVehicle>(center, dimensions, divisions);
                break;
            }

            case 1:
            {
                pd = new BruteForceProximityDatabase <IVehicle>();
                break;
            }
            }

            // switch each boid to new PD
            for (int i = 0; i < crowd.Count; i++)
            {
                crowd[i].NewPD(pd);
            }

            // delete old PD (if any)
            oldPD = null;
        }
Example #14
0
        public void LocateNeighboursOutsideSuperbrick()
        {
            var db = new LocalityQueryProximityDatabase <object>(Vector3.Zero, new Vector3(1, 1, 1), new Vector3(1, 1, 1));

            Dictionary <object, Vector3> positionLookup = new Dictionary <object, Vector3>();

            var token = CreateToken(db, new Vector3(0, 0, 0), positionLookup);

            CreateToken(db, new Vector3(3, 0, 0), positionLookup);
            CreateToken(db, new Vector3(4, 0, 0), positionLookup);

            var list = new List <object>();

            token.FindNeighbors(Vector3.Zero, 2, list);
            Assert.AreEqual(1, list.Count);

            list.Clear();
            token.FindNeighbors(new Vector3(3, 0, 0), 0.1f, list);
            Assert.AreEqual(1, list.Count);

            list.Clear();
            token.FindNeighbors(new Vector3(3, 0, 0), 1.1f, list);
            Assert.AreEqual(2, list.Count);
        }
        public void RemoveItem()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(100, 100, 100), new Vector3(1, 1, 1));

            var a = CreateToken(db, new Vector3(1, 0, 0), null);
            var b = CreateToken(db, new Vector3(2, 0, 0), null);

            Assert.AreEqual(2, db.Count);

            b.Dispose();

            Assert.AreEqual(1, db.Count);

            a.Dispose();

            Assert.AreEqual(0, db.Count);
        }
Example #16
0
        public void Construct()
        {
            var db = new LocalityQueryProximityDatabase <object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            Assert.AreEqual(0, db.Count);
        }
        public void Construct()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            Assert.AreEqual(0, db.Count);
        }
Example #18
0
		// for purposes of demonstration, allow cycling through various
		// types of proximity databases.  this routine is called when the
		// OpenSteerDemo user pushes a function key.
		void NextPD()
		{
		    // allocate new PD
			const int TOTAL_PD = 1;
			switch (_cyclePD = (_cyclePD + 1) % TOTAL_PD)
			{
			case 0:
				{
					Vector3 center = Vector3.Zero;
					const float DIV = 20.0f;
					Vector3 divisions = new Vector3(DIV, 1.0f, DIV);
					const float DIAMETER = 80.0f; //XXX need better way to get this
					Vector3 dimensions = new Vector3(DIAMETER, DIAMETER, DIAMETER);
					_pd = new LocalityQueryProximityDatabase<IVehicle>(center, dimensions, divisions);
					break;
				}
			}

			// switch each boid to new PD
			foreach (Pedestrian pedestrian in _crowd)
			    pedestrian.NewPD(_pd);
		}
Example #19
0
 public FlowFieldPlugIn(IAnnotationService annotations) : base(annotations)
 {
     PredictionTime = 1;
     Database       = new LocalityQueryProximityDatabase <IVehicle>(Vector3.Zero, new Vector3(250, 250, 250), new Vector3(10));
 }
Example #20
0
		// for purposes of demonstration, allow cycling through various
		// types of proximity databases.  this routine is called when the
		// Demo user pushes a function key.
	    private void NextPD()
		{
	        // allocate new PD
			const int TOTAL_PD = 1;
			switch (_cyclePD = (_cyclePD + 1) % TOTAL_PD)
			{
			case 0:
				{
					Vector3 center = Vector3.Zero;
					const float DIV = 10.0f;
					Vector3 divisions = new Vector3(DIV, DIV, DIV);
					const float DIAMETER = Boid.WORLD_RADIUS * 1.1f * 2;
					Vector3 dimensions = new Vector3(DIAMETER, DIAMETER, DIAMETER);
					_pd = new LocalityQueryProximityDatabase<IVehicle>(center, dimensions, divisions);
					break;
				}
			}

			// switch each boid to new PD
			foreach (Boid boid in _flock)
			    boid.NewPD(_pd);

	        // delete old PD (if any)
		}
Example #21
0
 public FlowFieldPlugIn(IAnnotationService annotations) : base(annotations)
 {
     PredictionTime = 1;
     Database = new LocalityQueryProximityDatabase<IVehicle>(Vector3.Zero, new Vector3(250, 250, 250), new Vector3(10));
 }