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 2.0k 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 26 Jul 2019, 01:38 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
    • H Offline
      H Offline
      hskoglund
      wrote on 26 Jul 2019, 01:58 last edited by
      #2

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

      J 1 Reply Last reply 26 Jul 2019, 13:10
      4
      • H hskoglund
        26 Jul 2019, 01:58

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

        J Online
        J Online
        JonB
        wrote on 26 Jul 2019, 13:10 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?

        H 1 Reply Last reply 26 Jul 2019, 22:12
        0
        • J JonB
          26 Jul 2019, 13:10

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

          H Offline
          H Offline
          hskoglund
          wrote on 26 Jul 2019, 22:12 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 :-)

          J 1 Reply Last reply 27 Jul 2019, 08:53
          2
          • H hskoglund
            26 Jul 2019, 22:12

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

            J Online
            J Online
            JonB
            wrote on 27 Jul 2019, 08:53 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

            2/5

            26 Jul 2019, 01:58

            • Login

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