Could we get a feature in the terrain node?
-
3DModelerMan
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Could we get a feature in the terrain node?
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
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
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
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
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
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:
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
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
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];
}
}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;
}
}-
Insomniacp
- Posts: 288
- Joined: Wed Apr 16, 2008 1:45 am
- Contact:
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.
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.
