Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Hex Battlefield Question

Author
Message
Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 8th Aug 2012 16:47
Any ideea of how I would start a hex3d random map generator.
I want to generate a honeycomb pattern and out of it, pick let's say 10-20 hexa tiles, keep those and destroy the rest.
I presume this would not be difficult, but I find it difficult to create a honeycomb pattern.
I want to make it 3D. Can I generate it directly in DBPro?
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 8th Aug 2012 18:05 Edited at: 8th Aug 2012 18:06
You can generate a honeycomb object in DBPro, I think with the vertexdata commands.

For the positioning, you'll position the objecs at the centers of the tiles. This isn't too hard, and you basically just can use an x/y array of objects. Lets say you start with a tile at 0,0 and want to extend to the top right (in the XZ plane). Lets say the tile is oriented like this:


So let s be the width of a tile from flat part to flat part. The first row will just have object positions of:
(0,0),(s,0), (2*s,0) ... ,(n*s,0) where n is some integer. The second row will have the same thing but it will be offset by some value. The offset is a bit tricky because we don't have a flat edge going up in the Z axis. Each row we move up by sin(60)*s units, so the y position of each row will be sin(60)*s*m (where m denotes the z-row).

The x position is a bit trickier because it will switch between 0 and a small offset depending on if its even or odd. For odd rows the x position is n*s+cos(60)*s, but for even rows it's just n*s.

The modulo command here comes to our aid: m mod 2 (read "m modulo 2") gives the remainder of m when divided by two. It's zero when m is even, and one when m is odd. This gives the complete formula:

position(n,m)=(n*s+cos(60)*s*(m mod 2),sin(60)*s*m)

Here's an implementation of it:




Each tile at (n,m) is adjacent to six tiles, but the way that it they're connected, unfortunately, depends on whether m is odd or even. (you can't always say that (n+1,m+1) is adjacent to (n,m)). I'd write six functions that return the n-coordinate of the hex tile adjacent to the current tile. The m-coordinate doesn't depend on whether m is odd or even, so we don't need to write functions for it.

I got a bit carried away and wrote a demo :3




Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 8th Aug 2012 18:28
Wow man, I don't remember the community being THAT helpful

Thanks a lot. I saw you used spheres. I presume I can make a 3d hex in blender and use it instead of the sphere right? Or even generate it using the vertex commands. Should be no problem whatsoever!

Again, million thanks, would not have figured the formula on my own on such a short notice
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 8th Aug 2012 20:59
if you want to see how it looks with hexatiles just change this

for this

instant hexatiles.
Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 12th Aug 2012 04:43
I did not knew you can manipulate a sphere like that.
That's awsome, thanks
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Aug 2012 14:02
Hah! That's awesome, good idea.

Login to post a reply

Server time is: 2026-07-21 20:35:23
Your offset time is: 2026-07-21 20:35:23