5 #ifndef MERCATOR_SEGMENT_H
6 #define MERCATOR_SEGMENT_H
8 #include <Mercator/Mercator.h>
9 #include <Mercator/Matrix.h>
10 #include <Mercator/BasePoint.h>
12 #include <wfmath/vector.h>
13 #include <wfmath/axisbox.h>
27 typedef std::set<const TerrainMod *> ModList;
72 explicit Segment(
int x,
int y,
unsigned int resolution);
165 float get(
int x,
int y)
const {
170 WFMath::Vector<3> &normal)
const;
171 bool clipToSegment(
const WFMath::AxisBox<2> &bbox,
int &lx,
int &hx,
int &ly,
int &hy)
const;
184 WFMath::AxisBox<2>
getRect()
const;
187 WFMath::AxisBox<3>
getBox()
const;
198 const ModList& getMods()
const
202 int updateArea(
const Area* a);
207 void fill1d(
const BasePoint& l,
const BasePoint &h,
float *array)
const;
209 void fill2d(
const BasePoint& p1,
const BasePoint& p2,
210 const BasePoint& p3,
const BasePoint& p4);
212 float qRMD(WFMath::MTRand& rng,
float nn,
float fn,
float ff,
float nf,
213 float roughness,
float falloff,
float depth)
const;
223 #endif // MERCATOR_SEGMENT_H
const bool isValid() const
Check whether this Segment contains valid point data.
Definition: Segment.h:98
const int m_size
Size of segment, m_res + 1.
Definition: Segment.h:47
float * getNormals()
Accessor for write access to buffer containing surface normals.
Definition: Segment.h:160
void populateSurfaces()
Populate the surfaces associated with this Segment.
Definition: Segment.cpp:291
void invalidate(bool points=true)
Mark the contents of this Segment as stale.
Definition: Segment.cpp:173
float getMin() const
Accessor for the minimum height value in this Segment.
Definition: Segment.h:181
float ep1
Values at the four corners.
Definition: Segment.cpp:80
void fill2d(const BasePoint &p1, const BasePoint &p2, const BasePoint &p3, const BasePoint &p4)
Two dimensional midpoint displacement fractal.
Definition: Segment.cpp:390
const Surfacestore & getSurfaces() const
Accessor for list of attached Surface objects.
Definition: Segment.h:135
void applyMod(const TerrainMod *t)
Modify the heightfield data using the TerrainMod objects which are attached to this Segment.
Definition: Segment.cpp:660
unsigned int seed() const
Calculate the random seed used at this base point.
Definition: Segment.cpp:26
float * m_points
Pointer to buffer containing height points.
Definition: Segment.h:55
const int getSize() const
Accessor for array size of this segment.
Definition: Segment.h:81
int updateMod(const TerrainMod *t)
Update a TerrainMod in this Segment.
Definition: Segment.cpp:616
Surface * newSurface(const Segment &) const
Create a new Surface which matches the requirements of this shader.
Definition: Shader.cpp:29
~Segment()
Destruct the Segment.
Definition: Segment.cpp:129
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:36
float calc(float loc)
Determine the interpolated value along the line.
Definition: Segment.cpp:46
float calc(float locX, float locY)
Determine the interpolated value within the quad.
Definition: Segment.cpp:82
static const float FALLOFF
Default falloff at the base point.
Definition: BasePoint.h:34
Areastore m_areas
Areas which intersect this segment.
Definition: Segment.h:67
Segment(int x, int y, unsigned int resolution)
Construct an empty segment with the given resolution.
Definition: Segment.cpp:115
bool noCalc
Flag indicating that both points have the same value.
Definition: Segment.cpp:41
const Areastore & getAreas() const
Accessor for multimap of Area objects.
Definition: Segment.h:195
float m_max
Maximum height of any point in this segment.
Definition: Segment.h:59
const int m_res
Distance between segments.
Definition: Segment.h:45
int getLayer() const
Accessor for the layer number.
Definition: Area.h:52
A fixed sized array of objects.
Definition: Matrix.h:14
Helper to interpolate in a quad.
Definition: Segment.cpp:72
const int getXRef() const
Accessor for Global x reference of this segment.
Definition: Segment.h:86
const float roughness() const
Accessor for the roughness at the base point.
Definition: BasePoint.h:52
virtual void apply(float &point, int x, int y) const =0
Apply this modifier on a terrain segment.
float m_min
Minimum height of any point in this segment.
Definition: Segment.h:61
LinInterp(float size, float l, float h)
Constructor.
Definition: Segment.cpp:56
bool clipToSegment(const WFMath::AxisBox< 2 > &bbox, int &lx, int &hx, int &ly, int &hy) const
Determine the intersection between an axis aligned box and this segment.
Definition: Segment.cpp:580
float m_size
The length of one side of the square quad.
Definition: Segment.cpp:75
Region of terrain surface which is modified.
Definition: Area.h:28
std::map< int, Surface * > Surfacestore
STL map of pointers to Surface objects.
Definition: Segment.h:39
Surfacestore m_surfaces
Store of surfaces which can be rendered on this terrain.
Definition: Segment.h:64
const float * getNormals() const
Accessor for buffer containing surface normals.
Definition: Segment.h:155
Matrix< 2, 2, BasePoint > m_controlPoints
2x2 matrix of points which control this segment
Definition: Segment.h:53
const int getYRef() const
Accessor for Global y reference of this segment.
Definition: Segment.h:91
Point on the fundamental grid that is used as the basis for terrain.
Definition: BasePoint.h:19
WFMath::AxisBox< 2 > getRect() const
The 2d area covered by this segment.
Definition: Segment.cpp:752
float * m_normals
Pointer to buffer containing normals for height points.
Definition: Segment.h:57
void getHeightAndNormal(float x, float y, float &h, WFMath::Vector< 3 > &normal) const
Get an accurate height and normal vector at a given coordinate relative to this segment.
Definition: Segment.cpp:529
float * getPoints()
Accessor for write access to buffer containing height points.
Definition: Segment.h:150
void fill1d(const BasePoint &l, const BasePoint &h, float *array) const
One dimensional midpoint displacement fractal.
Definition: Segment.cpp:341
void setCornerPoint(unsigned int x, unsigned int y, const BasePoint &bp)
Set the BasePoint data for one of the four that define this Segment.
Definition: Segment.h:119
WFMath::AxisBox< 3 > getBox() const
The 3d box covered by this segment.
Definition: Segment.cpp:759
void invalidateSurfaces()
Mark surfaces as stale.
Definition: Segment.cpp:192
std::multimap< int, const Area * > Areastore
STL multimap of pointers to Area objects affecting this segment.
Definition: Segment.h:42
float ep1
Values at the two ends.
Definition: Segment.cpp:44
void clearMods()
Delete all the modifications applied to this Segment.
Definition: Segment.cpp:647
void populate()
Populate the Segment with heightfield data.
Definition: Segment.cpp:152
Matrix< 2, 2, BasePoint > & getControlPoints()
Accessor for modifying 2D matrix of base points.
Definition: Segment.h:130
void checkMaxMin(float h)
Check a value against m_min and m_max and set one of them if appropriate.
Definition: Segment.cpp:325
QuadInterp(float size, float e1, float e2, float e3, float e4)
Constructor.
Definition: Segment.cpp:95
int removeArea(const Area *a)
Remove an area from those that affect this segment.
Definition: Segment.cpp:725
ModList m_modList
List of TerrainMod objects that are applied to this Segment.
Definition: Segment.h:70
int removeMod(const TerrainMod *t)
Remove a TerrainMod from this Segment.
Definition: Segment.cpp:631
const Matrix< 2, 2, BasePoint > & getControlPoints() const
Accessor for 2D matrix of base points.
Definition: Segment.h:125
float m_height
The height at the base point.
Definition: BasePoint.h:22
int addMod(const TerrainMod *t)
Add a TerrainMod to this Segment.
Definition: Segment.cpp:606
const WFMath::AxisBox< 2 > & bbox() const
Accessor for the bounding box of the geometric shape.
Definition: Effector.h:46
bool noCalc
Flag indicating that all points have the same value.
Definition: Segment.cpp:77
void setMinMax(float min, float max)
Set min and max height values for this Segment.
Definition: Segment.h:106
float get(int x, int y) const
Get the height at a relative integer position in the Segment.
Definition: Segment.h:165
const float height() const
Accessor for the height at the base point.
Definition: BasePoint.h:47
const int m_yRef
Global y reference of this segment.
Definition: Segment.h:51
void populateNormals()
Populate the Segment with surface normal data.
Definition: Segment.cpp:207
float qRMD(WFMath::MTRand &rng, float nn, float fn, float ff, float nf, float roughness, float falloff, float depth) const
quasi-Random Midpoint Displacement (qRMD) algorithm.
Definition: Segment.cpp:311
Surfacestore & getSurfaces()
Accessor for modifying list of attached Surface objects.
Definition: Segment.h:140
float m_size
The length of the line.
Definition: Segment.cpp:39
Base class for modifiers to the procedurally generated terrain.
Definition: TerrainMod.h:20
const int getResolution() const
Accessor for resolution of this segment.
Definition: Segment.h:76
int addArea(const Area *a)
Add an area to those that affect this segment.
Definition: Segment.cpp:683
float getMax() const
Accessor for the maximum height value in this Segment.
Definition: Segment.h:179
const float * getPoints() const
Accessor for buffer containing height points.
Definition: Segment.h:145
const int m_xRef
Global x reference of this segment.
Definition: Segment.h:49
Helper to interpolate on a line.
Definition: Segment.cpp:36