// credit where credit is due on this one, most of it was borrowed from the tutorial on gamedev.net with a few modifications. #include #include #include using std::cout; using std::cin; float *fVerts; unsigned int *uiList; #define LEAF_TYPE 0 #define NODE_TYPE 1 typedef struct vertex{ float x,y,z; }VERTEX; typedef struct node{ int bType; VERTEX vBoundingCoordinates[4]; unsigned int uiBranches[4]; unsigned int uiVertexStrip1[8]; unsigned int uiVertexStrip2[8]; unsigned int uiVertexStrip3[8]; unsigned int uiVertexStrip4[8]; unsigned int uiID; unsigned int uiParentID; }NODE; NODE *pNodeList; /* uiBoundingCoordinates[0] uiBoundingCoordinates[1] *---------------------------|--------------------------* *---------------------------|--------------------------* uiBoundingCoordinates[2] uiBoundingCoordinates[3] */ void CreateNode(unsigned int Bounding[4],unsigned int ParentID,unsigned int NodeID) { static unsigned int TotalTreeID = 0; unsigned int uiNodeType; float uiWidth,uiHeight; uiWidth = fVerts[(Bounding[1]*3)] - fVerts[(Bounding[0]*3)]; uiHeight = fVerts[(Bounding[2]*3)+2] - fVerts[(Bounding[0]*3)+2]; if(0.5*uiWidth==2) {uiNodeType = LEAF_TYPE;} else {uiNodeType = NODE_TYPE;} NODE *pNode = &pNodeList[NodeID]; // pointer to parrent is pNodeList's address malloc'd memfor quadtree pNode->uiID = NodeID; pNode->uiParentID = ParentID; //parrent NODE uiBounding coords for (int i=0; i < 4; i++){ pNode->vBoundingCoordinates[i].x = fVerts[(Bounding[i]*3)]; pNode->vBoundingCoordinates[i].y = fVerts[(Bounding[i]*3)+1]; pNode->vBoundingCoordinates[i].z = fVerts[(Bounding[i]*3)+2]; } pNode->bType = uiNodeType; if(uiNodeType == LEAF_TYPE){} // if its the parrent node do nothing else { unsigned int BoundingBox[4]; // maybe move this again later.-- for (unsigned int i=0;i < 4;i++) { TotalTreeID++; pNode->uiBranches[i] = TotalTreeID; BoundingBox[0] = Bounding[0]; //Top-Left i.e. b[0] BoundingBox[1] = Bounding[0]+((Bounding[1]-Bounding[0])/2); //Between b[0] and b[1] BoundingBox[2] = Bounding[0]+((Bounding[2]-Bounding[0])/2); //[between b[0] and b[2] BoundingBox[3] = Bounding[0]+((Bounding[2]-Bounding[0])/2)+((Bounding[1]-Bounding[0])/2); //middle of node CreateNode(BoundingBox,NodeID,TotalTreeID); } } } void ReportNode(NODE *pNode,int TotalNodes) { int child; cout<<"Root Node ID: "<>GridWidth; // GridWidth=8; cout<<"\nEnter Grid Height: "; // GridHeight=8; cin>>GridHeight; CreateGrid(GridWidth+1,GridHeight+1); unsigned int Temp =(GridWidth/4)*(GridWidth/4); // devided into 4 sections ?? unsigned int Temp2 = CalcNodeNum(Temp,4); // max , min cout<