i wanted to deform the terrain in my project, and i added 2 functions to the irrlicht source to make it easier to do.
what do those functions do?
a terrain is just a grid of vertices (points), and if you want to deform the terrain, you need to change the height of those vertices. my functions change or return the height of a specific vertex by the terrain.
how to use them?
Code: Select all
TerrainNode->setVertexHeight(123, 123, 1000.0);
float height = TerrainNode->getVertexHeight(123, 123);
note: if you use an X or Y value that is greater than the terrain heightmap's width or height, i think you will get a segmentation fault.
this can easily be prevented though, by adding checks to those functions (like: if(X > TheTerrainWidth){X = TerrainWidth;}) (i was too lazy to do that because i use a fixed terrain heightmap size of 129x129
ITerrainSceneNode.h, Line 155:
Code: Select all
virtual void setVertexHeight(const s32 X, const s32 Y, const f32 Height) = 0;
virtual f32 getVertexHeight(const s32 X, const s32 Y) = 0;
CTerrainSceneNode.h, Line 210:
Code: Select all
virtual void setVertexHeight(const s32 X, const s32 Y, const f32 Height);
virtual f32 getVertexHeight(const s32 X, const s32 Y);
CTerrainSceneNode.cpp, Line 1112:
Code: Select all
void CTerrainSceneNode::setVertexHeight(const s32 X, const s32 Y, const f32 Height)
{
RenderBuffer.Vertices[X*TerrainData.Size+Y].Pos.Y = Height;
}
f32 CTerrainSceneNode::getVertexHeight(const s32 X, const s32 Y)
{
return RenderBuffer.Vertices[X*TerrainData.Size+Y].Pos.Y;
}
maybe this is useful to some one out there. byebye![/code]
