Display list for the maze structure

Objectives are not display-listed as they are removed when walked over.
This commit is contained in:
trotFunky 2019-11-04 14:30:28 +01:00
parent 648548693d
commit 254e94f912
2 changed files with 50 additions and 24 deletions

View file

@ -42,10 +42,56 @@ Maze::Maze(const std::string& maze_map, unsigned int scaling_factor, const Textu
static_cast<double>(y)}; static_cast<double>(y)};
} }
} }
preapre_display_list();
}
Maze::~Maze()
{
if (display_list_index != -1)
{
glDeleteLists(display_list_index,1);
}
} }
void Maze::draw() 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 // Draw ground
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
@ -124,14 +170,6 @@ void Maze::draw()
} }
glEnd(); 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 // Draw outside
glBindTexture(GL_TEXTURE_2D,out.opengl_id[0]); 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); glVertex3f((outside_position.x+1)*scaling_factor,0,outside_position.z*scaling_factor);
glEnd(); glEnd();
}
bool Maze::remove_objective(const Vec2i& position) glEndList();
{
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;
} }

View file

@ -17,6 +17,7 @@ class Maze {
public: public:
Maze(const std::string& maze_map, unsigned int scaling_factor, const Texture& floor_texture, Maze(const std::string& maze_map, unsigned int scaling_factor, const Texture& floor_texture,
const Texture& wall_texture, const Texture& outside_texture, Model3D& objective); const Texture& wall_texture, const Texture& outside_texture, Model3D& objective);
~Maze();
void draw(); void draw();
@ -31,6 +32,8 @@ private:
const Texture& out; const Texture& out;
Model3D& objective; Model3D& objective;
GLuint display_list_index = -1;
const double objective_altitude = 0; const double objective_altitude = 0;
const double wall_height = 2; const double wall_height = 2;
unsigned corner_pos; unsigned corner_pos;