diff options
-rw-r--r-- | gui.h | 2 | ||||
-rw-r--r-- | quadtree.cpp | 18 | ||||
-rw-r--r-- | quadtree.h | 2 | ||||
-rw-r--r-- | tool.cpp | 2 |
4 files changed, 18 insertions, 6 deletions
@@ -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(); @@ -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); @@ -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; } } |