20 class DisplayListManager;
23 class HeightFieldBlob;
31 struct HeightFieldConfig
33 HeightFieldConfig() : m_xAltitudeCount(0), m_yAltitudeCount(0), m_tileSize(0.f) {}
47 class HeightField :
public RefCountBase<HeightField, MemStat_CollisionData>
51 HeightField() : m_blob(
nullptr), m_altitudes(
nullptr), m_tileSizeInv(1.f) {}
54 KyResult Initialize(
const HeightFieldConfig& config);
55 KyResult InitFromBlob(HeightFieldBlob* blob);
62 KY_INLINE
KyUInt32 GetXTileCount()
const {
return m_tileBox.
CountX(); }
63 KY_INLINE
KyUInt32 GetYTileCount()
const {
return m_tileBox.
CountY(); }
64 KY_INLINE
KyUInt32 GetTileCount()
const {
return GetXTileCount() * GetYTileCount(); }
66 KY_INLINE
KyUInt32 GetXAltitudeCount()
const {
return m_vertexBox.
CountX(); }
67 KY_INLINE
KyUInt32 GetYAltitudeCount()
const {
return m_vertexBox.
CountY(); }
68 KY_INLINE
KyUInt32 GetAltitudeCount()
const {
return GetXAltitudeCount() * GetYAltitudeCount(); }
70 KY_INLINE
KyFloat32 GetXExtents()
const {
return GetXTileCount() * m_blob->m_tileSize; }
71 KY_INLINE
KyFloat32 GetYExtents()
const {
return GetYTileCount() * m_blob->m_tileSize; }
73 KY_INLINE
void SetAltitude(
const HeightfieldVertexPos& pixelPos,
KyFloat32 altitude)
78 KY_INLINE
Vec3f GetVertex(
const HeightfieldVertexPos& vertexPos)
const
80 const KyFloat32 altitude = GetAltitude(vertexPos);
81 return m_blob->m_origin +
Vec3f((
KyFloat32)vertexPos.x * m_blob->m_tileSize, (
KyFloat32)vertexPos.y * m_blob->m_tileSize, altitude);
84 KY_INLINE
KyResult GetTileAtPos(
const Vec3f& pos, HeightFieldTile& tile)
const
87 const Vec3f localPos = pos - m_blob->m_origin;
88 const CellPos cellPos(SnapFloat(localPos.x), SnapFloat(localPos.y));
89 return GetTileAtPos(cellPos, tile);
92 KY_INLINE
KyResult GetTileAtPos(
const HeightfieldTilePos& pixelPos, HeightFieldTile& tile)
const
94 if (m_tileBox.DoesContain(pixelPos) ==
false)
97 const KyFloat32 southEastX = ((
KyFloat32)pixelPos.x * m_blob->m_tileSize) + m_blob->m_origin.x + m_blob->m_tileSize;
98 const KyFloat32 southEastY = ((
KyFloat32)pixelPos.y * m_blob->m_tileSize) + m_blob->m_origin.y;
100 tile.m_vertices[0].x = southEastX;
101 tile.m_vertices[0].y = southEastY;
102 tile.m_vertices[0].z = GetAltitude(pixelPos.NeighborEast());
104 tile.m_vertices[1].x = southEastX;
105 tile.m_vertices[1].y = southEastY + m_blob->m_tileSize;
106 tile.m_vertices[1].z = GetAltitude(pixelPos.NeighborNorthEast());
108 tile.m_vertices[2].x = southEastX - m_blob->m_tileSize;
109 tile.m_vertices[2].y = southEastY + m_blob->m_tileSize;
110 tile.m_vertices[2].z = GetAltitude(pixelPos.NeighborNorth());
112 tile.m_vertices[3].x = southEastX - m_blob->m_tileSize;
113 tile.m_vertices[3].y = southEastY;
114 tile.m_vertices[3].z = GetAltitude(pixelPos);
116 tile.m_cellPos = pixelPos;
121 Box2f GetAABB2D()
const
123 return Box2f(m_blob->m_origin.Get2d(), m_blob->m_origin.Get2d() +
124 Vec2f(m_blob->m_xAltitudeCount * m_blob->m_tileSize, m_blob->m_yAltitudeCount * m_blob->m_tileSize));
131 KyResult WriteToObj(File* file)
const;
137 KY_INLINE
KyFloat32 GetAltitude(
const HeightfieldVertexPos& vertexPos)
const
142 KyResult GetStartTile(
const Vec3f& startPoint,
const Vec3f& endPoint, HeightFieldTile& tile)
const;
143 KyResult GetNextTile(
const HeightFieldTile& tile,
const Vec2f& rayA,
const Vec2f& rayB, HeightFieldTile& outTile,
const HeightFieldTile* destTile =
nullptr)
const;
148 return KyUInt32(inputValue * m_tileSizeInv);
154 return Vec3f(s * v0[0] + rt * v1[0],
155 s * v0[1] + rt * v1[1],
156 s * v0[2] + rt * v1[2]);
161 Ptr<BlobHandler<HeightFieldBlob> > m_blobHandler;
162 HeightFieldBlob* m_blob;
165 HeightfieldTileBox m_tileBox;
166 HeightfieldVertexBox m_vertexBox;
2d axis aligned box of 32bits floating points
Definition: box2f.h:15
Game side: Manages all DisplayListData, send them to the NavigationLab.
Definition: displaylist.h:375
2d axis aligned box of 32bits integers. Very Important: CountX() returns m_max.x - m_min...
Definition: box2i.h:17
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Box2i HeightfieldTileBox
A type that represents a bounding box around the Tiles of the Heigtfield.
Definition: heightfield.h:26
3d triangle of 32bits floating points
Definition: triangle3f.h:15
Wraps a IndexedMeshBlob either as IndexedMeshBlob* or as Ptr< />> Also adds ...
Definition: indexedmesh.h:18
Box2i HeightfieldVertexBox
A type that represents a bounding box around the Vertices of the Heighfield.
Definition: heightfield.h:29
Vec2i HeightfieldVertexPos
A type that represents one of the vertices of a Tile within a 2D grid.
Definition: heightfield.h:28
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
Vec2i HeightfieldTilePos
A type that represents the position of a Tile within a 2D grid.
Definition: heightfield.h:23
KyInt32 GetRowMajorIndex(const Vec2i &pos) const
Compute index of position in box, where index is incremented in a outer-loop on Y and inner-loop on X...
Definition: box2i.h:101
2d vector using KyFloat32.
Definition: vec2f.h:18
Navigation return code class.
Definition: types.h:108
Heightfield with a uniform grid of sampled altitudes.
Definition: heightfield.h:47
2d vector using KyInt32
Definition: vec2i.h:18
CollisionRayCastResult
CollisionRayCastResult.
Definition: collisiontypes.h:15
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
KyInt32 CountY() const
Return m_max.y - m_min.y + 1.
Definition: box2i.h:56
#define KY_ERROR
use result == KY_ERROR to test for error
Definition: types.h:132
KyInt32 CountX() const
Return m_max.x - m_min.x + 1.
Definition: box2i.h:55
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16