Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Creating a Hexagonal Grid in Qt5
Forum Updated to NodeBB v4.3 + New Features

Creating a Hexagonal Grid in Qt5

Scheduled Pinned Locked Moved Unsolved Game Development
5 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nite Coder
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      If you need the cosine and sine formulas there here
      (This is the best site for everything hexagonal IMHO)

      JonBJ 1 Reply Last reply
      4
      • hskoglundH hskoglund

        If you need the cosine and sine formulas there here
        (This is the best site for everything hexagonal IMHO)

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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?

        hskoglundH 1 Reply Last reply
        0
        • JonBJ JonB

          @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?

          hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          @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 :-)

          JonBJ 1 Reply Last reply
          2
          • hskoglundH hskoglund

            @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 :-)

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @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 :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved