#include <src/GrassyTerrain.h>
Inheritance diagram for GrassyTerrain:
Grass is modelled as an energy density per surface. It can grow with a given rate, and be eaten.
Public Member Functions | |
GrassyTerrain (double worldSize, double maxHeight, int level, double persistance=0.5, double power=1.0) | |
virtual double | getGrassDensity (const double x, const double y) |
Gets the current grass density at the given location. | |
virtual double | getNormalizedGrassDensity (const double x, const double y) |
Same as above, but normalized between 0 and 1. | |
virtual double | graze (const double x, const double y, const double amount) |
Tries to eat a certain amount of grass at the given location the real amount eaten, if the desired amount is more than the current grass density. | |
void | setMaximumGrassDensity (const double density) |
Maximum grass density = maximum energy per terrain square unit. Note this is really per square unit, whatever the discretization of the grid: It uses the worldsize argument in the constructor, not the level one. Default is a completely arbitrary 10.0. | |
double | getMaximumGrassDensity () |
void | setGrassDensity (const double density) |
Give an initial grass density. Default is 5.0. | |
void | setGrassGrowthRate (const double rate) |
The rate at which grass regenerates, in density per time unit. This is constant growth, not exponential, and clamped at MaximumGrassDensity. Default is a completely arbitrary 1.0. | |
double | getGrassGrowthRate () |
virtual void | scheduleForGrowth (double integrationTimeStep) |
Protected Member Functions | |
virtual void | grow () |
Integration step: grass grows till. | |
virtual void | updateColors () |
update the colors, but only when necessary (no useless polling) | |
Protected Attributes | |
double * | grass |
double * | grassEnd |
double | maximumGrassDensity |
double | maximumGrassDensityPerGridPoint |
double | invMaximumGrassDensityPerGridPoint |
double | grassGrowthRate |
double | grassGrowthRatePerGridPoint |
double | timeStep |
double | gcoef |
bool | cleanVisualState |
|
Gets the current grass density at the given location. The grass is considered a discrete grid, like for numerical integration. Unlike altitude (in parent Terrain), the grass density is not interpolated. Instead, the closest discrete grid cell is used. The reason for this is to avoid problems when eating the grass: Example: Suppose a request is made for a point C between A and B, with respective distance ratio 2/5 and 3/5. Now suppose we interpolate the values at A=2 and B=7. Then C would have interpolated value of 4. Now an agent request to eat 4 grass units at C. How do we split this request among the points A & B? Suppose we remove some amount from both A and B. Then since neither A and B can be negative, the value at C will be positive too. Thus, after removing 4 units at a place where the agent saw 4 units, grass still remains... till both A and B are consumed entirely, for a grand total of 9 units, thus miserably destroying the initial intent of the interpolation. Using only the closest value corrects this problem, and is consistent with numerical integration schemes anyway. |