Fixed terrain painting not updating has_painting
This commit is contained in:
parent
ec69975146
commit
c51d6d2d35
5 changed files with 52 additions and 30 deletions
|
@ -140,7 +140,7 @@ void PaintedGrid::clearPainting()
|
||||||
brush_data->clear();
|
brush_data->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y, double force)
|
void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y, double force, bool commit)
|
||||||
{
|
{
|
||||||
int xstart, xend, ystart, yend;
|
int xstart, xend, ystart, yend;
|
||||||
|
|
||||||
|
@ -165,6 +165,11 @@ void PaintedGrid::applyBrush(const PaintedGridBrush &brush, double x, double y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (commit)
|
||||||
|
{
|
||||||
|
endBrushStroke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintedGrid::endBrushStroke()
|
void PaintedGrid::endBrushStroke()
|
||||||
|
|
|
@ -62,17 +62,17 @@ public:
|
||||||
/**
|
/**
|
||||||
* Clear all painting and reset the initial value everywhere.
|
* Clear all painting and reset the initial value everywhere.
|
||||||
*/
|
*/
|
||||||
void clearPainting();
|
virtual void clearPainting();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a brush stroke at a grid location (locating the brush center).
|
* Apply a brush stroke at a grid location (locating the brush center).
|
||||||
*/
|
*/
|
||||||
void applyBrush(const PaintedGridBrush &brush, double x, double y, double force);
|
virtual void applyBrush(const PaintedGridBrush &brush, double x, double y, double force, bool commit=false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit previous brush strokes.
|
* Commit previous brush strokes.
|
||||||
*/
|
*/
|
||||||
void endBrushStroke();
|
virtual void endBrushStroke();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Virtual method that can be reimplemented to provide the initial value at a grid location.
|
* Virtual method that can be reimplemented to provide the initial value at a grid location.
|
||||||
|
|
|
@ -22,32 +22,46 @@ double TerrainHeightMap::getInitialValue(double x, double y) const
|
||||||
return terrain->getInterpolatedHeight(x, y, false, false);
|
return terrain->getInterpolatedHeight(x, y, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainHeightMap::brushElevation(const PaintedGridBrush &brush, double x, double y, double value)
|
void TerrainHeightMap::brushElevation(const PaintedGridBrush &brush, double x, double y, double value, bool commit)
|
||||||
{
|
{
|
||||||
PaintedGridBrushRaiseLower sbrush(brush);
|
PaintedGridBrushRaiseLower sbrush(brush);
|
||||||
applyBrush(sbrush, x, y, value / terrain->height);
|
applyBrush(sbrush, x, y, value / terrain->height, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainHeightMap::brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force)
|
void TerrainHeightMap::brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force, bool commit)
|
||||||
{
|
{
|
||||||
PaintedGridBrushFlatten sbrush(brush, height);
|
PaintedGridBrushFlatten sbrush(brush, height);
|
||||||
applyBrush(sbrush, x, y, force / terrain->height);
|
applyBrush(sbrush, x, y, force / terrain->height, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainHeightMap::brushSmooth(const PaintedGridBrush &brush, double x, double y, double value)
|
void TerrainHeightMap::brushSmooth(const PaintedGridBrush &brush, double x, double y, double value, bool commit)
|
||||||
{
|
{
|
||||||
PaintedGridBrushSmooth sbrush(brush);
|
PaintedGridBrushSmooth sbrush(brush);
|
||||||
applyBrush(sbrush, x, y, value / terrain->height);
|
applyBrush(sbrush, x, y, value / terrain->height, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainHeightMap::brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value)
|
void TerrainHeightMap::brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value, bool commit)
|
||||||
{
|
{
|
||||||
PaintedGridBrushAddNoise sbrush(brush, generator);
|
PaintedGridBrushAddNoise sbrush(brush, generator);
|
||||||
applyBrush(sbrush, x, y, value / terrain->height);
|
applyBrush(sbrush, x, y, value / terrain->height, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainHeightMap::brushReset(const PaintedGridBrush &brush, double x, double y, double value)
|
void TerrainHeightMap::brushReset(const PaintedGridBrush &brush, double x, double y, double value, bool commit)
|
||||||
{
|
{
|
||||||
PaintedGridBrushReset sbrush(brush);
|
PaintedGridBrushReset sbrush(brush);
|
||||||
applyBrush(sbrush, x, y, value / terrain->height);
|
applyBrush(sbrush, x, y, value / terrain->height, commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerrainHeightMap::clearPainting()
|
||||||
|
{
|
||||||
|
PaintedGrid::clearPainting();
|
||||||
|
|
||||||
|
terrain->validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerrainHeightMap::endBrushStroke()
|
||||||
|
{
|
||||||
|
PaintedGrid::endBrushStroke();
|
||||||
|
|
||||||
|
terrain->validate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,14 @@ public:
|
||||||
|
|
||||||
virtual double getInitialValue(double x, double y) const override;
|
virtual double getInitialValue(double x, double y) const override;
|
||||||
|
|
||||||
void brushElevation(const PaintedGridBrush &brush, double x, double y, double value);
|
void brushElevation(const PaintedGridBrush &brush, double x, double y, double value, bool commit=false);
|
||||||
void brushSmooth(const PaintedGridBrush &brush, double x, double y, double value);
|
void brushSmooth(const PaintedGridBrush &brush, double x, double y, double value, bool commit=false);
|
||||||
void brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value);
|
void brushAddNoise(const PaintedGridBrush &brush, double x, double y, NoiseGenerator* generator, double value, bool commit=false);
|
||||||
void brushReset(const PaintedGridBrush &brush, double x, double y, double value);
|
void brushReset(const PaintedGridBrush &brush, double x, double y, double value, bool commit=false);
|
||||||
void brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force);
|
void brushFlatten(const PaintedGridBrush &brush, double x, double y, double height, double force, bool commit=false);
|
||||||
|
|
||||||
|
virtual void clearPainting() override;
|
||||||
|
virtual void endBrushStroke() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TerrainDefinition* terrain;
|
TerrainDefinition* terrain;
|
||||||
|
|
|
@ -113,24 +113,24 @@ TEST_F(TerrainPainting_Test, brush_flatten)
|
||||||
|
|
||||||
/* Test flattening center at 0.5 */
|
/* Test flattening center at 0.5 */
|
||||||
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
||||||
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0);
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0, true);
|
||||||
_checkBrushResult(terrain, &brush, 0.5, 0.5, 0.5, 0.25, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.5, 0.5, 0.5, 0.25, 0.0, 0.0, 0);
|
||||||
|
|
||||||
/* Test brush strength */
|
/* Test brush strength */
|
||||||
terrain->height_map->clearPainting();
|
terrain->height_map->clearPainting();
|
||||||
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
||||||
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01);
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01, true);
|
||||||
_checkBrushResult(terrain, &brush, 0.005, 0.005, 0.005, 0.0025, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.005, 0.005, 0.005, 0.0025, 0.0, 0.0, 0);
|
||||||
|
|
||||||
/* Test cumulative effect */
|
/* Test cumulative effect */
|
||||||
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01);
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01, true);
|
||||||
_checkBrushResult(terrain, &brush, 0.00995, 0.00995, 0.00995, 0.0049875, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.00995, 0.00995, 0.00995, 0.0049875, 0.0, 0.0, 0);
|
||||||
|
|
||||||
/* Test with height modifier */
|
/* Test with height modifier */
|
||||||
terrain->height = 10.0;
|
terrain->height = 10.0;
|
||||||
terrain->height_map->clearPainting();
|
terrain->height_map->clearPainting();
|
||||||
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
||||||
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0);
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0, true);
|
||||||
_checkBrushResult(terrain, &brush, 0.05, 0.05, 0.05, 0.025, 0.0, 0.0, 0);
|
_checkBrushResult(terrain, &brush, 0.05, 0.05, 0.05, 0.025, 0.0, 0.0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,29 +144,29 @@ TEST_F(TerrainPainting_Test, brush_reset)
|
||||||
|
|
||||||
/* Test resetting at center */
|
/* Test resetting at center */
|
||||||
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
||||||
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0);
|
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
|
||||||
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
|
||||||
terrain->height_map->brushReset(brush, 0.0, 0.0, 1.0);
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 1.0, true);
|
||||||
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.5, 2.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.5, 2.0, 1.0, 0);
|
||||||
|
|
||||||
/* Test brush strength */
|
/* Test brush strength */
|
||||||
terrain->height_map->clearPainting();
|
terrain->height_map->clearPainting();
|
||||||
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
||||||
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0);
|
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
|
||||||
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
|
||||||
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1);
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
|
||||||
_checkBrushResult(terrain, &brush, 1.9, 1.9, 1.9, 1.95, 2.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.9, 1.9, 1.9, 1.95, 2.0, 1.0, 0);
|
||||||
|
|
||||||
/* Test cumulative effect */
|
/* Test cumulative effect */
|
||||||
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1);
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
|
||||||
_checkBrushResult(terrain, &brush, 1.81, 1.81, 1.81, 1.9025, 2.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.81, 1.81, 1.81, 1.9025, 2.0, 1.0, 0);
|
||||||
|
|
||||||
/* Test with height modifier */
|
/* Test with height modifier */
|
||||||
terrain->height = 10.0;
|
terrain->height = 10.0;
|
||||||
terrain->height_map->clearPainting();
|
terrain->height_map->clearPainting();
|
||||||
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
||||||
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0);
|
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
|
||||||
_checkBrushResult(terrain, &brush, 1.1, 1.1, 1.1, 1.1, 1.1, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.1, 1.1, 1.1, 1.1, 1.1, 1.0, 0);
|
||||||
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1);
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
|
||||||
_checkBrushResult(terrain, &brush, 1.099, 1.099, 1.099, 1.0995, 1.1, 1.0, 0);
|
_checkBrushResult(terrain, &brush, 1.099, 1.099, 1.099, 1.0995, 1.1, 1.0, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue