Advertisement

Drawing hex map

Started by May 18, 2000 08:49 AM
1 comment, last by Peter Fisla 24 years, 7 months ago
Hi all, I was wondering what would be the reasonable way to draw hexes. I''m working on a operational wargame, I have a structure that knows the coordinates of all the exes on the map. I have my transparency function set up so that I can draw my hex map. In ::OnDraw() which in WinApi really means WM_PAINT I have a for loop and I draw all my hexes (meaning the for loop uses the coordinate numbers from the strucutre). My map is 151 x 81 hexes big so the for loop is from 0 to 12392. Now I know this is not a good way to draw since I''m drawing all the exes even thouse not needed on the screen. So the trick is to draw only the hexes that my screen is currently displaying. I suppose one way it would be to check scroll bars and to find out what position they are and based on that draw the required hexes. This all still however pretty scetchy for my right now. Anyone have any idea ? Thanks for your help Peter
essentially, this is what you need to do:

A) detect which hex the upper left corner of the view area is on.

B) draw a row of tiles (pick a number that is guaranteed to span the width of the view area.. having one or two extra wont hurt, but having too many will)

C) from the beginning of that row, move down a row, alternately moving SW then SE for even/odd rows, and continue drawing rows of tiles until you have drawn as many rows as will fit. again, having one or two extra rows wont hurt, when compared to redrawing the entire map.

Get off my lawn!

Advertisement
TANSTAAFL thanks ! I''m looking forward to the Long weekend starting tomorrow

Peter

PS: I''m looking forward to your book.

This topic is closed to new replies.

Advertisement