Could we get a feature in the terrain node?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Could we get a feature in the terrain node?

Post by 3DModelerMan »

I noticed a getHeight(x, y) function in the terrain scene node, would it work tohave a setHeight(x, y, height) function? Or maybe a get dimensions function so that you could rebuild a heightmap based on the size of the terrain.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

does the getHeight() actually get the height of a particular vertex of the terrain geometry or it actually is getting the gray value of the pixel on the height map?
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
Brainsaw
Posts: 1241
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

I think it's returning the actual height of the geometry. I use it to show the altitude of the plane / helicopter in my IrrOdeCar demo.
Image
Dustbin::Games on the web: https://www.dustbin-online.de/
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

it returns the height of the intersection of the vertical line starting from the camera position and the terrain. If you are exactly above a vertex getHeight(...) return its height but you usually are not above a vertex.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

You could alter the mesh buffer that is being rendered, don't know how safe it is to do but here is the code I use

Code: Select all

node=smgr->addTerrainSceneNode("blankMap.bmp",0,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(0,0,0), SColor(255,255,255,255),6,ETPS_33);
			//now do some magical height altering
			IMeshBuffer* buff=node->getRenderBuffer();
			S3DVertex2TCoords* vertices=(S3DVertex2TCoords*)buff->getVertices();
			for(int x=0;x<mapSize;x++){
				for(int y=0;y<mapSize;y++){
					S3DVertex2TCoords* vertex = vertices +(x*mapSize+y) ; 
					vertex->Pos.Y=heights[x][y];
				}
			}
You can take that code and alter it into a function. It would look something like this if your maps are squares, pass the terrain node in, the x and y vertex, the height to set it to and the pixel width of the heightmap image (number of vertices in a given row of the terrain node since there is 1 vertex per pixel in the image). This code doesn't do any safety checks to make sure it worked or if the vertex is possible (so you can pass in any x and y and alter memory that you didn't want to. So you would have to add those. simple really....
if(x*mapSize+y<buff->getVertexCount())
I added that for you, anyway hope you enjoy.

Code: Select all

void setHeight(ITerrainSceneNode* node, int x, int y, f32 height, int mapSize){
if(x*mapSize+y<buff->getVertexCount()){
			//get the render buffer
			IMeshBuffer* buff=node->getRenderBuffer();
			//get the vertices
			S3DVertex2TCoords* vertices=(S3DVertex2TCoords*)buff->getVertices();
			//get the vertex we want to alter
			S3DVertex2TCoords* vertex = vertices +(x*mapSize+y) ; 
			//set its height
			vertex->Pos.Y=height;
}
}
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Post by REDDemon »

so you are directly moving vertices from the GPU? O_O
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

yes, I used it in my previous map editor though at the moment it is not working for me using my map generator code. Probably a mistake on my part that I over looked within my code.
In the map editor I used it to edit terrain heights in real time based on distance from the center of a sphere. The code is somewhere on the forums I think (well a link to a download). In the map editor I didn't see any other code that would make it work different from what I posted. You will probably want to adjust hardware mapping hints depending your use of this. If it is going to change often you can optimize it by making it either dynamic or stream.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to call setDirty() on the meshbuffer in order to get the data copied over to the GPU. Please note, though, that the full geometry is uploaded on the next frame. We don't support partial buffer updates. The terrain is EHM_DYNAMIC anyway, because of the LOD system.
Post Reply