Implementación de OpenGL de laberinto 3D

I'm trying to create a simple 3D Maze in opengl. My initial idea was to have a grid of cubes with some of the faces of each cube transparent (for the corridors). However, I'm having a little trouble thinking of a way to do this efficiently. I don't want to have to define every single cube separately for my maze, that would be a huge mess of code (I think).

Also, would I need to create new cubes each time, or could I define a single cube and simply translate it while redrawing it to form the maze?

preguntado el 05 de mayo de 13 a las 17:05

If you want to go with the cube idea. Fill the entire grid with cubes, then use a maze generation algorithm such as depth first search ( en.wikipedia.org/wiki/Maze_generation_algorithm ) to move through the grid, removing cubes that are no longer part of the maze. Code should be simple for initializing the cubes. Just fill every grid spot. -

1 Respuestas

Defining each cube separetly would create a huge mess of code, as you said. Also it would be impossible to implement randomly generated mazes. And it would be very tiring to do any changes on the maze.

I would go with the "defining a single cube and simply translating it". Define a function which renders a cube with its center at the origin, and translate it according to its world coordinates.

I don't think you should use transparency at all. Simply render a cube if there is one and don't if there isn't one.

for(i=0; i<width; i++){
    for(j=0; j<height; j++){
        if(maze[i][j] == 1){  // Means there is a cube there
            glPushMatrix();
            glTranslatef(j * scale, 0, i * scale);
            DrawCube();
            glPopMatrix();
        }
    }
}

I suppose you could use a similar structure for collision detection too.

contestado el 06 de mayo de 13 a las 01:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.