From 7d5c1adf8e581599848b3fec54e0af88eb469046 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 8 May 2011 15:02:30 +0200 Subject: Working dynamic generation of terrain. --- scene.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'scene.cpp') diff --git a/scene.cpp b/scene.cpp index b67468b..8d7301d 100644 --- a/scene.cpp +++ b/scene.cpp @@ -15,6 +15,7 @@ Scene::Scene() { running = true; grid = false; + normals = false; terrain = true; gravity = true; @@ -48,10 +49,7 @@ Scene::Scene() { marker_texture = load_texture("textures/cross.png"); /* init quadtree */ - int w = 1025; - int h = 1025; - float *heightmap = Terrain::generate_heights(0, 0, w, h); - qt = new Quadtree(w, h, heightmap); + qt = new Quadtree(); /* load font */ font = new FTTextureFont("fonts/VeraMono.ttf"); @@ -156,6 +154,9 @@ void Scene::events() { case SDLK_g: grid = !grid; break; + case SDLK_n: + normals = !normals; + break; case SDLK_t: terrain = !terrain; break; @@ -340,17 +341,19 @@ void Scene::render() { glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, marker_texture); - std::queue q; + /*std::queue q; q.push(qt->root); while(!q.empty()) { Quadtree::QuadChunk *chunk = q.front(); - q.pop(); - if(!chunk->nodes) { + q.pop();*/ + for(std::list::iterator it = qt->chunks.begin(); it != qt->chunks.end(); it++) { + Quadtree::QuadChunk *chunk = *it; + /*if(!chunk->nodes) { for(int i = 0; i < 4; i++) q.push(chunk->children[i]); continue; } else if(!chunk->vbo_object) - continue; + continue;*/ chunks_rendered++; glPushMatrix(); glTranslatef(-pos.x + chunk->x, -pos.y, -pos.z + chunk->y); @@ -382,19 +385,34 @@ void Scene::render() { glColor3f(0, 0, 0); else glColor3f(1, 1, 1); - std::queue q; + /*std::queue q; q.push(qt->root); while(!q.empty()) { Quadtree::QuadChunk *chunk = q.front(); - q.pop(); - if(!chunk->nodes) { + q.pop();*/ + for(std::list::iterator it = qt->chunks.begin(); it != qt->chunks.end(); it++) { + Quadtree::QuadChunk *chunk = *it; + glPushMatrix(); + glTranslatef(-pos.x, -pos.y, -pos.z); + /*if(!chunk->nodes) { for(int i = 0; i < 4; i++) q.push(chunk->children[i]); continue; - } else if(chunk->vbo_object) { + } else*/ if(chunk->vbo_object) { for(unsigned int i = 0; i < chunk->node_count; i++) chunk->nodes[i]->draw_grid(); } + glPopMatrix(); + } + } + if(normals) { + for(std::list::iterator it = qt->chunks.begin(); it != qt->chunks.end(); it++) { + Quadtree::QuadChunk *chunk = *it; + glPushMatrix(); + glTranslatef(-pos.x, -pos.y, -pos.z); + for(unsigned int i = 0; i < chunk->node_count; i++) + chunk->nodes[i]->draw_normal(); + glPopMatrix(); } } @@ -411,8 +429,8 @@ void Scene::render() { float height = font->LineHeight(); glColor3f(1, 1, 1); glTranslatef(0, video::height-height, 0); - font->Render((boost::format("%dx%d chunks: %d gravity: %d steps: %d") - % qt->width % qt->height % chunks_rendered % gravity % steps).str().c_str()); + font->Render((boost::format("chunks: %d gravity: %d steps: %d") + % chunks_rendered % gravity % steps).str().c_str()); //font->Render((boost::format("%dx%d %d levels %d nodes tree creation time: %f steps: %d update: %d") // % scene.qt->width % scene.qt->height % scene.qt->levels % scene.qt->nodes % scene.qt->init_time % steps % scene.qt->thread_running).str().c_str()); //glTranslatef(0, height, 0); -- cgit v1.2.3