void BoundsTree::LayoutTree(Leaf *l, int depth) { depth--; if (depth == 0) { l->SetBottom(TRUE); return; } for (int i =0; i < 4; i++) { l->SetQuad(i, new Leaf(l->GetBounds(i).min,l->GetBounds(i).max)); } LayoutTree(l->GetQuad(0),depth); LayoutTree(l->GetQuad(1),depth); LayoutTree(l->GetQuad(2),depth); LayoutTree(l->GetQuad(3),depth); }
int main (int argc, char **argv) { Hangman controller; /* access to Hangman engine */ HM_Window window; /* access to Hangman gui */ char guess[32]; char filename[32]; int count = 0; int win = 0; HM_Window_Init(&window); LayoutTree(&window); DrawWindow(&window); // contains debugging statements to indicate where in the program execution is // initialize the controller printf ("initializing...\n"); Hangman_Init (&controller); // test the internet stuff controller.type = 'i'; Hangman_ReadFile(&controller, HOST); controller.type = 'f'; printf ("Enter file name: "); fgets (guess, sizeof (guess), stdin); guess[strlen (guess) - 1] = 0; strcpy (filename, PATH); printf ("%s\n",filename); strcat (filename, guess); printf("%s\n",filename); printf ("Reading file...\n"); Hangman_ReadFile (&controller, filename); printf ("Done.\n"); // loop for repeated tests, ctrl C to break while (1) { // start a new game printf ("Creating new game...\n"); Hangman_NewGame (&controller, controller.type); win = 0; count = 0; // loop through current game until user guesses correctly, or until they // run out of guesses while (controller.guessedSize < MAX_Guess && win == 0) { printf ("Guess: "); fgets (guess, sizeof (guess), stdin); if (Hangman_CheckGuess (&controller, guess)) { printf ("Correct!\n"); printf ("%s\n", controller.correctGuessed); } else printf ("wrong\n"); if (Hangman_AllCorrect (&controller)) win = 1; } controller.guessedSize = 0; } return 0; }
void BoundsTree::BuildQuadTree() { //layout tree based on depth Point2 min; min.x = 0.0f; min.y = 0.0f; Point2 max; max.x = 1.0f; max.y = 1.0f; Box3 bb; bb.Init(); for (int i = 0; i < meshList.Count(); i++) { if (meshList[i]) { bb += meshList[i]->bb; } } min.x = bb.pmin.x; min.y = bb.pmin.y; max.x = bb.pmax.x; max.y = bb.pmax.y; head = new Leaf(min,max); LayoutTree(head, depth); //now stuff the points into the boudningbox list for (int m = 0; m < meshList.Count(); m++) { if (meshList[m]) { meshList[m]->boundingBoxList.SetCount(meshList[m]->faces.Count()); Face *faces = meshList[m]->faces.Addr(0); for (i =0; i < meshList[m]->faces.Count(); i++) { meshList[m]->boundingBoxList[i].SetEmpty(); for (int j = 0; j < 3; j++) { int vid = (*faces).v[j]; Point3 p = meshList[m]->vertsViewSpace[vid]; Point2 p2; p2.x = p.x; p2.y = p.y; meshList[m]->boundingBoxList[i] += p2; } faces++; } //now go through our tree adding the bounding list for (i =0; i < meshList[m]->faces.Count(); i++) { AddFace(i,meshList[m]->boundingBoxList[i],m); } } } }