terrain deformation functions to ITerrainSceneNode

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
gfxstyler
Posts: 222
Joined: Tue Apr 18, 2006 11:47 pm

terrain deformation functions to ITerrainSceneNode

Post by gfxstyler »

hi!

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 :D )



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]
asdfgames
Posts: 1
Joined: Thu Jan 25, 2007 2:20 am
Location: California

Post by asdfgames »

thanks, gfxstyler!

This is just what I was looking for... :D
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

wow this is an awesome function, thanks!

I vote for this to go in irrlicht.
gfxstyler
Posts: 222
Joined: Tue Apr 18, 2006 11:47 pm

Post by gfxstyler »

not like this. it really needs a range-check and code for re-generating the normals. i had that stuff done in my old irrlicht 1.1 but i switched to 1.2 and removed the old one. it's not much work because normal-generation code is already in the terrain-node.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Won't this value get overridden once the RenderBuffer is re-calculated from the original StaticBuffer when LOD's change???

Also, why not take into account transformation( scaling, rotationg, position )?
Image
gfxstyler
Posts: 222
Joined: Tue Apr 18, 2006 11:47 pm

Post by gfxstyler »

i turned LOD off in my project so i didnt notice that, it just seemed to work.

that's a big >DAMN< :?
wowdevver24
Posts: 26
Joined: Mon Jan 04, 2010 8:02 pm

Post by wowdevver24 »

I know this thread is kinda old but is there any way to do this to the terrain by modifying the vertex height of the mesh directly (why does irrlicht protect mesh data anyway as long as our programs access it through private shouldn't that be enough)
Remember all information is contextual and if I do not understand the context I cannot gras the information
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

What? Anyway, yes, old threads should stay as-is, unless one can put really useful information to that thread :?
Post Reply