Archived

This topic is now archived and is closed to further replies.

limon19

very very frusted...RE: moving a cursor by itself in a 2D Maze

Recommended Posts

hi- first of all thanks for any replies... heres the problem... -i cant seem to move my red box (the cursor) by itself to find the end of the maze.... -basically when the program is executed i want to be able to see the backtracking, the rights, lefts etc...as it tries to find the end -but instead, it just displays red boxes randomly (i think) everywhere in the maze -in my validPaths() method...i asses wether or not there exists a wall at each direction...(N,S,E,W)...if there''s no wall i push the coordinates on a stack...then utilizing a depth-first-search algorithm to ''find'' the end...again- i probably dint implement the recursion correctly (prolog is not my friend- yet anyhow)... -and when exactly should i use a glutSwapBuffers() rather than a glFlush()?? heres where i used them- achieved this comnbination late at night- through trial and error because i just wanted to see something on the screen rather than a SIGBUS- -drawGrid() //draws the maze glutSwapBuffers() -drawMove() //draws a red box at the cursor''s (x,y) location //here im trying to move the box(cursor), one move at a time- but //for some reason i end up seeing multiple redboxes everywhere glutSwapBuffers() -display() glClear(GL_COLOR_BUFFER_BIT) glFlush() -key() //when the user press ''b'' to begin maze glFlush() -validPaths() //right before the recursive call i have a drawMove()...heres'' //implementation...i think its fairly right- again i maybe dead //wrong validPaths(int x, int y, PLIST * &valid) { int chosenX, chosenY; if( (!within(x, 0, col)) && (!within(y, 0, row))){ printf("not within the range"); return; } if(mazeNorthWalls[x][y][VISITED] && mazeEastWalls[x][y][VISITED]) return; mazeNorthWalls[x][y][VISITED] = 1; mazeEastWalls[x][y][VISITED] = 1; if(y<(col-1)) if(mazeNorthWalls[x][y+1][NO_WALL] && !mazeNorthWalls[x][y+1][VISITED]) insertNode(x, y+1, valid); if(x > 0) if(mazeEastWalls[x-1][y][NO_WALL] && !mazeEastWalls[x-1][y][VISITED]) insertNode(x-1, y, valid); if(x<(row-1)) if(mazeEastWalls[x+1][y][NO_WALL] && !mazeEastWalls[x+1][y][VISITED]) insertNode(x+1, y, valid); if(y>0) if(mazeNorthWalls[x][y-1][NO_WALL] && !mazeNorthWalls[x][y-1][VISITED]) insertNode(x, y-1, valid); while(valid != NULL) { chosenX = valid->row; chosenY = valid->col; valid = valid->next; if(chosenX == desPosX && chosenY == desPosY){ printf("Hurrah!/n"); return; }else{ curPosX = chosenX; curPosY = chosenY; drawMove(); validPaths(curPosX, curPosY,valid); } } } I tried emailing my old professors for help- to no avail, no surprise there...move to new area, not acquainted with other programmers, therefore any help would be greatly (!) appreciated- sorry for the long post.. thanks. [Edited by - limon19 on February 27, 2008 7:30:04 PM]

Share this post


Link to post
Share on other sites
I suspect that your problem isn't really related to OpenGL. Feel free to revise the question and I'll move it to AI if you want. You will probably get a better response there.

To answer the OpenGL part:
quote:
and when exactly should i use a glutSwapBuffers() rather than a glFlush()??

You don't need glFlush if you're using glutSwapBuffers, since glutSwapBuffers calls glFlush() before returning. As long as you call it once per frame, you're okay.

[edited by - benjamin bunny on October 5, 2003 9:37:45 PM]

Share this post


Link to post
Share on other sites
concerning opengl all i could say is: forget glflush for now and use swapbuffers only once and right before you start drawing your new frame. that way opengl has as much time as possible to finish before you swap buffers. do NOT call swapbuffers multiple times during one frame, because that way it wont be one frame anymore.

Share this post


Link to post
Share on other sites