• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Telcontar

Hex Coordinate Math - Deriving the center of a "Superhex"

8 posts in this topic

Alright, so I'm building a game that uses hexagons for its maps. For my dark and mysterious reasons the world also needs to be split up into "Supertiles" (or Superhexes as I call them in the thread title) composed of nineteen hexes as shown in the picture below.

 

Assuming the origin tile of (0,0) is the center of a supertile, I'm trying to figure out a formula to calculate whether or not any other particular tile is the center of a supertile. (If no such exists, I can fall back on recursive algorithms to determine it after awhile using "jump towards origin by supertile-centers and see if you can hit 0,0", but I'd love to be able to calculate it directly).

 

I have the following tables for determining the centers of any NEIGHBORING supertile based on the coordinates for the center of the CURRENT supertile:

 

(N1 labeled in picture, go around clockwise for N2-6)

If the X-Coordinate is even:

  • N1: (+3, +3)
  • N2: (-2, +4)
  • N3: (-5, 0)
  • N4: (-3, -4)
  • N5: (+2, -4)
  • N6: (+5, -1)

If The X-Coordinate is odd:

  • N1: (+3,+4)
  • N2: (-2, +4)
  • N3: (-5, +1)
  • N4: (-3, -3)
  • N5: (+2, -4)
  • N6: (+5, 0)

[attachment=16836:hex_arrangement.png]

 

I have not yet found a solution to the problem by internet searches or using my own meager skills with math. If anyone can point me to one or figure it out, I will be eternally thankful. Furthermore if any part of the info above is incorrect or unclear please let me know - my brain hurts a bit, so it wouldn't surprise me.

 

I'm going to go sit in a corner and look at some pictures of kittens to soothe my brain.

0

Share this post


Link to post
Share on other sites

Your best bet for hex grids is to represent them as a rectangular grid but displace every other row by half a tile.

 

Like so:

 

hexgrid.png

 

That will probably make things easier for you to think about...

 

(You can still draw the hexes how you like, just represent the map like that, it will make the maths easier).

0

Share this post


Link to post
Share on other sites

Yes! Actually, that is in fact how they are arranged - as a simple 2D array. The graphic and all coordinates are calculated using that. Apologies for not mentioning that in the original post.

0

Share this post


Link to post
Share on other sites

I find the arithmetic much easier to handle if you use coordinates where moving down is always adding (0,1) and moving down and to the right is always adding (1,0) (or any other such convention). Those are still fairly standard coordinates in an affine plane, which means a lot of familiar things still work.

 

So start by transforming from your coordinates to the ones I describe (it should be as easy as taking (x,y) and mapping it to (x, y-floor(x/2)), or something like that).

 

Now the list of neighboring offsets is (3,2), (-2,5), (-5,3), (-3,-2), (2,-5), (5,-3)

 

The grid is now much more understandable, and the centers of the hexagons are simply of the form A*(3,2) + B*(-2,5), for some integers A and B.

 

From here there are several ways to finish the job. For instance, taking the matrix with columns (3,2) and (-2,5) and inverting it, I get this rule: A point (x,y) is the center of a hexagon if and only if 5x+2y is a multiple of 19 and 2x-3y is a multiple of 19.

2

Share this post


Link to post
Share on other sites

My approach was to look at the 6 directions in which the neighboring hexagons can be reached as 3 axes of a space. Hence one gets co-ordinates to the 6 surrounding super-hexagons as (0,3,2), (3,2,0), (2,0,-3) and their negatives, of course.

 

However, this leads to a similar system as in Avaro's solution above but with 3 equations, and hence seems not be worth to be investigated further. Probably this is because Alvaro's co-ordinates and mine can be transformed into each other.

0

Share this post


Link to post
Share on other sites

I find the arithmetic much easier to handle if you use coordinates where moving down is always adding (0,1) and moving down and to the right is always adding (1,0) (or any other such convention). Those are still fairly standard coordinates in an affine plane, which means a lot of familiar things still work.

 

I'm not certain I understand this. Can this be done while still using a 2D array of values to store the hexes (as a heightmap) in memory?

0

Share this post


Link to post
Share on other sites


I'm not certain I understand this. Can this be done while still using a 2D array of values to store the hexes (as a heightmap) in memory?

 

Yes, you only needed to read one more line in my post:


So start by transforming from your coordinates to the ones I describe (it should be as easy as taking (x,y) and mapping it to (x, y-floor(x/2)), or something like that).
1

Share this post


Link to post
Share on other sites

Try this:

bool is_center(int x, int y) {
  y -= (x - (x&1)) / 2;
  return (5*x + 2*y) % 19 == 0 && (2*x - 3*y) % 19 == 0;
}
1

Share this post


Link to post
Share on other sites

Oh, I read it - I just didn't understand it either. I believe I mentioned my meager math skills.

 

Either way, I think I get it now. Many thanks! That ought to about be the solution I need.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0