summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-06-01 20:09:51 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-06-01 20:09:51 +0200
commit41c94dfe4dd6ec19ae66f690a70447a5bbb04d8c (patch)
tree96095c5d84e8a31110b6c2cf2e8e12943cf48111
parent8b7e1b871e0895890257d6045e13b8fc22902a4c (diff)
Clean up normals in Terrain, fixes mingw32 build.
-rw-r--r--terrain.cpp56
-rw-r--r--terrain.h2
2 files changed, 7 insertions, 51 deletions
diff --git a/terrain.cpp b/terrain.cpp
index 4035a89..e32a52b 100644
--- a/terrain.cpp
+++ b/terrain.cpp
@@ -132,7 +132,6 @@ Terrain::Chunk::Chunk(Terrain *terrain, float x, float y) : cache_obj(terrain->t
this->n_height = height+1;
this->vbo_object = this->node_count = this->vertices = 0;
this->nodes = NULL;
- this->need_normals = true;
heights = cache_obj->heights;
normals = new Vector3[(int)((n_width)*(n_height))];
@@ -146,8 +145,7 @@ Terrain::Chunk::Chunk(Terrain *terrain, float x, float y) : cache_obj(terrain->t
}
}
- if(!need_normals)
- make_vbo();
+ make_vbo();
}
Terrain::Chunk::~Chunk() {
@@ -275,23 +273,6 @@ Terrain::Node* Terrain::Chunk::find(float x, float y) {
}
void Terrain::Chunk::calc_normals() {
- float *right, *left, *up, *down;
-
- /*TerrainCacheObject::p right_ob = terrain->tc->get_chunk(this->x - chunk_size, this->y, h_width, h_height),
- left_ob = terrain->tc->get_chunk(this->x + chunk_size, this->y, h_width, h_height),
- up_ob = terrain->tc->get_chunk(this->x, this->y + chunk_size, h_width, h_height),
- down_ob = terrain->tc->get_chunk(this->x, this->y - chunk_size, h_width, h_height);
-
- right = right_ob->heights;
- left = left_ob->heights;
- up = up_ob->heights;
- down = down_ob->heights;*/
-
- if(!right || !left || !up || !down) {
- need_normals = true;
- return;
- }
-
for(int x = 1; x < h_width-1; x++) {
for(int y = 1; y < h_height-1; y++) {
Vector3 p(x, heights[x*h_height + y], y);
@@ -299,48 +280,30 @@ void Terrain::Chunk::calc_normals() {
float h;
// right
- /*if(x == 0)
- h = right[(chunk_size-1)*(int)(h_height) + y];
- else*/
- h = heights[(x-1)*h_height + y];
+ h = heights[(x-1)*h_height + y];
U = Vector3(x-1, h, y) - p;
// down
- /*if(y == 0)
- h = down[x*(int)(h_height) + chunk_size - 1];
- else*/
- h = heights[x*h_height + y - 1];
+ h = heights[x*h_height + y - 1];
V = Vector3(x, h, y-1) - p;
N += V.cross(U);
// up
- /*if(y == h_height-1)
- h = up[x*(int)(h_height) + 1]; // y == 1
- else*/
- h = heights[x*h_height + y + 1];
+ h = heights[x*h_height + y + 1];
V = Vector3(x, h, y+1) - p;
N += U.cross(V);
// left
- /*if(x == h_width-1)
- h = left[h_height + y]; // x == 1
- else*/
- h = heights[(x+1)*h_height + y];
+ h = heights[(x+1)*h_height + y];
U = Vector3(x+1, h, y) - p;
//down
- /*if(y == 0)
- h = down[x*(int)(h_height) + chunk_size - 1];
- else*/
- h = heights[x*h_height + y - 1];
+ h = heights[x*h_height + y - 1];
V = Vector3(x, h, y-1) - p;
N += U.cross(V);
// up
- /*if(y == h_height-1)
- h = up[x*(int)(h_height) + 1]; // y == 1
- else*/
- h = heights[x*h_height + y + 1];
+ h = heights[x*h_height + y + 1];
V = Vector3(x, h, y+1) - p;
N += V.cross(U);
@@ -348,8 +311,6 @@ void Terrain::Chunk::calc_normals() {
normals[(x-1)*n_height + y - 1] = N;
}
}
-
- need_normals = false;
}
Terrain::Terrain() {
@@ -465,9 +426,6 @@ void Terrain::update(float x, float z) {
if(chunk->distance(x, z) > chunk_dist_threshold) {
delete *it;
it = chunks.erase(it);
- } else if((*it)->need_normals) {
- chunk->calc_normals();
- chunk->make_vbo();
}
}
diff --git a/terrain.h b/terrain.h
index cca01b7..386f6e3 100644
--- a/terrain.h
+++ b/terrain.h
@@ -42,8 +42,6 @@ class Terrain {
unsigned int vbo_object;
unsigned int node_count;
unsigned int vertices;
- float init_time;
- bool need_normals;
Chunk(Terrain *tree, float x, float y);
~Chunk();