diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-04-01 15:53:14 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-04-01 15:53:14 +0200 |
commit | 3b360c21777aad02394a643b32be2ab25362bba1 (patch) | |
tree | e5a3ed2c546e31c9e83170c53fc75c0016169384 /main.cpp | |
parent | bd22509aa429c6f33075293e379f1e2b2714a094 (diff) |
Some cleanup in preparation for dynamic subdivision of the terrain quadtree.
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
@@ -198,14 +198,14 @@ int main(int argc, char **argv) { grid = !grid; break; case SDLK_KP_PLUS: - delete qt; - qt = new Quadtree(hm->w, hm->h, heightmap, ++level); + case SDLK_PLUS: + qt->create_nodes(++level); level = qt->levels; break; case SDLK_KP_MINUS: + case SDLK_MINUS: if(level > 0) { - delete qt; - qt = new Quadtree(hm->w, hm->h, heightmap, --level); + qt->create_nodes(--level); } break; case SDLK_SPACE: @@ -278,21 +278,19 @@ int main(int argc, char **argv) { scene.move(forward, right, steps*(keystate[SDLK_LSHIFT]?10:1)); std::string move_str; - { - Quadtree::QuadNode *node = qt->find(scene.pos.x, scene.pos.z); - if(node) { - float y = node->get_height(scene.pos.x, scene.pos.z); - if(scene.pos.y > y && !keystate[SDLK_e]) - scene.yvel -= 9.81 * steps / 85000; - if(scene.yvel < -.5) - scene.yvel = -.5; - scene.pos.y += scene.yvel * steps; - if(scene.pos.y < y) { - scene.pos.y = y; - scene.yvel = 0; - } - move_str = (boost::format("%s %.2f,%.2f %dx%d") % scene.pos.str() % node->x % node->y % node->width % node->height).str(); + Quadtree::QuadNode *node = qt->find(scene.pos.x, scene.pos.z); + if(node) { + float y = node->get_height(scene.pos.x, scene.pos.z); + if(scene.pos.y > y && !keystate[SDLK_e]) + scene.yvel -= 9.81 * steps / 85000; + if(scene.yvel < -.5) + scene.yvel = -.5; + scene.pos.y += scene.yvel * steps; + if(scene.pos.y < y) { + scene.pos.y = y; + scene.yvel = 0; } + move_str = (boost::format("%s %.2f,%.2f %dx%d %d") % scene.pos.str() % node->x % node->y % node->width % node->height % node->level).str(); } scene.lookat(); |