summaryrefslogtreecommitdiff
path: root/quadtree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'quadtree.cpp')
-rw-r--r--quadtree.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/quadtree.cpp b/quadtree.cpp
index 65c60ae..396c18f 100644
--- a/quadtree.cpp
+++ b/quadtree.cpp
@@ -363,19 +363,29 @@ Quadtree::~Quadtree() {
delete[] normals;
}
-void Quadtree::raise(float x, float z, float radius, float focus, float strength) {
+void Quadtree::raise(float x, float z, float radius, float focus, float strength, bool up) {
if(x < 0 || x >= width-1 || z < 0 || z >= height-1)
return;
/* adjust heights */
- QuadNode *node = find(x, z);
for(int i = x-radius; i < x+radius; i++) {
if(i < 0 || i >= width-1)
continue;
for(int j = z-radius; j < z+radius; j++) {
if(j < 0 || j >= height-1)
continue;
- heights[i*height + j] += strength / max(powf((Vector2(x, z) - Vector2(i, j)).length(), focus), 1.0f);
+ 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);
+
+ if(up)
+ heights[i*height + j] += v;
+ else
+ heights[i*height + j] -= v;
}
}
@@ -398,7 +408,7 @@ void Quadtree::raise(float x, float z, float radius, float focus, float strength
if(nz < 0 || nz >= height-1)
continue;
QuadNode *node = find(nx, nz);
- for(int i = 0; i < node->chunk->node_count; i++) {
+ for(unsigned int i = 0; i < node->chunk->node_count; i++) {
node->chunk->nodes[i]->fill();
}
node->chunk->make_vbo();