# How to calculate IntBuffer?

Hi,
I am trying to wright hex tile by code. see below code and output. It looks correct as I wanted but I had to wright intbuffer manually.

How to calculate it programmatically?

See the last screen. Its generated in blender. I want to generate the same Hex grid by programmatically. I’ll appreciate is some one give me any suggestions for this too…!!!

``` private Mesh creteTrieFan() { Vector3f center = new Vector3f(0, 0, 0); float size = 1.0f; Vector3f[] vertices = new Vector3f[7]; int j = 1; DecimalFormat decimalFormat = new DecimalFormat("0.00"); vertices[0] = center; for (float i = 0; i < 6; i++) { float angle = 2.0f * FastMath.PI / 6.0f * (i + 0.5f); float x= center.x + size * FastMath.cos(angle); float z= center.z + size * FastMath.sin(angle); vertices[j] = new Vector3f(x, center.y, z); guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); BitmapText ch = new BitmapText(guiFont, false); ch.setSize(0.1f); ch.setText(j + " : " + decimalFormat.format(x) + " : " + decimalFormat.format(z)); ch.setColor(new ColorRGBA(1f, 0.8f, 0.3f, 0.8f)); ch.setLocalTranslation(x, 0.0f, z); rootNode.attachChild(ch); j++; } Mesh mesh = new Mesh(); int[] indexes = {1, 0, 2, 2, 0, 3, 3, 0, 4, 4, 0, 5, 5, 0, 6, 6, 0, 1}; mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes)); mesh.updateBound(); return mesh; } ```

I referred the same tutorial. but it’s not mentioned how to calculate intbuffer…

You can’t calculate it automatically.

its sad… is there any other way to do it?

Create the vertices line by line and then set your indexes array?

Or what exactly do you want to have calculated

you should find the tesselation function that match your need.
=> create triangle
=> list vertices index into your Index (IntBuffer)

to complete the tutorial (wiki)
eg of cone + tesselation:

Actually i think we should define what you mean for automatically.

Because if you mean like a generateIndexes(mesh) method, that works for every mesh, this is not possible.

If you want to fill a 2d shape of which you have only the external edges, this is possible, search for triangulation algorithms.

If you know the order of your vertices, ie. you generated them from a known function, then you can calculate the index as well… you just need to join the points… for instance in your specific case (first screenshot), you can find the central vertex, and then join any group of two adjacent vertices with the central one.

BTW why do you want to do this?
Is it just to have more vertices (for eg. Lighting or a terrain) or do you have some special plan for it like a triangle based strategy map, because then you should use different meshes instead of one

yes, basically I am planing to make hax grid based terrain system.

A, B or C - Yes ^^

B

So you need some way to store height information

probably in future, yes. my current target is make hex tile only.

Then what is a flat terrain system ?
I’m a bit confused right now

Edit: or do you mean something like

I am not going to make exactly “flat terrain system” but as of now in its initial stage it will be flat terrain only.
My Idea for Hex terrain system is like below.
Hex terrain will have many hex tiles.
The tiles can be added and removed or hide as per users preference. Idea is at a time 7 tiles will be on screen.
Each tile will have reference of its neighbors.
Each tile will have logical hex grid. The logical grid is basically virtually divided area of surface.
The logical grid will keep track of any assets on surface. e.g. trees grass, water, surface type, weather, characters and part of story line.
Event listeners and notification system will be implemented on tile and its logical grid.
Tile will be relatively small so that more better graphics can be presented.

Till now this is the idea.

So one tile is this huge hexagon from above?
So you can only see the “active” tile and its neighbours at a time?
Strange game idea I think XD

I do something like my picture above and for everey field I have a node which holds the ground, the objects etc for this position, you could not do that with one big mesh

Yes, its strange. I want to make plugable design. New story line and tile set can be added later as extension and will be co-relate with main story line.

Sounds cool, I hope we’ll see something from you
Now, have you solved your problem ?

Yes… I’ll share screenshots in some time.