Added scaling adjustements

This is not enough, there are still problems with painting brush offsets.
This commit is contained in:
Michaël Lemaire 2013-06-09 23:03:16 +02:00
parent b15ea439d2
commit 47de568004
6 changed files with 29 additions and 22 deletions

View file

@ -123,7 +123,7 @@ void PaintingBrush::applyToTerrain(TerrainDefinition* terrain, double x, double
case PAINTING_BRUSH_SMOOTH: case PAINTING_BRUSH_SMOOTH:
if (reverse) if (reverse)
{ {
terrainBrushSmooth(terrain->height_map, &brush, brush_strength); terrainBrushSmooth(terrain->height_map, &brush, brush_strength * 30.0);
} }
else else
{ {
@ -133,15 +133,15 @@ void PaintingBrush::applyToTerrain(TerrainDefinition* terrain, double x, double
case PAINTING_BRUSH_FLATTEN: case PAINTING_BRUSH_FLATTEN:
if (reverse) if (reverse)
{ {
_height = terrainGetInterpolatedHeight(terrain, x, z, 1); _height = terrainGetInterpolatedHeight(terrain, x, z, 0, 1);
} }
else else
{ {
terrainBrushFlatten(terrain->height_map, &brush, _height, brush_strength); terrainBrushFlatten(terrain->height_map, &brush, _height, brush_strength * 30.0);
} }
break; break;
case PAINTING_BRUSH_RESTORE: case PAINTING_BRUSH_RESTORE:
terrainBrushReset(terrain->height_map, &brush, brush_strength); terrainBrushReset(terrain->height_map, &brush, brush_strength * 30.0);
break; break;
default: default:
return; return;

View file

@ -29,7 +29,7 @@ QGLWidget(parent)
_wireframe = true; _wireframe = true;
WaterDefinition* water_definition = (WaterDefinition*)WaterDefinitionClass.create(); WaterDefinition* water_definition = (WaterDefinition*)WaterDefinitionClass.create();
sceneryGetWater(water_definition); sceneryGetWater(water_definition);
_water_height = _renderer->terrain->getWaterHeight(_renderer); _water_height = 0.0;
WaterDefinitionClass.destroy(water_definition); WaterDefinitionClass.destroy(water_definition);
_average_frame_time = 0.0; _average_frame_time = 0.0;
@ -74,7 +74,7 @@ void WidgetHeightMap::setTerrain(TerrainDefinition* terrain)
{ {
_terrain = terrain; _terrain = terrain;
TerrainRendererClass.bind(_renderer, _terrain); TerrainRendererClass.bind(_renderer, _terrain);
_water_height = _renderer->terrain->getWaterHeight(_renderer); _water_height = _renderer->terrain->getWaterHeight(_renderer) / _terrain->scaling;
revert(); revert();
} }
@ -210,7 +210,7 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
_last_time = new_time; _last_time = new_time;
// Update top camera // 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); cameraSetLocationCoords(_top_camera, target.x, target.y + 1.0, target.z + 0.1);
cameraSetTarget(_top_camera, target); cameraSetTarget(_top_camera, target);
cameraSetZoomToTarget(_top_camera, _zoom); cameraSetZoomToTarget(_top_camera, _zoom);
@ -531,7 +531,7 @@ void WidgetHeightMap::updateVertexInfo()
vertex->point.x = (double) dx; vertex->point.x = (double) dx;
vertex->point.z = (double) dz; 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); vertex->painted = terrainIsPainted(_terrain->height_map, dx, dz);
} }

View file

@ -64,7 +64,7 @@ extern StandardRenderer TerrainRendererClass;
void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset); void terrainAutoPreset(TerrainDefinition* definition, TerrainPreset preset);
void terrainRenderSurface(Renderer* renderer); void terrainRenderSurface(Renderer* renderer);
double terrainGetGridHeight(TerrainDefinition* definition, int x, int z, int with_painting); 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); size_t terrainGetMemoryStats(TerrainDefinition* definition);
Renderer* terrainCreatePreviewRenderer(); Renderer* terrainCreatePreviewRenderer();

View file

@ -105,10 +105,10 @@ double terrainGetGridHeight(TerrainDefinition* definition, int x, int z, int wit
height = noiseGet2DTotal(definition->_height_noise, (double)x, (double)z); 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; double height;
x /= definition->scaling; x /= definition->scaling;
@ -119,5 +119,12 @@ double terrainGetInterpolatedHeight(TerrainDefinition* definition, double x, dou
height = noiseGet2DTotal(definition->_height_noise, x, z); height = noiseGet2DTotal(definition->_height_noise, x, z);
} }
return height * definition->height * definition->scaling; if (scaled)
{
return height * definition->height * definition->scaling;
}
else
{
return height;
}
} }

View file

@ -307,12 +307,12 @@ static double* _getDataPointer(HeightMapData* data, int x, int z, HeightMapData*
} }
else if (terrain) else if (terrain)
{ {
*pixel = terrainGetGridHeight(terrain, x, z, 0) / (terrain->height * terrain->scaling); *pixel = terrainGetGridHeight(terrain, x, z, 0);
} }
} }
else if (terrain) else if (terrain)
{ {
*pixel = terrainGetGridHeight(terrain, x, z, 0) / (terrain->height * terrain->scaling); *pixel = terrainGetGridHeight(terrain, x, z, 0);
} }
} }
return pixel; return pixel;
@ -411,7 +411,7 @@ int terrainHeightmapGetInterpolatedHeight(TerrainHeightMap* heightmap, double x,
{ {
if (!terrainHeightmapGetGridHeight(heightmap, ix, iz, &value)) 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; stencil[(iz - (zlow - 1)) * 4 + ix - (xlow - 1)] = value;
} }
@ -468,7 +468,7 @@ static inline void _applyBrush(TerrainHeightMap* heightmap, TerrainBrush* brush,
int x, z; int x, z;
double dx, dz, distance, influence; 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++) for (x = brush_rect.xstart; x <= brush_rect.xend; x++)
{ {
@ -536,10 +536,10 @@ static double _applyBrushSmooth(TerrainHeightMap* heightmap, TerrainBrush* brush
UNUSED(data); UNUSED(data);
double ideal, factor; 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, 0, 1);
ideal += terrainGetInterpolatedHeight(heightmap->terrain, x - brush->total_radius * 0.5, z, 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, 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, 1); ideal += terrainGetInterpolatedHeight(heightmap->terrain, x, z + brush->total_radius * 0.5, 0, 1);
ideal /= 4.0; ideal /= 4.0;
factor = influence * force; factor = influence * force;
if (factor > 1.0) if (factor > 1.0)
@ -571,7 +571,7 @@ static double _applyBrushReset(TerrainHeightMap* heightmap, TerrainBrush* brush,
UNUSED(brush); UNUSED(brush);
UNUSED(data); 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; return basevalue + (ideal - basevalue) * influence * force;
} }

View file

@ -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) 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) static TerrainResult _fakeGetResult(Renderer* renderer, double x, double z, int with_painting, int with_textures)