summaryrefslogtreecommitdiff
path: root/scene.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-05-08 15:02:30 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-05-08 15:02:30 +0200
commit7d5c1adf8e581599848b3fec54e0af88eb469046 (patch)
tree824d398dc14b7044b49d15b35d0c3501264e10fd /scene.cpp
parent17715403aff8ba1889c9e1ef473fe9319b87d1d2 (diff)
Working dynamic generation of terrain.
Diffstat (limited to 'scene.cpp')
-rw-r--r--scene.cpp46
1 files changed, 32 insertions, 14 deletions
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<Quadtree::QuadChunk*> q;
+ /*std::queue<Quadtree::QuadChunk*> q;
q.push(qt->root);
while(!q.empty()) {
Quadtree::QuadChunk *chunk = q.front();
- q.pop();
- if(!chunk->nodes) {
+ q.pop();*/
+ for(std::list<Quadtree::QuadChunk*>::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<Quadtree::QuadChunk*> q;
+ /*std::queue<Quadtree::QuadChunk*> q;
q.push(qt->root);
while(!q.empty()) {
Quadtree::QuadChunk *chunk = q.front();
- q.pop();
- if(!chunk->nodes) {
+ q.pop();*/
+ for(std::list<Quadtree::QuadChunk*>::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<Quadtree::QuadChunk*>::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);