From 47de5680043f0cc6420cdffb46c867aa7470efc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 9 Jun 2013 23:03:16 +0200 Subject: [PATCH] Added scaling adjustements This is not enough, there are still problems with painting brush offsets. --- src/editing/terrain/paintingbrush.cpp | 8 ++++---- src/editing/terrain/widgetheightmap.cpp | 8 ++++---- src/rendering/terrain/public.h | 2 +- src/rendering/terrain/ter_definition.c | 13 ++++++++++--- src/rendering/terrain/ter_painting.c | 18 +++++++++--------- src/rendering/terrain/ter_render.c | 2 +- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/editing/terrain/paintingbrush.cpp b/src/editing/terrain/paintingbrush.cpp index 8f18651..de1cf40 100644 --- a/src/editing/terrain/paintingbrush.cpp +++ b/src/editing/terrain/paintingbrush.cpp @@ -123,7 +123,7 @@ void PaintingBrush::applyToTerrain(TerrainDefinition* terrain, double x, double case PAINTING_BRUSH_SMOOTH: if (reverse) { - terrainBrushSmooth(terrain->height_map, &brush, brush_strength); + terrainBrushSmooth(terrain->height_map, &brush, brush_strength * 30.0); } else { @@ -133,15 +133,15 @@ void PaintingBrush::applyToTerrain(TerrainDefinition* terrain, double x, double case PAINTING_BRUSH_FLATTEN: if (reverse) { - _height = terrainGetInterpolatedHeight(terrain, x, z, 1); + _height = terrainGetInterpolatedHeight(terrain, x, z, 0, 1); } else { - terrainBrushFlatten(terrain->height_map, &brush, _height, brush_strength); + terrainBrushFlatten(terrain->height_map, &brush, _height, brush_strength * 30.0); } break; case PAINTING_BRUSH_RESTORE: - terrainBrushReset(terrain->height_map, &brush, brush_strength); + terrainBrushReset(terrain->height_map, &brush, brush_strength * 30.0); break; default: return; diff --git a/src/editing/terrain/widgetheightmap.cpp b/src/editing/terrain/widgetheightmap.cpp index f6cde1e..299d7b4 100644 --- a/src/editing/terrain/widgetheightmap.cpp +++ b/src/editing/terrain/widgetheightmap.cpp @@ -29,7 +29,7 @@ QGLWidget(parent) _wireframe = true; WaterDefinition* water_definition = (WaterDefinition*)WaterDefinitionClass.create(); sceneryGetWater(water_definition); - _water_height = _renderer->terrain->getWaterHeight(_renderer); + _water_height = 0.0; WaterDefinitionClass.destroy(water_definition); _average_frame_time = 0.0; @@ -74,7 +74,7 @@ void WidgetHeightMap::setTerrain(TerrainDefinition* terrain) { _terrain = terrain; TerrainRendererClass.bind(_renderer, _terrain); - _water_height = _renderer->terrain->getWaterHeight(_renderer); + _water_height = _renderer->terrain->getWaterHeight(_renderer) / _terrain->scaling; revert(); } @@ -210,7 +210,7 @@ void WidgetHeightMap::timerEvent(QTimerEvent*) _last_time = new_time; // Update top camera - Vector3 target = {_target_x, terrainGetInterpolatedHeight(_terrain, _target_x, _target_z, 1), _target_z}; + Vector3 target = {_target_x, terrainGetInterpolatedHeight(_terrain, _target_x, _target_z, 1, 1), _target_z}; cameraSetLocationCoords(_top_camera, target.x, target.y + 1.0, target.z + 0.1); cameraSetTarget(_top_camera, target); cameraSetZoomToTarget(_top_camera, _zoom); @@ -531,7 +531,7 @@ void WidgetHeightMap::updateVertexInfo() vertex->point.x = (double) dx; vertex->point.z = (double) dz; - vertex->point.y = terrainGetGridHeight(_terrain, dx, dz, 1); + vertex->point.y = terrainGetGridHeight(_terrain, dx, dz, 1) * _terrain->height; vertex->painted = terrainIsPainted(_terrain->height_map, dx, dz); } diff --git a/src/rendering/terrain/public.h b/src/rendering/terrain/public.h index 905e626..dddf26f 100644 --- a/src/rendering/terrain/public.h +++ b/src/rendering/terrain/public.h @@ -64,7 +64,7 @@ extern StandardRenderer TerrainRendererClass; void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset); void terrainRenderSurface(Renderer* renderer); double terrainGetGridHeight(TerrainDefinition* definition, int x, int z, int with_painting); -double terrainGetInterpolatedHeight(TerrainDefinition* definition, double x, double z, int with_painting); +double terrainGetInterpolatedHeight(TerrainDefinition* definition, double x, double z, int scaled, int with_painting); size_t terrainGetMemoryStats(TerrainDefinition* definition); Renderer* terrainCreatePreviewRenderer(); diff --git a/src/rendering/terrain/ter_definition.c b/src/rendering/terrain/ter_definition.c index be387c2..d61ef46 100644 --- a/src/rendering/terrain/ter_definition.c +++ b/src/rendering/terrain/ter_definition.c @@ -105,10 +105,10 @@ double terrainGetGridHeight(TerrainDefinition* definition, int x, int z, int wit height = noiseGet2DTotal(definition->_height_noise, (double)x, (double)z); } - return height * definition->height * definition->scaling; + return height; } -double terrainGetInterpolatedHeight(TerrainDefinition* definition, double x, double z, int with_painting) +double terrainGetInterpolatedHeight(TerrainDefinition* definition, double x, double z, int scaled, int with_painting) { double height; x /= definition->scaling; @@ -119,5 +119,12 @@ double terrainGetInterpolatedHeight(TerrainDefinition* definition, double x, dou height = noiseGet2DTotal(definition->_height_noise, x, z); } - return height * definition->height * definition->scaling; + if (scaled) + { + return height * definition->height * definition->scaling; + } + else + { + return height; + } } diff --git a/src/rendering/terrain/ter_painting.c b/src/rendering/terrain/ter_painting.c index b94ab59..fd90ddf 100644 --- a/src/rendering/terrain/ter_painting.c +++ b/src/rendering/terrain/ter_painting.c @@ -307,12 +307,12 @@ static double* _getDataPointer(HeightMapData* data, int x, int z, HeightMapData* } else if (terrain) { - *pixel = terrainGetGridHeight(terrain, x, z, 0) / (terrain->height * terrain->scaling); + *pixel = terrainGetGridHeight(terrain, x, z, 0); } } else if (terrain) { - *pixel = terrainGetGridHeight(terrain, x, z, 0) / (terrain->height * terrain->scaling); + *pixel = terrainGetGridHeight(terrain, x, z, 0); } } return pixel; @@ -411,7 +411,7 @@ int terrainHeightmapGetInterpolatedHeight(TerrainHeightMap* heightmap, double x, { if (!terrainHeightmapGetGridHeight(heightmap, ix, iz, &value)) { - value = terrainGetGridHeight(heightmap->terrain, ix, iz, 0) / (heightmap->terrain->scaling * heightmap->terrain->height); + value = terrainGetGridHeight(heightmap->terrain, ix, iz, 0); } stencil[(iz - (zlow - 1)) * 4 + ix - (xlow - 1)] = value; } @@ -468,7 +468,7 @@ static inline void _applyBrush(TerrainHeightMap* heightmap, TerrainBrush* brush, int x, z; double dx, dz, distance, influence; - force /= (heightmap->terrain->height * heightmap->terrain->scaling); + force /= heightmap->terrain->height; for (x = brush_rect.xstart; x <= brush_rect.xend; x++) { @@ -536,10 +536,10 @@ static double _applyBrushSmooth(TerrainHeightMap* heightmap, TerrainBrush* brush UNUSED(data); double ideal, factor; - ideal = terrainGetInterpolatedHeight(heightmap->terrain, x + brush->total_radius * 0.5, z, 1); - ideal += terrainGetInterpolatedHeight(heightmap->terrain, x - brush->total_radius * 0.5, z, 1); - ideal += terrainGetInterpolatedHeight(heightmap->terrain, x, z - brush->total_radius * 0.5, 1); - ideal += terrainGetInterpolatedHeight(heightmap->terrain, x, z + brush->total_radius * 0.5, 1); + ideal = terrainGetInterpolatedHeight(heightmap->terrain, x + brush->total_radius * 0.5, z, 0, 1); + ideal += terrainGetInterpolatedHeight(heightmap->terrain, x - brush->total_radius * 0.5, z, 0, 1); + ideal += terrainGetInterpolatedHeight(heightmap->terrain, x, z - brush->total_radius * 0.5, 0, 1); + ideal += terrainGetInterpolatedHeight(heightmap->terrain, x, z + brush->total_radius * 0.5, 0, 1); ideal /= 4.0; factor = influence * force; if (factor > 1.0) @@ -571,7 +571,7 @@ static double _applyBrushReset(TerrainHeightMap* heightmap, TerrainBrush* brush, UNUSED(brush); UNUSED(data); - double ideal = terrainGetInterpolatedHeight(heightmap->terrain, x, z, 0); + double ideal = terrainGetInterpolatedHeight(heightmap->terrain, x, z, 0, 0); return basevalue + (ideal - basevalue) * influence * force; } diff --git a/src/rendering/terrain/ter_render.c b/src/rendering/terrain/ter_render.c index c6d15a0..0a1e72e 100644 --- a/src/rendering/terrain/ter_render.c +++ b/src/rendering/terrain/ter_render.c @@ -18,7 +18,7 @@ static double _fakeGetHeight(Renderer* renderer, double x, double z, int with_pa static double _realGetHeight(Renderer* renderer, double x, double z, int with_painting) { - return terrainGetInterpolatedHeight(renderer->terrain->definition, x, z, with_painting); + return terrainGetInterpolatedHeight(renderer->terrain->definition, x, z, 1, with_painting); } static TerrainResult _fakeGetResult(Renderer* renderer, double x, double z, int with_painting, int with_textures)