[java] Trouble with Hex Map
Tryin to draw my temp hex tiles, but i am having problems getting them to 'stick' horizontially, ive read tuts. but my problem is that i dont know how to find the length of each side on the hexagon, i need that for the other problems to work, but ive gone this far with just dividing the rectangular hexagon image.
code:
// even row
if (i%2==0) {
hexGraphic[j].draw(g,
(int)xPos+i*HEX_SIZE,
(int)yPos+j*HEX_SIZE);
}
// odd row
else {
hexGraphic[j].draw(g,
(int)xPos+i*HEX_SIZE,
(int)yPos+j*HEX_SIZE+HEX_SIZE/2);
}
picture:
http://img295.imageshack.us/img295/8981/hexhelpni9.png
Don't think of them as hexes. Think of them as 6 equalateral triangles joined.
So if you draw a line between the center points of 2 hexes, you are actually bisecting a triangle in each. And since all your hexes/triangles are the same size, you can figure out the length of one to find the distance between the 2. Just us basic geometry.
d = b / 2
e2 = b2 - d2
So if b is 6 then
e = sqrt(62 - 32)
e = sqrt(27)
e = 5.2
Hope that helps.
ps. I tried to draw a picture, but the forum won't let me draw preformatted text anymore. Check out this link instead and the pics there should help. The second picture shows the 6 triangles and the text helps explain a bit of what I am talking about.
http://mathforum.org/pow/solutio90.html
So if you draw a line between the center points of 2 hexes, you are actually bisecting a triangle in each. And since all your hexes/triangles are the same size, you can figure out the length of one to find the distance between the 2. Just us basic geometry.
d = b / 2
e2 = b2 - d2
So if b is 6 then
e = sqrt(62 - 32)
e = sqrt(27)
e = 5.2
Hope that helps.
ps. I tried to draw a picture, but the forum won't let me draw preformatted text anymore. Check out this link instead and the pics there should help. The second picture shows the 6 triangles and the text helps explain a bit of what I am talking about.
http://mathforum.org/pow/solutio90.html
I was looking at some other tutorials and replaced the code with this: i use 0.75 to represent the overlapping part:
// even row
if (i%2==0) {
hexGraphic[j].draw(g,
(int)xPos+i*(int)(HEX_SIZE*0.75),
(int)yPos+j*HEX_SIZE);
}
// odd row
else {
hexGraphic[j].draw(g,
(int)xPos+i*(int)(HEX_SIZE*0.75),
(int)yPos+j*HEX_SIZE+HEX_SIZE/2);
}
}
is there anything wrong with this? it seems to work fine, i just hope it doesnt mess up other calculations for placing objects on certain hex coords.
// even row
if (i%2==0) {
hexGraphic[j].draw(g,
(int)xPos+i*(int)(HEX_SIZE*0.75),
(int)yPos+j*HEX_SIZE);
}
// odd row
else {
hexGraphic[j].draw(g,
(int)xPos+i*(int)(HEX_SIZE*0.75),
(int)yPos+j*HEX_SIZE+HEX_SIZE/2);
}
}
is there anything wrong with this? it seems to work fine, i just hope it doesnt mess up other calculations for placing objects on certain hex coords.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement