summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--terrain.cpp72
1 files changed, 48 insertions, 24 deletions
diff --git a/terrain.cpp b/terrain.cpp
index a6f1e66..b9927b4 100644
--- a/terrain.cpp
+++ b/terrain.cpp
@@ -5,6 +5,7 @@
#include <noise/noise.h>
#include "noiseutils/noiseutils.h"
+#include <boost/format.hpp>
#include <iostream>
#include <cmath>
@@ -475,57 +476,80 @@ bool Terrain::has_chunk(int x, int y) {
}
void Terrain::raise(float x, float z, float radius, float focus, float strength, bool up) {
- // TODO: fix this
-/* if(x < 0 || x >= width-1 || z < 0 || z >= height-1)
- return;
+ // TODO: check nodes
/* adjust heights */
- /*for(int i = x-radius; i < x+radius; i++) {
- if(i < 0 || i >= width-1)
- continue;
+ for(int i = x-radius; i < x+radius; i++) {
for(int j = z-radius; j < z+radius; j++) {
- if(j < 0 || j >= height-1)
- continue;
float v = powf((radius - min((Vector2(x, z) - Vector2(i, j)).length(), radius)) * strength, 1+focus);
if(focus > 0)
/* Scale v with radius based on focus.
* Not 100% accurate, but close enough.
*/
- /*v /= radius * (focus/2);
+ v /= radius * (focus/2);
+ Node *node = find(i, j);
+ int index = (i-node->chunk->x)*(node->chunk->height+1) + j-node->chunk->y;
if(up)
- heights[i*height + j] += v;
+ node->chunk->heights[index] += v;
else
- heights[i*height + j] -= v;
+ node->chunk->heights[index] -= v;
+
+ /* fill the "outer border" */
+ if(i % chunk_size == 0) {
+ node = find(i-chunk_size, j);
+ if(node) {
+ index = (chunk_size)*(node->chunk->height+1) + j-node->chunk->y;
+ if(up)
+ node->chunk->heights[index] += v;
+ else
+ node->chunk->heights[index] -= v;
+ }
+ }
+ if(j % chunk_size == 0) {
+ node = find(i, j-chunk_size);
+ if(node) {
+ index = (i-node->chunk->x)*(node->chunk->height+1) + chunk_size;
+ if(up)
+ node->chunk->heights[index] += v;
+ else
+ node->chunk->heights[index] -= v;
+ }
+ }
+ if(i % chunk_size == 0 && j % chunk_size == 0) {
+ node = find(i-chunk_size, j-chunk_size);
+ if(node) {
+ index = (chunk_size)*(node->chunk->height+1) + chunk_size;
+ if(up)
+ node->chunk->heights[index] += v;
+ else
+ node->chunk->heights[index] -= v;
+ }
+ }
}
}
/* recalculate normals */
- /*for(int i = x-radius-1; i < x+radius; i++) {
- if(i < 0 || i >= width-1)
- continue;
- for(int j = z-radius-1; j < z+radius; j++) {
- if(j < 0 || j >= height-1)
- continue;
- calc_normal(i, j);
+ for(int i = x-radius-1; i < x+radius; i+=chunk_size) {
+ for(int j = z-radius-1; j < z+radius; j+=chunk_size) {
+ find(i, j)->chunk->calc_normals();
}
}
/* refill nodes and remake VBOs */
- /*for(int nx = x-radius-1; nx < x+radius+chunk_size; nx+=chunk_size) {
- if(nx < 0 || nx >= width-1)
- continue;
+ for(int nx = x-radius-1; nx < x+radius+chunk_size; nx+=chunk_size) {
for(int nz = z-radius-1; nz < z+radius+chunk_size; nz+=chunk_size) {
- if(nz < 0 || nz >= height-1)
- continue;
Node *node = find(nx, nz);
+ if(!node) {
+ continue;
+ }
for(unsigned int i = 0; i < node->chunk->node_count; i++) {
node->chunk->nodes[i]->fill();
}
node->chunk->make_vbo();
}
- }*/
+ }
}
void Terrain::update(float x, float z) {