2013-11-10 20:14:10 +00:00
|
|
|
#include "BaseTestCase.h"
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
2015-12-30 23:36:22 +00:00
|
|
|
#include "Maths.h"
|
2016-01-14 19:24:01 +00:00
|
|
|
#include "NoiseNode.h"
|
|
|
|
#include "TestToolNoise.h"
|
2013-11-17 21:36:18 +00:00
|
|
|
#include "TerrainDefinition.h"
|
|
|
|
#include "TerrainHeightMap.h"
|
2014-09-15 10:32:27 +00:00
|
|
|
#include "PaintedGridBrush.h"
|
2015-08-17 20:55:30 +00:00
|
|
|
#include "FloatNode.h"
|
2013-11-10 16:03:07 +00:00
|
|
|
|
2016-01-14 19:24:01 +00:00
|
|
|
// Noise sin period is defined at 20.0
|
|
|
|
static constexpr double X_FACTOR = Maths::PI / 10.0;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class SinFractalNoise : public FractalNoise {
|
|
|
|
public:
|
|
|
|
SinFractalNoise() {
|
|
|
|
setScaling(1.0, 2.0);
|
|
|
|
setStep(0.0);
|
|
|
|
NoiseState state;
|
|
|
|
state.setLevelCount(1);
|
|
|
|
state.setLevel(0, 0.0, 0.0, 0.0);
|
|
|
|
setState(state);
|
|
|
|
}
|
|
|
|
virtual ~SinFractalNoise();
|
|
|
|
virtual double getBase1d(double x) const override {
|
|
|
|
return sin(x * X_FACTOR) * 0.5;
|
|
|
|
}
|
|
|
|
virtual double getBase2d(double x, double) const override {
|
|
|
|
return sin(x * X_FACTOR) * 0.5;
|
|
|
|
}
|
|
|
|
virtual double getBase3d(double x, double, double) const override {
|
|
|
|
return sin(x * X_FACTOR) * 0.5;
|
|
|
|
}
|
|
|
|
};
|
2013-11-10 16:03:07 +00:00
|
|
|
|
2016-01-14 19:24:01 +00:00
|
|
|
SinFractalNoise::~SinFractalNoise() {
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 20:14:10 +00:00
|
|
|
class TerrainPainting_Test : public BaseTestCase {
|
2016-01-14 19:24:01 +00:00
|
|
|
public:
|
|
|
|
virtual ~TerrainPainting_Test();
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
protected:
|
2013-11-10 20:14:10 +00:00
|
|
|
virtual void SetUp() {
|
2013-11-17 21:36:18 +00:00
|
|
|
terrain = new TerrainDefinition(NULL);
|
2016-01-14 19:24:01 +00:00
|
|
|
terrain->propHeightNoise()->forceSetGenerator(new SinFractalNoise);
|
2015-08-17 20:55:30 +00:00
|
|
|
terrain->propWaterHeight()->setValue(0.0);
|
2013-11-10 20:14:10 +00:00
|
|
|
}
|
2013-11-10 16:03:07 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
virtual void TearDown() {
|
2013-11-17 21:36:18 +00:00
|
|
|
delete terrain;
|
2013-11-10 20:14:10 +00:00
|
|
|
}
|
2013-11-10 16:03:07 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TerrainDefinition *terrain;
|
2013-12-31 14:56:30 +00:00
|
|
|
NoiseState noise_state;
|
2013-11-10 20:14:10 +00:00
|
|
|
};
|
2016-01-14 19:24:01 +00:00
|
|
|
TerrainPainting_Test::~TerrainPainting_Test() {
|
|
|
|
}
|
|
|
|
}
|
2013-11-10 16:03:07 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST_F(TerrainPainting_Test, grid) {
|
2013-11-10 16:03:07 +00:00
|
|
|
/* Test base grid */
|
2013-11-17 21:36:18 +00:00
|
|
|
EXPECT_DOUBLE_EQ(0.0, terrain->getGridHeight(0, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(0.0, terrain->getGridHeight(0, 1, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(0.0, terrain->getGridHeight(0, 0, 1));
|
|
|
|
EXPECT_DOUBLE_EQ(sin(1.0 * X_FACTOR), terrain->getGridHeight(1, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(sin(2.0 * X_FACTOR), terrain->getGridHeight(2, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(sin(3.0 * X_FACTOR), terrain->getGridHeight(3, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(sin(4.0 * X_FACTOR), terrain->getGridHeight(4, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(1.0, terrain->getGridHeight(5, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(sin(4.0 * X_FACTOR), terrain->getGridHeight(6, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(-sin(1.0 * X_FACTOR), terrain->getGridHeight(-1, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(0.0, terrain->getGridHeight(10, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(-1.0, terrain->getGridHeight(15, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(0.0, terrain->getGridHeight(20, 0, 0));
|
|
|
|
EXPECT_DOUBLE_EQ(-1.0, terrain->getGridHeight(-5, 0, 0));
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
/* Test interpolated result */
|
2016-01-14 19:24:01 +00:00
|
|
|
EXPECT_DOUBLE_EQ(terrain->getInterpolatedHeight(0.0, 0.0, false, false), 0.0);
|
|
|
|
EXPECT_DOUBLE_IN_RANGE(terrain->getInterpolatedHeight(0.5, 0.0, false, false), 0.1564, 0.1566);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getInterpolatedHeight(1.0, 0.0, false, false), sin(X_FACTOR));
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
static void _checkBrushResultSides(TerrainDefinition *terrain, PaintedGridBrush *, double center, double midhard,
|
|
|
|
double hard, double midsoft, double soft, double exter, double neg_midhard,
|
|
|
|
double neg_hard, double neg_midsoft, double neg_soft, double neg_exter) {
|
2013-11-17 21:36:18 +00:00
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(0, 0, 1), center);
|
|
|
|
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(1, 0, 1), midhard);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(2, 0, 1), hard);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(3, 0, 1), midsoft);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(4, 0, 1), soft);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(5, 0, 1), exter);
|
|
|
|
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(-1, 0, 1), neg_midhard);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(-2, 0, 1), neg_hard);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(-3, 0, 1), neg_midsoft);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(-4, 0, 1), neg_soft);
|
|
|
|
EXPECT_DOUBLE_EQ(terrain->getGridHeight(-5, 0, 1), neg_exter);
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
static void _checkBrushResult(TerrainDefinition *terrain, PaintedGridBrush *brush, double center, double midhard,
|
|
|
|
double hard, double midsoft, double soft, double exter, int mirror) {
|
|
|
|
if (mirror) {
|
|
|
|
_checkBrushResultSides(terrain, brush, center, midhard, hard, midsoft, soft, exter, -midhard, -hard, -midsoft,
|
|
|
|
-soft, -exter);
|
|
|
|
} else {
|
|
|
|
_checkBrushResultSides(terrain, brush, center, midhard, hard, midsoft, soft, exter, midhard, hard, midsoft,
|
|
|
|
soft, exter);
|
2013-11-10 16:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST_F(TerrainPainting_Test, brush_flatten) {
|
2013-11-10 16:03:07 +00:00
|
|
|
/* Set up */
|
2014-09-15 10:32:27 +00:00
|
|
|
PaintedGridBrush brush(2.0, 2.0, 4.0);
|
2016-01-14 19:24:01 +00:00
|
|
|
terrain->propHeightNoise()->forceSetGenerator(new ConstantFractalNoise(0.0));
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
/* Test flattening center at 0.5 */
|
|
|
|
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 1.0, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 0.5, 0.5, 0.5, 0.25, 0.0, 0.0, 0);
|
|
|
|
|
|
|
|
/* Test brush strength */
|
2013-11-17 21:36:18 +00:00
|
|
|
terrain->height_map->clearPainting();
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 0.005, 0.005, 0.005, 0.0025, 0.0, 0.0, 0);
|
|
|
|
|
|
|
|
/* Test cumulative effect */
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushFlatten(brush, 0.0, 0.0, 0.5, 0.01, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 0.00995, 0.00995, 0.00995, 0.0049875, 0.0, 0.0, 0);
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST_F(TerrainPainting_Test, brush_reset) {
|
2013-11-10 16:03:07 +00:00
|
|
|
/* Set up */
|
2014-09-15 10:32:27 +00:00
|
|
|
PaintedGridBrush brush(2.0, 2.0, 4.0);
|
|
|
|
PaintedGridBrush brush_full(4.0, 0.0, 4.0);
|
2016-01-14 19:24:01 +00:00
|
|
|
terrain->propHeightNoise()->forceSetGenerator(new ConstantFractalNoise(1.0));
|
2013-11-10 16:03:07 +00:00
|
|
|
|
|
|
|
/* Test resetting at center */
|
|
|
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 1.0, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.5, 2.0, 1.0, 0);
|
|
|
|
|
|
|
|
/* Test brush strength */
|
2013-11-17 21:36:18 +00:00
|
|
|
terrain->height_map->clearPainting();
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0);
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushFlatten(brush_full, 0.0, 0.0, 2.0, 1.0, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 0);
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 1.9, 1.9, 1.9, 1.95, 2.0, 1.0, 0);
|
|
|
|
|
|
|
|
/* Test cumulative effect */
|
2015-09-21 17:37:17 +00:00
|
|
|
terrain->height_map->brushReset(brush, 0.0, 0.0, 0.1, true);
|
2013-11-10 16:03:07 +00:00
|
|
|
_checkBrushResult(terrain, &brush, 1.81, 1.81, 1.81, 1.9025, 2.0, 1.0, 0);
|
|
|
|
}
|