Creating a Hexagonal Grid in Qt5
-
So recently I have been trying to figure out how to create a hexagonal grid in Qt for a game, like those in a strategy game. I have had zero luck inn doing so and was wondering if anyone knew how? I also am making this 2D.
Qt Version: 5.13.0
Platform: Arch Linux -
@hskoglund
Interesting! Nice to see hexes are still alive :)But calculate sine & cosines dynamically at run-time? Isn't that slow? Can't we do coords for hexagons without need them? At least cache the answers for multiples of 60 degrees?
-
@jonb Absolutely, caching the values/coords for a single hexagon is a good idea, will indeed save you same CPU cycles.
P.S. I remember drawing some hexagonal grids a long time ago, a slight complication in those days was the x/y ratio for the screen pixels, it wasn't 1:1 (CGA and EGA monitors). Like. a circle became an ellipse on screen etc. Nowadays it's so much easier :-)
-
@hskoglund
I drew hexagons on a UNIX box more-years-ago-than-I-care-to-admit. I doubt I used floating point sine/cosine calculations. Don't the vertices come out at some nice integer coordinate values for 60 degrees if you pick a suitable integer for the side lengths?a slight complication in those days was the x/y ratio for the screen pixels, it wasn't 1:1
That's not your problem as a programmer! 60 degrees is 60 degrees. The user can go buy a different monitor/graphics card if his ratio is not right :)