paysages: Apply canvas height limits to terrain
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@396 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
4477d40e7a
commit
3ad79c9b7c
4 changed files with 30 additions and 3 deletions
|
@ -72,11 +72,31 @@ void terrainCopyDefinition(TerrainDefinition* source, TerrainDefinition* destina
|
||||||
|
|
||||||
void terrainValidateDefinition(TerrainDefinition* definition)
|
void terrainValidateDefinition(TerrainDefinition* definition)
|
||||||
{
|
{
|
||||||
|
int i, n;
|
||||||
|
TerrainCanvas* canvas;
|
||||||
|
double min, max;
|
||||||
|
|
||||||
noiseValidate(definition->height_noise);
|
noiseValidate(definition->height_noise);
|
||||||
layersValidate(definition->canvases);
|
layersValidate(definition->canvases);
|
||||||
|
|
||||||
|
/* Get minimal and maximal height */
|
||||||
|
definition->_min_height = -noiseGetMaxValue(definition->height_noise) * definition->height_factor;
|
||||||
definition->_max_height = noiseGetMaxValue(definition->height_noise) * definition->height_factor;
|
definition->_max_height = noiseGetMaxValue(definition->height_noise) * definition->height_factor;
|
||||||
/* FIXME _max_height depends on canvases/modifiers */
|
|
||||||
|
n = layersCount(definition->canvases);
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
canvas = layersGetLayer(definition->canvases, i);
|
||||||
|
terrainCanvasGetLimits(canvas, &min, &max);
|
||||||
|
if (min < definition->_min_height)
|
||||||
|
{
|
||||||
|
definition->_min_height = min;
|
||||||
|
}
|
||||||
|
if (max > definition->_max_height)
|
||||||
|
{
|
||||||
|
definition->_max_height = max;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline double _getHeight(TerrainDefinition* definition, double x, double z)
|
static inline double _getHeight(TerrainDefinition* definition, double x, double z)
|
||||||
|
@ -309,13 +329,13 @@ double terrainGetHeight(TerrainDefinition* definition, double x, double z)
|
||||||
|
|
||||||
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z)
|
double terrainGetHeightNormalized(TerrainDefinition* definition, double x, double z)
|
||||||
{
|
{
|
||||||
if (definition->_max_height == 0.0)
|
if (definition->_max_height - definition->_min_height <= 0.0000001)
|
||||||
{
|
{
|
||||||
return 0.5;
|
return 0.5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0.5 + _getHeight(definition, x, z) / (definition->_max_height * 2.0);
|
return _getHeight(definition, x, z) - definition->_min_height / (definition->_max_height - definition->_min_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ typedef struct
|
||||||
Layers* canvases;
|
Layers* canvases;
|
||||||
double shadow_smoothing;
|
double shadow_smoothing;
|
||||||
|
|
||||||
|
double _min_height;
|
||||||
double _max_height;
|
double _max_height;
|
||||||
} TerrainDefinition;
|
} TerrainDefinition;
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,11 @@ void terrainCanvasLoad(PackStream* stream, TerrainCanvas* canvas)
|
||||||
packReadDouble(stream, &canvas->mask.smoothing);
|
packReadDouble(stream, &canvas->mask.smoothing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double terrainCanvasGetLimits(TerrainCanvas* canvas, double* ymin, double* ymax)
|
||||||
|
{
|
||||||
|
return heightmapGetLimits(canvas->height_map, ymin, ymax);
|
||||||
|
}
|
||||||
|
|
||||||
void terrainCanvasRevertToTerrain(TerrainCanvas* canvas, TerrainDefinition* terrain, int only_masked)
|
void terrainCanvasRevertToTerrain(TerrainCanvas* canvas, TerrainDefinition* terrain, int only_masked)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ LayerType terrainCanvasGetLayerType();
|
||||||
void terrainCanvasSave(PackStream* stream, TerrainCanvas* canvas);
|
void terrainCanvasSave(PackStream* stream, TerrainCanvas* canvas);
|
||||||
void terrainCanvasLoad(PackStream* stream, TerrainCanvas* canvas);
|
void terrainCanvasLoad(PackStream* stream, TerrainCanvas* canvas);
|
||||||
|
|
||||||
|
double terrainCanvasGetLimits(TerrainCanvas* canvas, double* ymin, double* ymax);
|
||||||
void terrainCanvasRevertToTerrain(TerrainCanvas* canvas, TerrainDefinition* terrain, int only_masked);
|
void terrainCanvasRevertToTerrain(TerrainCanvas* canvas, TerrainDefinition* terrain, int only_masked);
|
||||||
Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location);
|
Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue