paysages : Added terrain canvas preview.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@406 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-08-08 15:32:54 +00:00 committed by ThunderK
parent 7d446591c9
commit 20bbe4f7ba
3 changed files with 59 additions and 27 deletions

View file

@ -11,8 +11,8 @@ public:
//addOsd(QString("geolocation"));
configScaling(0.5, 200.0, 3.0, 50.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
configScaling(1.0, 1.0, 1.0, 1.0);
//configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
~PreviewTerrainCanvasHeight()
@ -22,18 +22,37 @@ public:
protected:
QColor getColor(double x, double y)
{
Color col, mask;
double height;
height = 0.0; // TODO
return QColor((int)(255.0 * height), (int)(255.0 * height), (int)(255.0 * height));
if (_max - _min < 0.000001)
{
return Qt::black;
}
else
{
height = heightmapGetValue(&_preview_canvas->height_map, x + 0.5, y + 0.5);
col.r = col.g = col.b = (height - _min) / (_max - _min);
col.a = 1.0;
mask.r = 0.3;
mask.g = 0.0;
mask.b = 0.0;
mask.a = 1.0 - terrainCanvasGetMaskValue(_preview_canvas, x + 0.5, y + 0.5);
colorMask(&col, &mask);
return colorToQColor(col);
}
}
void updateData()
{
terrainCanvasCopy(_base_canvas, _preview_canvas);
heightmapGetLimits(&_preview_canvas->height_map, &_min, &_max);
}
private:
TerrainCanvas* _base_canvas;
TerrainCanvas* _preview_canvas;
double _max, _min;
};
/**************** Form ****************/

View file

@ -126,8 +126,7 @@ Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location)
double height, distance;
/* Get height map displacement */
inside_x = (location.x - canvas->area.location_x) / canvas->area.size_x;
inside_z = (location.z - canvas->area.location_z) / canvas->area.size_z;
geoareaToLocal(&canvas->area, location.x, location.z, &inside_x, &inside_z);
height = heightmapGetValue(&canvas->height_map, inside_x, inside_z);
/* Apply factor */
@ -137,28 +136,41 @@ Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location)
height += noiseGet2DTotal(canvas->detail_noise, location.x / canvas->detail_scaling, location.z / canvas->detail_scaling) * canvas->detail_height_factor;
/* Apply integration mask */
inside_x = (inside_x - 0.5) * 2.0;
inside_z = (inside_z - 0.5) * 2.0;
if (canvas->mask.mode == INTEGRATIONMASK_MODE_SQUARE)
{
inside_x = fabs(inside_x);
inside_z = fabs(inside_z);
distance = inside_x > inside_z ? inside_x : inside_z;
}
else
{
distance = sqrt(inside_x * inside_x + inside_z * inside_z);
}
if (distance <= 1.0 - canvas->mask.smoothing)
{
location.y = height;
}
else if (distance <= 1.0)
{
double influence = (1.0 - distance) / canvas->mask.smoothing;
location.y = influence * height + (1.0 - influence) * location.y;
}
double influence = terrainCanvasGetMaskValue(canvas, inside_x, inside_z);
location.y = influence * height + (1.0 - influence) * location.y;
}
return location;
}
double terrainCanvasGetMaskValue(TerrainCanvas* canvas, double local_x, double local_z)
{
double distance;
local_x = (local_x - 0.5) * 2.0;
local_z = (local_z - 0.5) * 2.0;
if (canvas->mask.mode == INTEGRATIONMASK_MODE_SQUARE)
{
local_x = fabs(local_x);
local_z = fabs(local_z);
distance = local_x > local_z ? local_x : local_z;
}
else
{
distance = sqrt(local_x * local_x + local_z * local_z);
}
if (distance <= 1.0 - canvas->mask.smoothing)
{
return 1.0;
}
else if (distance <= 1.0)
{
return (1.0 - distance) / canvas->mask.smoothing;
}
else
{
return 0.0;
}
}

View file

@ -47,6 +47,7 @@ void terrainCanvasLoad(PackStream* stream, TerrainCanvas* canvas);
void terrainCanvasGetLimits(TerrainCanvas* canvas, double* ymin, double* ymax);
void terrainCanvasRevertToTerrain(TerrainCanvas* canvas);
Vector3 terrainCanvasApply(TerrainCanvas* canvas, Vector3 location);
double terrainCanvasGetMaskValue(TerrainCanvas* canvas, double local_x, double local_z);
#ifdef __cplusplus
}