本文整理汇总了C#中QuadTree类的典型用法代码示例。如果您正苦于以下问题:C# QuadTree类的具体用法?C# QuadTree怎么用?C# QuadTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QuadTree类属于命名空间,在下文中一共展示了QuadTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GameplayScreen
public GameplayScreen(Game1 game, Vector2 worldSize, Levels currentLevel)
: base(game)
{
this.worldSize = worldSize;
eCurrentLevel = currentLevel;
heatmapWriteTimer = 0;
//Make the tree a bit wider for outer walls.
quadTree = new QuadTree(new Rectangle(
-10, -10, (int)worldSize.X + 20, (int)worldSize.Y + 20));
//Add the 4 walls on the outside of the world.
Components.Add(new Wall(GDGame, new Vector2(-10, -10), new Vector2(worldSize.X + 10, 0)));
Components.Add(new Wall(GDGame, new Vector2(worldSize.X, -10), new Vector2(worldSize.X + 10, worldSize.Y)));
Components.Add(new Wall(GDGame, new Vector2(0, worldSize.Y), new Vector2(worldSize.X + 10, worldSize.Y + 10)));
Components.Add(new Wall(GDGame, new Vector2(-10, 0), new Vector2(0, worldSize.Y + 10)));
//Add the player to world.
Components.Add(Player = new PlayerBall(GDGame, new Vector2(300, 300)));
//Give the camera the new world size.
GDGame.Camera.WorldSize = worldSize + new Vector2(0, 100);
gameOver = won = false;
GDGame.IsMouseVisible = false;
}
示例2: Map
public Map()
{
_Random = Regulus.Utility.Random.Instance;
_EntranceSet = new List<Visible>();
this._Set = new Dictionary<Guid, Visible>();
this._QuadTree = new QuadTree<Visible>(new Size(2, 2), 100);
}
示例3: QuadTreeTestOne
public void QuadTreeTestOne()
{
GridVector2[] points = new GridVector2[] { new GridVector2(0,0),
new GridVector2(1,1),
new GridVector2(-10,-10),
new GridVector2(-7.5, 2.5),
new GridVector2(8.5, -1.5),
new GridVector2(3.5, -6.5),
new GridVector2(1.5, -8.5),
new GridVector2(10, 10)};
int[] values = new int[] {0,1,2,3,4,5,6,7};
GridRectangle border = GridVector2.Border(points);
QuadTree<int> tree = new QuadTree<int>(points, values, border);
//Start with a basic test ensuring we can find all the existing points
for(int i = 0; i < points.Length; i++)
{
double distance;
int RetValue;
RetValue = tree.FindNearest(points[i], out distance);
Debug.Assert(RetValue == i);
Debug.Assert(distance == 0);
}
//Check to see if we can find nearby points
GridVector2[] nearpoints = new GridVector2[] { new GridVector2(.25,.25),
new GridVector2(.5,.51),
new GridVector2(-7.5,-7.5),
new GridVector2(-7.5, -1.5),
new GridVector2(8.5, -5.5),
new GridVector2(4.5, -7.75),
new GridVector2(1, -8.75),
new GridVector2(11, 11)}; //Out of original boundaries
for (int i = 0; i < nearpoints.Length; i++)
{
double distance;
int RetValue;
RetValue = tree.FindNearest(nearpoints[i], out distance);
Debug.Assert(RetValue == i);
Debug.Assert(distance == GridVector2.Distance(points[i], nearpoints[i]));
}
//Check to see if we can return all points in a rectangle
GridRectangle gridRect = new GridRectangle(0,15, 0,15);
List<GridVector2> intersectPoints;
List<int> intersectValues;
tree.Intersect(gridRect, out intersectPoints, out intersectValues);
Debug.Assert(intersectValues.Contains(0));
Debug.Assert(intersectValues.Contains(1));
Debug.Assert(intersectValues.Contains(7));
Debug.Assert(false == intersectValues.Contains(2));
Debug.Assert(false == intersectValues.Contains(3));
Debug.Assert(false == intersectValues.Contains(4));
Debug.Assert(false == intersectValues.Contains(5));
Debug.Assert(false == intersectValues.Contains(6));
}
示例4: getObjectsColliding
private void getObjectsColliding(Rectangle bounds, QuadTree<Object.Object>.QuadNode currentNode, List<Object.Object> result, List<SearchFlags.Searchflag> _SearchFlags)
{
if (Utility.Collision.Intersection.RectangleIsInRectangle(bounds, currentNode.Bounds))
{
//Circle fits in node, so search in subnodes
Boolean circleFitsInSubnode = false;
foreach (QuadTree<Object.Object>.QuadNode node in currentNode.Nodes)
{
if (node != null)
{
if (Utility.Collision.Intersection.RectangleIsInRectangle(bounds, node.Bounds))
{
circleFitsInSubnode = true;
getObjectsInRange(bounds, node, result, _SearchFlags);
}
}
}
//Aggrocircle fit into a subnode? then
if (!circleFitsInSubnode)
{
addAllObjectsInRange(currentNode, bounds, result, _SearchFlags);
}
return;
}
if (currentNode.Equals(this.quadTreeObject.Root))
{
addAllObjectsInRange(currentNode, bounds, result, _SearchFlags);
}
}
示例5: QuadTreeBroadPhase
/// <summary>
/// Creates a new quad tree broadphase with the specified span.
/// </summary>
/// <param name="span">the maximum span of the tree (world size)</param>
public QuadTreeBroadPhase(AABB span)
{
_quadTree = new QuadTree<FixtureProxy>(span, 5, 10);
_idRegister = new Dictionary<int, Element<FixtureProxy>>();
_moveBuffer = new List<Element<FixtureProxy>>();
_pairBuffer = new List<Pair>();
}
示例6: Search_AreaWithOnePoint_ReturnsOnePoint
public void Search_AreaWithOnePoint_ReturnsOnePoint()
{
var center = new Point(0, 0);
var boundary = new Boundary(center, 1, 1);
var quad = new QuadTree<Point>(boundary);
// insert one point in the second quadrant
var point = new Point(-0.75, +0.75);
quad.Insert(point);
// then insert one point in each remaining quadrant
var points = new List<Point>
{
new Point(+0.75, +0.75), // first quadrant
new Point(-0.75, -0.75), // third quadrant
new Point(+0.75, -0.75) // fourth quadrant
};
points.ForEach(p => quad.Insert(p));
// search second quadrant
var searchArea = new Boundary(new Point(-0.5, 0.5), 0.5, 0.5);
var results = quad.Search(searchArea);
Assert.IsTrue(results.Count == 1);
Assert.IsTrue(results.Contains(point));
}
示例7: GameWorld
public GameWorld(int width, int height)
{
Width = width;
Height = height;
TileMap = new TileMap(Width, Height);
_gameObjects = new List<GameObject>();
_quadTree = new QuadTree<GameObject>(new Rectangle(0,0, Width * 64, Height * 64));
_quadTree.MaxGeneration = 4;
_addNewObjectsQueue = new Queue<GameObject>();
_deleteObjectsQueue = new Queue<GameObject>();
Camera = new Camera(Game.g_screenSize, new Point(Game.g_screenSize.Width / 2, Game.g_screenSize.Height / 2), true);
Camera.ScaleTo(1f);
Camera.MoveSpeed = 7;
background = new ParallaxBackground(this);
BloodSystem = new BloodSystem(this);
BloodSystem.Init();
BloodSystem.BlendWith(back);
mback = new MagicBackground();
UpdateObjectsEnqueues();
}
示例8: CollisionDetector
/// <summary>
/// Default ctor
/// </summary>
public CollisionDetector()
{
// TODO: evaluate these numbers
// sample usage says
// "Use larger min size, and higher min object values for better performance"
m_tree = new QuadTree<Collider>(new DoubleSize(25, 25), 0, false);
}
示例9: createSpatialIndex
public void createSpatialIndex()
{
this._spatialIndex = new QuadTree<OGRBufferCacheRow>(this._envelope);
foreach (OGRBufferCacheRow row in this._rows)
{
this._spatialIndex.add(row);
}
}
示例10: GameObjectsManager
public GameObjectsManager(Camera camera)
{
_camera = camera;
_gameObjects = new List<GameObject>(150);
_addNewObjectsQueue = new Queue<GameObject>(150);
_deleteObjectsQueue = new Queue<GameObject>(150);
QuadTree = new QuadTree<ColliderComponent>(new Rectangle(0, 0, 1024, 1024));
}
示例11: Map
private Map()
{
const int numTiles = TerrainConstants.TilesPerMapSide * TerrainConstants.TilesPerMapSide;
_tiles = new Dictionary<TileIdentifier, Tile>(numTiles);
const float baseLength = TerrainConstants.MapLength / 2.0f;
var basePosition = new Point(baseLength, baseLength);
QuadTree = new QuadTree<Tile>(basePosition, TerrainConstants.TilesPerMapSide, TerrainConstants.TileSize);
}
示例12: EntityManager
public EntityManager()
{
float gridSize = 262144.0f / 2;
quadTree = new QuadTree(new Vector2(-gridSize / 2, -gridSize / 2), gridSize, null, QuadType.Parent);
Random r = Game1.Instance.Random;
Time = 1.0f;
selectRect = new Rectangle(400, 400, 400, 400);
results = new List<GraphicalEntity>();
}
示例13: Build
public static TriangulationQuadTree Build(IReadOnlyList<DelaunayTriangle> triangulation)
{
var quadTree = new QuadTree<DelaunayTriangle, Vec2>(
GetBoundingRectangle(triangulation.SelectMany(x => x.Points)),
GetRectangle,
Convert,
Test);
return new TriangulationQuadTree(quadTree);
}
示例14: Insert_WithinBoundary_ReturnsTrue
public void Insert_WithinBoundary_ReturnsTrue()
{
var center = new Point(0, 0);
var boundary = new Boundary(center, 1, 1);
var quad = new QuadTree<Point>(boundary);
Assert.IsTrue(quad.Insert(new Point(0, 0)));
Assert.IsTrue(quad.Insert(new Point(-0.5, 0.5)));
}
示例15: Insert_OutOfBoundary_ReturnsFalse
public void Insert_OutOfBoundary_ReturnsFalse()
{
var center = new Point(0, 0);
var boundary = new Boundary(center, 1, 1);
var quad = new QuadTree<Point>(boundary);
Assert.IsFalse(quad.Insert(new Point(2, 0)));
Assert.IsFalse(quad.Insert(new Point(0, 2)));
}