summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-05-06 22:31:11 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-05-06 22:31:11 +0200
commit5c9deee8dcd0299176c3a4d95af11bc3ca514f08 (patch)
treea106bc0672f9235438375d81b40dc083df59c9f3
parent8c0e4076b82d9b9b013bcf1fd89f0451d602508b (diff)
Changed raise algorithm.
-rw-r--r--gui.h2
-rw-r--r--quadtree.cpp18
-rw-r--r--quadtree.h2
-rw-r--r--tool.cpp2
4 files changed, 18 insertions, 6 deletions
diff --git a/gui.h b/gui.h
index 30bf6dd..fe3bb3e 100644
--- a/gui.h
+++ b/gui.h
@@ -1,6 +1,8 @@
#ifndef GUI_H
#define GUI_H
+// TODO: Remove temporary workaround for CEGUI + GCC 4.6
+#include <cstddef>
#include <CEGUI.h>
class GUI {
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();
diff --git a/quadtree.h b/quadtree.h
index 45ee09b..62ac8bb 100644
--- a/quadtree.h
+++ b/quadtree.h
@@ -52,7 +52,7 @@ class Quadtree {
Quadtree(int width, int height, float *heightmap);
virtual ~Quadtree();
- void raise(float x, float z, float radius, float focus, float strength);
+ void raise(float x, float z, float radius, float focus, float strength, bool up = true);
Vector3 calc_normal(int x, int y);
void update(float x, float z);
diff --git a/tool.cpp b/tool.cpp
index 83353b4..fc19b28 100644
--- a/tool.cpp
+++ b/tool.cpp
@@ -30,7 +30,7 @@ bool RaiseTool::handle_event(SDL_Event& event, Vector3& selected) {
return true;
case SDL_BUTTON_WHEELDOWN:
tree->raise(selected.x, selected.z, wnd->get_radius(), wnd->get_focus(),
- -wnd->get_strength());
+ wnd->get_strength(), false);
return true;
}
}