int main(int argc, char* argv[]) { NWindow Window(&Width,&Height,"Quadtrees!",false,argc,argv); //Create and size window (with opengl bindings) NText::SetScreen(Width, Height); //Make sure our text render-er knows how large the window is NText::Text MyText("Quadtrees!","textures/boot",16,0,0,1,1,1,1); //Create a text object glClearColor(0.2,0.1,0.2,1); //Set clear color to some sweet purple color NQuadTree::Node* MyNode = NQuadTree::NewNode(0,0,Width,Height,NULL); //Create our root quad-tree and subdivide it 4 times MyNode->SubDivide(); MyNode->SubDivide(); MyNode->SubDivide(); MyNode->SubDivide(); while(true) { if (Window.ChangedSize(&Width,&Height)) //If the window changes size, update the shaders. { NText::SetScreen(Width, Height); } if (!Window.CheckOpen()) //If the window is closed, clean up and exit. { std::cout << "X window closed, exiting...\n"; CleanAndExit(); } int X,Y; Window.GetMouse(&X,&Y); if (Window.GetKey() == 25) //If W is pressed clear the screen { Dots.clear(); } for (unsigned int i=0;i<3;i++) //create 3 dots per frame { Dot MyDot(rand()%Width,0,3+rand()%10); MyDot.VX = float(rand()%10-rand()%10); Dots.push_back(MyDot); } MyNode->Clear(); //empty out the quad tree for (unsigned int i=0;i<Dots.size();i++) //Update every dot and insert them into the quad tree { Dots[i].Update(MyNode); MyNode->AddObject(&Dots[i]); } glClear(GL_COLOR_BUFFER_BIT); //Clear buffer to our purple color. NQuadTree::DrawNodes(); //Draw some boxes around our quad tree's nodes for (unsigned int i=0;i<Dots.size();i++) //Draw our dots { Dots[i].Draw(); } MyText.Draw(); //Draw our text into the buffer. Window.SwapBuffer(); //Swap the buffer, effectively displaying the drawn image. Window.CapFPS(60); //Cap the fps at 60 so our program doesn't eat all the CPU it can. for (unsigned int i=0;i<Dots.size();i++) //Delayed position update to keep collisions sane { Dots[i].UpdatePos(); } } return 0; }
///////////////////////////////////////////////////////////////////////////// // // socketErrorExit // // Description // Print supplied error message and exit the program. // // Parameters // szError - Error message text // void CProxy::socketErrorExit(char *szError) { printf("Socket error: %s\n", szError); CleanAndExit(0); }