diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 42 |
1 files changed, 34 insertions, 8 deletions
@@ -72,13 +72,17 @@ int main(int argc, char **argv) { SDL_Event event; bool running = true; bool grid = false; + bool terrain = true; bool gravity = true; SDL_WarpMouse(video::width/2, video::height/2); unsigned int last_time = SDL_GetTicks(); + unsigned int last_update = SDL_GetTicks(); /*boost::timer t; double last_time = 0;*/ Vector3 selected; Quadtree::QuadNode *node; + Quadtree::QuadNode *last_node = NULL; + scene.update(); while(running) { unsigned int time = SDL_GetTicks(); //double time = t.elapsed(); @@ -86,6 +90,10 @@ int main(int argc, char **argv) { unsigned int steps = time - last_time + 1; //double steps = (time - last_time) * 1000; last_time = time; + /*if(time - last_update > 5000) { + scene.update(); + last_update = time; + }*/ bool do_select = 0; int sx, sy; while(SDL_PollEvent(&event)) { @@ -101,6 +109,9 @@ int main(int argc, char **argv) { case SDLK_g: grid = !grid; break; + case SDLK_t: + terrain = !terrain; + break; case SDLK_KP_PLUS: case SDLK_PLUS: scene.qt->create_nodes(scene.qt->levels+1); @@ -127,6 +138,12 @@ int main(int argc, char **argv) { case SDLK_h: gravity = !gravity; break; + case SDLK_u: + scene.update(); + break; + case SDLK_c: + scene.qt->fix_cracks(); + break; default: break; } @@ -190,8 +207,9 @@ int main(int argc, char **argv) { scene.pos.y -= 0.002*steps*(keystate[SDLK_LSHIFT]?10:1); if(keystate[SDLK_e]) scene.pos.y += 0.002*steps*(keystate[SDLK_LSHIFT]?10:1); - if(moved && (forward || right)) + if(moved && (forward || right)) { scene.move(forward, right, steps*(keystate[SDLK_LSHIFT]?10:1)); + } std::string move_str; Quadtree::QuadNode *node = scene.qt->find(scene.pos.x, scene.pos.z); @@ -209,18 +227,21 @@ int main(int argc, char **argv) { } } move_str = (boost::format("%s %.2f,%.2f %.2fx%.2f %d") % scene.pos.str() % node->x % node->y % node->width % node->height % node->level).str(); - } - scene.update(); + if(last_node != node) { + last_node = node; + scene.update(); + } + } scene.lookat(); - glEnable(GL_LIGHTING); + //glEnable(GL_LIGHTING); const float light_pos[4] = {50, 100, 50, 1}; //const float light_pos[4] = {0, 1, 0, 0}; - glLightfv(GL_LIGHT0, GL_POSITION, light_pos); + //glLightfv(GL_LIGHT0, GL_POSITION, light_pos); - if(!grid) { + if(terrain) { program.use(); glBindTexture(GL_TEXTURE_2D, grass_texture); glEnable(GL_TEXTURE_2D); @@ -237,7 +258,12 @@ int main(int argc, char **argv) { glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); glUseProgram(0); - } else { + } + if(grid) { + if(terrain) + glColor3f(0, 0, 0); + else + glColor3f(1, 1, 1); std::queue<Quadtree::QuadNode*> q; q.push(scene.qt->root); while(!q.empty()) { @@ -251,7 +277,7 @@ int main(int argc, char **argv) { } } - glDisable(GL_LIGHTING); + //glDisable(GL_LIGHTING); float px, py, pz; if(do_select && scene.select(sx, sy, px, py, pz)) { |