Creating custom geometry

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jwadden
Posts: 2
Joined: Sat Aug 16, 2014 3:30 am

Creating custom geometry

Post by jwadden »

I'm trying to make a grid-based strategy game using Irrlicht, and I intend every grid tile to be a square made up of four triangles sharing five vertices, the height of which to be determined by the height of the tiles of the game map. The middle vertex will be the tile's actual height, and the heights of the vertexes at the four corners of the square will be determined based on the average heights of the tile and its neighbours in order to simulate smoothly rolling terrain.

I think I can do this by modifying the code from the Custom Scene Node tutorial, but doing it that way would seem to introduce a lot of unnecessary boilerplate code and require that I do things like calculate normals manually, which I'd prefer not to have to worry about. I've also seen mentions of a geometry creator class, but it only seems to be able to create a particular set of primitives, none of which are what I'm looking for. Does anyone have any ideas as to what the best way to create these grid tiles would be?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Creating custom geometry

Post by mongoose7 »

You don't need a custom scene node to create a mesh. Look at how the Geometry Creator builds a cube.And it is not hard to calculate the normal for a triangle: normalize(cross(B - A, C - A)). The Mesh Manipulator may be able to calculate normals but I'm not sure. I know there is code in Irrlicht somewhere for this. But it does raise the question of whether you want "smooth" normals.
jwadden
Posts: 2
Joined: Sat Aug 16, 2014 3:30 am

Re: Creating custom geometry

Post by jwadden »

Is there any kind of documentation or guide that would let me get more information on what you're talking about, or will I have to comb through the source code and try to piece things together?

EDIT: I just looked at the code for the gemotery creator and it looks like it's doing basically the same thing that the custom scene node example does. I'm not sure what I should be looking at here.
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Creating custom geometry

Post by kklouzal »

You have the ability to create your custom geometry as mongoose7 has suggested, or if I were you, I would take advantage of a library called PolyVox which would allow you to do exactly what you're trying to do here.

Basically you would just create your region, 1024x1024x1024 for example, then you can iterate through each voxel in your region assigning a "density" value between 0-255, the higher the density the more "square" that particular voxel would be, which in turn would allow you to create rolling hills like you want here. You can easily input a heightmap file and take the color value from each pixel of the heightmap to compute your density.
Dream Big Or Go Home.
Help Me Help You.
Post Reply