• 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

Hexagon Map Subdivision Coordinate Problem

1 post in this topic

I have a website based MMO space trading game I'm working on and I'm having trouble with hexagon math when it comes to finding the subdivision on the map a particular hex is located in. I have a working site to actually toy with and to better understand my problem but I will also explain here with screen shots first.

Bring this test page up and click "Show Hex" in the upper right to understand what I'm saying here:
[b]PLEASE USE Internet Explorer![/b] I just realized there's a problem with the mouseover using Chrome.


I have a large galaxy on a hexagon map and this map is subdivided by larger hexagons on a scale of 1 to 25. The big hexes are 25 "Smaller" hexes across. From the center of one subdivision to the center of another is 25 hexes. It is also subdivided 5 times as you zoom out to view the entire galaxy. I call these big subdivisions "Quadrants" then "Zones" etc down to the actual Galactic Grid coordinates that something is on.

It looks like this as you zoom in down to New York on Earth:


As you zoom in you are clicking on a coordinate in the big hex where the center of the hex is 17:17. As you click down to New York in the screenshot, it has a a set of coordinates that look like this: 17:24, 17:17, 17:17, 17:17, 18:12, 11:14 and New York is on galactic coordinate -19:-68359247 from center of the universe. I translate the coordinates to actual named objects if they exists in the navbar. My hexagon map coordinate system is laid out like this:


I can figure out the galactic coordinate by multiplying the other coordinates offset by 17:17 and added to (25 ^ <the zoom level>). Which is to say, for every top level "Quadrant" hex you are offset by, your galactic coordinate moves by about 9765625 (25 to the 5th power) and then for every second level "Zone" you are offset from 17:17 by, you are at an additional 390625 (25 to the 4th power) hexes in that direction etc.

Its done in the database where you pass in all the coordinates and it gives you the galactic coordinate. The SQL code looks something like this:

Declare @intGalacticHex_X int
SET @intGalacticHex_X = 0

SET @intGalacticHex_X = @intGalacticHex_X + ((17 - @Quad_X) * (POWER(25,5)))
SET @intGalacticHex_X = @intGalacticHex_X + ((17 - @Zone_X) * (POWER(25,4)))
SET @intGalacticHex_X = @intGalacticHex_X + ((17 - @Sector_X) * (POWER(25,3)))
SET @intGalacticHex_X = @intGalacticHex_X + ((17 - @System_X) * (POWER(25,2)))
SET @intGalacticHex_X = @intGalacticHex_X + ((17 - @Hex_X) * (25))
SET @intGalacticHex_X = @intGalacticHex_X + ((17 - @Grid_X))

-- Return the result of the function
RETURN @intGalacticHex_X


While I can figure out your galactic coordinate based on all the upper tier coordinates you've provided, I haven't figured out how to the reverse it correctly. As in, If I give you a galactic coordinate, say New York on -19:-68359247 , I need to return the Quadrant, Zone, Sector, System, Hex and Grid Coordinates back (i.e. 17:24, 17:17, 17:17, 17:17, 18:12, 11:14)

It's a similar problem to the way you can translate pixel coordinates of the mouse to Hexagon coordinates, which I've been able to figure out with a lot of help, but I can't figure this one out as I can't find anyone who has an example.

Take the following graphic, which is kind of a zoom in of earth near Jupiter from the other screenshot, to to see how it is not straightforward:


Much like pixel to hexagon coordinates solutions, you probably need to break up the hex and do a different algorithm depending which part of the bigger hex it is in. New york is a bad example because its towards the center, but a spot towards the tips on the left or right is more difficult to figure out. As its vertical coordinate changes it runs across one subdivision for a few hexes and then the next for several more hexes.

Also, there is a "border" between hexes where the two bigger hexes technically share half of the hex. If you are on that border (There will be ships flying around) I need to have that ship resolve its coordinates in a consistent way, most likely dropping a fraction and having them be in the subdivision to the upper left. As long as they resolve consistently it's irrelevant which way they go but they cannot be in two subdivision hexes at the same time.

I tried a few different ways of resolving this but I can't wrap my head around it. The irony is that I can determine your galactic coordinate given all the other coordinates but I couldn't reverse it. I feel the simplest solution is to simply REVERSE the process I used to get your galactic coordinate using algebra but again, I tried and failed. I can figure out your X coordinate by using the powers of 25 and adding them together but to reverse it and get back all the other coordinates, I think I need to know your Y coordinate also.

I've tried some stuff using MOD 25 to try to figure out which subdivision you are on but again, I think I need to use both coordinates or try to figure out your "offset" first or something.

You can also zoom to the center of the galaxy to bring the galactic coordinates down to a manageable size and understand the coordinate system I'm using better. Start in the Milky Way and choose the center hex 17:17 all the way down and you should be at galactic 0:0. then zoom out and move around a bit to see how the coordinate system works.

Share this post

Link to post
Share on other sites
Does this simplified example code help you? It's C++, but the meaning of the code is practically self-evident. What you did so far was pretty clever.

#include <iostream>
using std::cout;
using std::endl;

#include <cmath>

int main(void)
long unsigned int galactic = 6;
long unsigned int solar = 13;
long unsigned int planetary = 3;

const long unsigned int galactic_factor = 625; // 25^2
const long unsigned int solar_factor = 25; // 25^1
const long unsigned int planetary_factor = 1; // 25^0

// combine individual position components into one position
long unsigned int pos = galactic*galactic_factor + solar*solar_factor + planetary*planetary_factor;

cout << pos << endl;

// retrieve individual position components
long unsigned int g = pos / galactic_factor;
long unsigned int s = (pos - g*galactic_factor) / solar_factor;
long unsigned int p = (pos - g*galactic_factor - s*solar_factor) / planetary_factor;

cout << galactic << ' ' << g << endl;
cout << solar << ' ' << s << endl;
cout << planetary << ' ' << p << endl;

return 0;

It's worth noting that if you go to Wolfram Alpha and type in "solve for g where x = g*a + s*b + p*c", you'll get a basic idea of what I did here. Of course, since the factors are of a different order of magnitude, the solution presented in the code is thankfully simpler than that given by Wolfram Alpha. For what it's worth, algebra is evil and I feel your pain. Hope this helps.

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