Display list for the maze structure
Objectives are not display-listed as they are removed when walked over.
This commit is contained in:
parent
648548693d
commit
254e94f912
2 changed files with 50 additions and 24 deletions
71
src/Maze.cpp
71
src/Maze.cpp
|
@ -42,10 +42,56 @@ Maze::Maze(const std::string& maze_map, unsigned int scaling_factor, const Textu
|
|||
static_cast<double>(y)};
|
||||
}
|
||||
}
|
||||
|
||||
preapre_display_list();
|
||||
}
|
||||
|
||||
Maze::~Maze()
|
||||
{
|
||||
if (display_list_index != -1)
|
||||
{
|
||||
glDeleteLists(display_list_index,1);
|
||||
}
|
||||
}
|
||||
|
||||
void Maze::draw()
|
||||
{
|
||||
// Draw Maze
|
||||
glCallList(display_list_index);
|
||||
|
||||
// Draw objectives
|
||||
for (const Vec3d& objective_pos: objective_positions)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef((objective_pos.x+0.5)*scaling_factor,objective_pos.y,(objective_pos.z+0.5)*scaling_factor);
|
||||
objective.draw_model();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
bool Maze::remove_objective(const Vec2i& position)
|
||||
{
|
||||
Vec3d objective{static_cast<double>(position.x),
|
||||
objective_altitude,
|
||||
static_cast<double>(position.y)};
|
||||
|
||||
for (auto it = objective_positions.begin();it!=objective_positions.end();++it)
|
||||
{
|
||||
if (objective == *it)
|
||||
{
|
||||
objective_positions.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Maze::preapre_display_list()
|
||||
{
|
||||
display_list_index = glGenLists(1);
|
||||
|
||||
glNewList(display_list_index,GL_COMPILE);
|
||||
|
||||
// Draw ground
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
|
||||
|
@ -124,14 +170,6 @@ void Maze::draw()
|
|||
}
|
||||
glEnd();
|
||||
|
||||
for (const Vec3d& objective_pos: objective_positions)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef((objective_pos.x+0.5)*scaling_factor,objective_pos.y,(objective_pos.z+0.5)*scaling_factor);
|
||||
objective.draw_model();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
// Draw outside
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,out.opengl_id[0]);
|
||||
|
@ -181,21 +219,6 @@ void Maze::draw()
|
|||
glVertex3f((outside_position.x+1)*scaling_factor,0,outside_position.z*scaling_factor);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
bool Maze::remove_objective(const Vec2i& position)
|
||||
{
|
||||
Vec3d objective{static_cast<double>(position.x),
|
||||
objective_altitude,
|
||||
static_cast<double>(position.y)};
|
||||
|
||||
for (auto it = objective_positions.begin();it!=objective_positions.end();++it)
|
||||
{
|
||||
if (objective == *it)
|
||||
{
|
||||
objective_positions.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
glEndList();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class Maze {
|
|||
public:
|
||||
Maze(const std::string& maze_map, unsigned int scaling_factor, const Texture& floor_texture,
|
||||
const Texture& wall_texture, const Texture& outside_texture, Model3D& objective);
|
||||
~Maze();
|
||||
|
||||
void draw();
|
||||
|
||||
|
@ -31,6 +32,8 @@ private:
|
|||
const Texture& out;
|
||||
Model3D& objective;
|
||||
|
||||
GLuint display_list_index = -1;
|
||||
|
||||
const double objective_altitude = 0;
|
||||
const double wall_height = 2;
|
||||
unsigned corner_pos;
|
||||
|
|
Loading…
Add table
Reference in a new issue