Esempio n. 1
0
        public void DrawQuery()
        {
            if (shape == null)
            {
                return;
            }

            ConvexRect rect = shape as ConvexRect;

            Gizmos.color = Color.yellow;

            Vector2[] allCorners = rect.AllCorners;
            //LT->RT
            Gizmos.DrawLine(new Vector3(allCorners[0].x, allCorners[0].y, 0),
                            new Vector3(allCorners[1].x, allCorners[1].y, 0));

            //RT->RB
            Gizmos.DrawLine(new Vector3(allCorners[1].x, allCorners[1].y, 0),
                            new Vector3(allCorners[2].x, allCorners[2].y, 0));

            //RB->LB
            Gizmos.DrawLine(new Vector3(allCorners[2].x, allCorners[2].y, 0),
                            new Vector3(allCorners[3].x, allCorners[3].y, 0));

            //LB->LT
            Gizmos.DrawLine(new Vector3(allCorners[3].x, allCorners[3].y, 0),
                            new Vector3(allCorners[0].x, allCorners[0].y, 0));
        }
Esempio n. 2
0
		/**
		 * Set boundary of this node
		 **/
		void SetBoundary(ConvexRect nodeBoundary){

			if (nodeBoundary == ConvexRect.zero)
				return;

			boundary = nodeBoundary;
		}
Esempio n. 3
0
		/**
		 * Create a root element
		 * 
		 * Given rect of boundary must have topleft corner as origin
		 **/
		public static QuadtreeNode createRootQuadtree(ConvexRect nodeBoundry){

			QuadtreeNode rootQuadtree = new QuadtreeNode (null);

			rootQuadtree.SetBoundary (nodeBoundry);

			return rootQuadtree;
		}
Esempio n. 4
0
		/**
		 * Draw Quadtree boundary
		 **/
		public void DebugDraw(float z, bool child = true){

			z = z + depthIndex;

			if (child) {
				//Draw child node
				if (nodes != null) {

					foreach (QuadtreeNode n in nodes) {

						n.DebugDraw (z, child);
					}
				}
			}


			//boundary for drawing
			float offset = 0.0f;
			ConvexRect dBoundary = boundary;
			Vector2 topLeftCorner = boundary.AllCorners[0];
			if (parentNode != null) {

				topLeftCorner.x += offset;
				topLeftCorner.y += offset;
				dBoundary.Width -= offset*2;
				dBoundary.Height -= offset*2;
			}

			//Gizmos.color = debugDrawColor;
			Gizmos.color = debugDrawColor;
			//Handles.zTest = UnityEngine.Rendering.CompareFunction.Less;

			//LT->RT
			Gizmos.DrawLine (new Vector3 (topLeftCorner.x, topLeftCorner.y, z),
				new Vector3 (topLeftCorner.x + dBoundary.Width, topLeftCorner.y, z));

			//RT->RB
			Gizmos.DrawLine (new Vector3 (topLeftCorner.x + dBoundary.Width, topLeftCorner.y, z),
				new Vector3 (topLeftCorner.x + dBoundary.Width, topLeftCorner.y - dBoundary.Height, z));

			//RB->LB
			Gizmos.DrawLine (new Vector3 (topLeftCorner.x + dBoundary.Width, topLeftCorner.y - dBoundary.Height, z),
				new Vector3 (topLeftCorner.x, topLeftCorner.y - dBoundary.Height, z));

			//LB->LT
			Gizmos.DrawLine (new Vector3 (topLeftCorner.x, topLeftCorner.y - dBoundary.Height, z),
				new Vector3 (topLeftCorner.x, topLeftCorner.y, z));


		}
Esempio n. 5
0
        void Awake()
        {
            quadtreeSize = new Vector2(Camera.main.orthographicSize - 1.0f, Camera.main.orthographicSize - 1.0f);


            boundary = new ConvexRect(new Vector2(transform.position.x, transform.position.y),
                                      new Vector2(quadtreeSize.x, quadtreeSize.y)
                                      );

            QuadtreeNode.elementCapacity = capacity;
            quadtree = QuadtreeNode.createRootQuadtree(boundary);

            if (objToAdd > 0)
            {
                StartCoroutine(AutoAddObject());
            }
        }
Esempio n. 6
0
		/**
		 * Split quadtree node into 4
		 **/
		private void Split(){

			/*
			#if DEBUG
			Debug.Log("Split quadtree");
			#endif
			*/
			#if DEBUG
			if(nodes != null){
				Debug.LogWarning("Child node already exist before split");
				return;
			}
			#endif

			ConvexRect newBoundary;
			float width = boundary.Width / 2.0f;
			float height = boundary.Height / 2.0f;
			Vector2 topLeftCorner = boundary.AllCorners[0];

			nodes = new QuadtreeNode[4];

			//TopLeft(NorthWest)
			newBoundary = new ConvexRect(topLeftCorner.x, topLeftCorner.y, width, height);
			nodes[0] = new QuadtreeNode (this,newBoundary);


			//TopRight(NorthEast)
			newBoundary = new ConvexRect(topLeftCorner.x+width, topLeftCorner.y, width, height);
			nodes[1] = new QuadtreeNode (this, newBoundary);


			//BottomRight(SouthEast)
			newBoundary = new ConvexRect(topLeftCorner.x+width, topLeftCorner.y - height, width, height);
			nodes[2] = new QuadtreeNode (this, newBoundary);


			//BottomLeft(SouthWest)
			newBoundary = new ConvexRect(topLeftCorner.x, topLeftCorner.y - height, width, height);
			nodes[3] = new QuadtreeNode (this, newBoundary);
		}
Esempio n. 7
0
 public QtRectangleQuery(Vector2 center, Vector2 size)
 {
     shape = new ConvexRect(center, size);
 }
Esempio n. 8
0
		QuadtreeNode(QuadtreeNode parent, float x, float y , float width, float height){

			InitNode (parent);
			ConvexRect nodeBoundary = new ConvexRect (x, y, width, height);
			SetBoundary (nodeBoundary);
		}
Esempio n. 9
0
		QuadtreeNode(QuadtreeNode parent, ConvexRect nodeBoundary){

			InitNode (parent);
			SetBoundary (nodeBoundary);
		}
Esempio n. 10
0
 // Use this for initialization
 void Start()
 {
     rect = new ConvexRect(center, new Vector2(width, height));
     //rect = new ConvexRect(x,y,width,height);
 }
Esempio n. 11
0
 // Use this for initialization
 void Start()
 {
     rect1 = new ConvexRect(center1, rect1Size);
     rect2 = new ConvexRect(center2, rect2Size);
 }
Esempio n. 12
0
 // Use this for initialization
 void Start()
 {
     rect1  = new ConvexRect(rectCenter, rectSize);
     circle = new ConvexCircle(circlePosition, cRadius);
 }