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:
Z Axis
^
|
/\
| | -> X axis
\/
(imagine this being equilateral)
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:
`%Project Title%
`%Source File Name%
`======================
global s as float
s=1
o=1
for n=0 to 10
for m=0 to 10
make object sphere o,1
position object o,getXPosition(n,m),0,getZPosition(n,m)
o=o+1
next m
next n
do
xrotate camera camera angle x()+mousemovey()*.1
yrotate camera camera angle y()+mousemovex()*.1
move camera ((mouseclick()=1)-(mouseclick()=2))*.01 //move by clicking the left and right mouse buttons
sync
loop
function getXPosition(n as integer,m as integer)
x#=n*s+cos(60)*s*(m mod 2)
endfunction x#
function getZPosition(n as integer, m as integer)
z#=sin(60)*s*m
endfunction z#
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
`%Project Title%
`%Source File Name%
`======================
global s as float
global xnum as integer
global znum as integer
xnum=10
znum=10
type hextiletype
obj as integer
foo as float
endtype
dim hextile(xnum,znum) as hextiletype
position camera 20,20,20
point camera 20,0,20
s=1
o=1
for n=0 to xnum
for m=0 to znum
make object sphere o,1
position object o,getXPosition(n,m),0,getZPosition(n,m)
hextile(n,m).obj=o
hextile(n,m).foo=rnd(1000)/1000.0
o=o+1
next m
next n
t#=0
do
t#=t#+.1
xrotate camera camera angle x()+mousemovey()*.1
yrotate camera camera angle y()+mousemovex()*.1
move camera ((mouseclick()=1)-(mouseclick()=2))*.01 //move by clicking the left and right mouse buttons
highlightAdjacentToMouse(colorFunction(t#))
sync
loop
function colorFunction(t as float)
r=cos01(t)*255
g=cos01(t*5)*100+100
b=cos01(t*2+100)*255
col=rgb(r,g,b)
endfunction col
function cos01(t as float)
n#=(cos(t)+1)*.5
endfunction n#
`highlights the object the mouse is hovering over as well as the six adjacent cells.
function highlightAdjacentToMouse(col as dword)
w=pick object(mousex(),mousey(),1,10000)
ntile=-100
mtile=-100
`find the tile with this object number.
for n=0 to xnum
for m=0 to znum
if hextile(n,m).obj=w
ntile=n
mtile=m
endif
next m
next n
colorTile(ntile,mtile,col) `this
colorTile(ladjn(ntile,mtile),mtile,col) `left
colorTile(tladjn(ntile,mtile),mtile+1,col)
colorTile(tradjn(ntile,mtile),mtile+1,col)
colorTile(radjn(ntile,mtile),mtile,col)
colorTile(bradjn(ntile,mtile),mtile-1,col)
colorTile(bladjn(ntile,mtile),mtile-1,col)
endfunction
function colorTile(n,m,color as dword)
if tileIsInRange(n,m)
color object hextile(n,m).obj, color
endif
endfunction
function tileIsInRange(n,m)
if n>=0 and m>=0 and n<=xnum and m<=znum then exitfunction 1
endfunction 0
function getXPosition(n as integer,m as integer)
x#=n*s+cos(60)*s*(m mod 2)
endfunction x#
function getZPosition(n as integer, m as integer)
z#=sin(60)*s*m
endfunction z#
rem get the n array index of adjacent tiles:
`top left adjacent n-array index
function tladjn(n as integer,m as integer)
if (m mod 2)=1
ret=n
else
ret=n-1
endif
endfunction ret
`left adjacent n-array index
function ladjn(n as integer,m as integer)
ret=n-1
endfunction ret
`bottom left adjacent n-array index
function bladjn(n as integer, m as integer)
if (m mod 2)=1
ret=n
else
ret=n-1
endif
endfunction ret
`top right adjacent n-array index
function tradjn(n as integer,m as integer)
if (m mod 2)=1
ret=n+1
else
ret=n
endif
endfunction ret
`right adjacent n-array index
function radjn(n as integer,m as integer)
ret=n+1
endfunction ret
`bottom right adjacent n-array index
function bradjn(n as integer, m as integer)
if (m mod 2)=1
ret=n+1
else
ret=n
endif
endfunction ret
