vegetation: Added basic distribution algorithm
This commit is contained in:
parent
0ddec2393d
commit
d937bd08f6
3 changed files with 38 additions and 7 deletions
|
@ -155,7 +155,7 @@ void VegetationModelDefinition::randomize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add foliage items
|
// Add foliage items
|
||||||
for (int i = 0; i < 150; i++)
|
for (int i = 0; i < 50; i++)
|
||||||
{
|
{
|
||||||
double radius = 0.15;
|
double radius = 0.15;
|
||||||
Vector3 dir = Vector3::randomInSphere(1.0 - radius);
|
Vector3 dir = Vector3::randomInSphere(1.0 - radius);
|
||||||
|
|
|
@ -3,19 +3,46 @@
|
||||||
#include "Scenery.h"
|
#include "Scenery.h"
|
||||||
#include "TerrainDefinition.h"
|
#include "TerrainDefinition.h"
|
||||||
#include "VegetationLayerDefinition.h"
|
#include "VegetationLayerDefinition.h"
|
||||||
|
#include "VegetationModelDefinition.h"
|
||||||
#include "VegetationInstance.h"
|
#include "VegetationInstance.h"
|
||||||
|
#include "FloatNode.h"
|
||||||
|
#include "NoiseNode.h"
|
||||||
|
#include "NoiseGenerator.h"
|
||||||
|
|
||||||
VegetationPresenceDefinition::VegetationPresenceDefinition(VegetationLayerDefinition *parent):
|
VegetationPresenceDefinition::VegetationPresenceDefinition(VegetationLayerDefinition *parent):
|
||||||
DefinitionNode(parent, "presence")
|
DefinitionNode(parent, "presence")
|
||||||
{
|
{
|
||||||
|
noise = new NoiseNode(this);
|
||||||
|
noise->setLevels(4);
|
||||||
|
interval = new FloatNode(this, "interval", 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VegetationPresenceDefinition::collectInstances(std::vector<VegetationInstance> *result, const VegetationModelDefinition &model, double xmin, double zmin, double xmax, double zmax, bool outcomers) const
|
bool VegetationPresenceDefinition::collectInstances(std::vector<VegetationInstance> *result, const VegetationModelDefinition &model, double xmin, double zmin, double xmax, double zmax, bool outcomers) const
|
||||||
{
|
{
|
||||||
// TEMP debug implementation
|
bool added = 0;
|
||||||
double x = (xmin + xmax) / 2.0;
|
|
||||||
double z = (zmax + zmin) / 2.0;
|
const NoiseGenerator *generator = noise->getGenerator();
|
||||||
double y = getScenery()->getTerrain()->getInterpolatedHeight(x, z, true, true);
|
double interval_value = interval->getValue();
|
||||||
result->push_back(VegetationInstance(model, Vector3(x, y, z), 0.2));
|
|
||||||
return true;
|
double xstart = xmin - fmod(xmin, interval_value);
|
||||||
|
double zstart = zmin - fmod(zmin, interval_value);
|
||||||
|
for (double x = xstart; x < xmax; x += interval_value)
|
||||||
|
{
|
||||||
|
for (double z = zstart; z < zmax; z += interval_value)
|
||||||
|
{
|
||||||
|
double noise_presence = generator->get2DTotal(x * 0.1, z * 0.1);
|
||||||
|
if (noise_presence > 0.0)
|
||||||
|
{
|
||||||
|
double size = 0.1 + 0.2 * fabs(generator->get2DTotal(z * 10.0, x * 10.0)) * (noise_presence * 0.5 + 0.5);
|
||||||
|
double angle = 3.0 * generator->get2DTotal(-x * 20.0, z * 20.0); // TODO balanced distribution
|
||||||
|
double xoffset = fabs(generator->get2DTotal(x * 12.0, -z * 12.0));
|
||||||
|
double zoffset = fabs(generator->get2DTotal(-x * 27.0, -z * 27.0));
|
||||||
|
double y = getScenery()->getTerrain()->getInterpolatedHeight(x + xoffset, z + zoffset, true, true);
|
||||||
|
result->push_back(VegetationInstance(model, Vector3(x + xoffset, y, z + zoffset), size, angle));
|
||||||
|
added++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return added > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ public:
|
||||||
* It's the renderer role to apply the correct displacement.
|
* It's the renderer role to apply the correct displacement.
|
||||||
*/
|
*/
|
||||||
bool collectInstances(std::vector<VegetationInstance> *result, const VegetationModelDefinition &model, double xmin, double zmin, double xmax, double zmax, bool outcomers=true) const;
|
bool collectInstances(std::vector<VegetationInstance> *result, const VegetationModelDefinition &model, double xmin, double zmin, double xmax, double zmax, bool outcomers=true) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
NoiseNode *noise;
|
||||||
|
FloatNode *interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue