22 #include "precompiled.h"
43 : m_Heightmap(0), m_Patches(0), m_MapSize(0), m_MapSizePatches(0),
44 m_BaseColour(255, 255, 255, 255)
125 pos.
Z = float(j*TERRAIN_TILE_SIZE);
184 normal = n0 + n1 + n2 + n3;
185 float nlen=normal.
Length();
186 if (nlen>0.00001f) normal*=1.0f/nlen;
231 normal = n0 + n1 + n2 + n3;
335 u16 delta = std::max(std::max(h00, h01), std::max(h10, h11)) -
336 std::min(std::min(h00, h01), std::min(h10, h11));
375 return HEIGHT_SCALE * (h00 + (h10-h00)*xf + (h01-h00)*zf);
380 return HEIGHT_SCALE * (h11 + (h01-h11)*(1-xf) + (h10-h11)*(1-zf));
388 return HEIGHT_SCALE * (h00 + (h11-h01)*xf + (h01-h00)*zf);
393 return HEIGHT_SCALE * (h00 + (h10-h00)*xf + (h11-h10)*zf);
416 const fixed xf0 = xf / 2;
417 const fixed xf1 = (one - xf) / 2;
420 return ((one - zf).Multiply(xf1 * h00 + xf0 * h10)
443 return (mid1 < mid2);
463 u16* newHeightmap=
new u16[newMapSize*newMapSize];
469 memset(newHeightmap,0,newMapSize*newMapSize*
sizeof(
u16));
474 u16* dst=newHeightmap;
476 for (
ssize_t j=0;j<copysize;j++) {
477 memcpy(dst,src,copysize*
sizeof(
u16));
482 for (
size_t i=0;i<newMapSize-(size_t)
m_MapSize;i++) {
491 src=newHeightmap+((
m_MapSize-1)*newMapSize);
494 memcpy(dst,src,newMapSize*
sizeof(
u16));
525 CPatch* dstpatch=srcpatch+size;
531 CMiniPatch& dst=dstpatch->m_MiniPatches[m][k];
606 for (
ssize_t j = pj0; j <= pj1; j++)
608 for (
ssize_t i = pi0; i <= pi1; i++)
655 for (
ssize_t j = j0; j <= j1; ++j)
657 for (
ssize_t i = i0; i <= i1; ++i)
667 bound[0].Z = (float)(j0*TERRAIN_TILE_SIZE);
668 bound[1].X = (float)(i1*TERRAIN_TILE_SIZE);
669 bound[1].Y = (float)(maxH*HEIGHT_SCALE);
670 bound[1].Z = (float)(j1*TERRAIN_TILE_SIZE);
CStr8 GetMovementClass(ssize_t i, ssize_t j) const
A simple fixed-point number class.
CTerrainTextureEntry * GetTextureEntry()
void MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags)
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
CBoundingBoxAligned GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1)
Returns a 3D bounding box encompassing the given vertex range (inclusive)
void SetHeightMap(u16 *heightmap)
#define RENDERDATA_UPDATE_VERTICES
float GetTrilinearGroundLevel(float x, float z, float radius) const
CVector3D Cross(const CVector3D &vector) const
void CalcPosition(ssize_t i, ssize_t j, CVector3D &pos) const
bool GetTriangulationDir(ssize_t i, ssize_t j) const
void Normalize()
Normalize the vector so that length is close to 1.
float GetExactGroundLevel(float x, float z) const
void CalcNormal(ssize_t i, ssize_t j, CVector3D &normal) const
void CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D &pos) const
void Initialize(size_t mapSize, const u16 *ptr)
fixed GetSlopeFixed(ssize_t i, ssize_t j) const
const float HEIGHT_SCALE
metres per u16 height unit
CFixedVector3D Cross(const CFixedVector3D &v)
Compute the cross product of this vector with another.
CFixed Multiply(CFixed n) const
Multiply by a CFixed.
CMiniPatch * GetTile(ssize_t i, ssize_t j) const
CHeightMipmap m_HeightMipmap
void Update(const u16 *ptr)
void SetDirty(u32 dirtyflags)
bool Initialize(ssize_t patchesPerSide, const u16 *ptr)
fixed GetExactGroundLevelFixed(fixed x, fixed z) const
static CFixed FromInt(int n)
float GetFilteredGroundLevel(float x, float z, float radius) const
void CalcNormalFixed(ssize_t i, ssize_t j, CFixedVector3D &normal) const
fixed GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const
CPatch * GetPatch(ssize_t i, ssize_t j) const
float GetVertexGroundLevel(ssize_t i, ssize_t j) const
CMiniPatch m_MiniPatches[PATCH_SIZE][PATCH_SIZE]
void Resize(ssize_t size)
CStr GetMovementClass() const
void Initialize(CTerrain *parent, ssize_t x, ssize_t z)
CVector3D Normalized() const
T clamp(T value, T min, T max)
void CalcBounds()
(Re)calculates and stores any bounds or bound-dependent data for this object.
const CTerrainProperties & GetProperties() const
const ssize_t HEIGHT_UNITS_PER_METRE
number of u16 height units per metre
CVector3D CalcExactNormal(float x, float z) const
virtual void InvalidateBounds()
Marks the bounds as invalid.