Forum Logo

A lesson in overcomplicating stuff.

D
#1•7y ago•59,174 posts

So I'm playing around with an idea for a game. For it, I needed a hexagonal map coordinate system. So playing around in Inkscape, I drafted up this:

The hexagon is broken into triangles and each point of every triangle has a simple column, row coordinate. However because in a hexagonal map, the points don't like up neatly like boxes do in a regular coordinate system, you can see that the columns in my system actually line up on a forward leaning angle.

So anyway, to start with I just coded it without worrying about translating between my coordinate system and the screen coordinates and just rendered some data. This was the result and was what I expected:

Ok. So now the fun part. How do I get it to show the hexagons properly translated into x,y coordinates? Now I left high school at 15 but I'm not afraid to try some "advanced" math and I started googling basic trigonometric functions.

This is what I was doing:

This is what I imagined I was doing:

This is the result I was getting:

So I just kept throwing more math and code at it. This what my program was starting to look like:

Finally, I was just about ready to give up, when I took one more look at the original non-translated result:

And I thought, hang on. The rows don't need to change at all. The columns above row zero need to slide to the right. The columns below zero slide to the left. The further away from row zero, the more they slide. And then I replaced all my junk math/code with this:

And hey, fucking presto! I now get this:

7
Liked:
Pakoon
Gators1
Wingmann
Tazz
tigger
eWildcat
Kilemall
Tazz
#2•7y ago•70,432 posts

I have no idea what to say but it looks cool.

My video card can handle 3 Million fully featured triangles/sec (Filtered, LOD MIP-mapped, Z-buffered, alpha-blended, fogging enabled, textured triangles) so it should work.

0
Wingmann
#3•7y ago•7,858 posts
@tazzsaidin@tazz

My video card can handle 3 Million fully featured triangles/sec (Filtered, LOD MIP-mapped, Z-buffered, alpha-blended, fogging enabled, textured triangles) so it should work.

And that's a raw card. Now imagine you put it in the oven for a while...

10
Liked:
Lithu
Pakoon
Gators1
Tazz
tigger
eWildcat
Kilemall
Jam
TheMouse
Lob12
Lob12
#4•7y ago•25,232 posts

What is dead may never die!

0
Kilemall
#5•7y ago•35,803 posts

The usual wargaming coordinate system is by hex column then effectively 'row', counting down.

So this example-

https://i.imgur.com/ugJPJae.png

The leftmost hex would be 0101, a hex below it would be 0102, the next column over would be 0201/0202/0203 etc.

So any coordinate system I would put in for the points in between would describe a specific interface point. I think I would use which hexes touch on it, with map edge N S E or W describing any point not connecting to two or more hexes.

So the leftmost hex would have the centerpoint be 0101, then assuming a 0102 hex below and going from upper left around the edge, 0101-N, 0101-0201, 0101-0201-0202, 0101-0202, 0101-0102-0202, 0101-0102, and 0101-W.

0
D
#6•7y ago•59,174 posts

@kilemall Yeah I've muddled some concepts in my post. It's actually not a hex tile cooridinate system at all. In fact the hexagons are just a kind of artifact of the node/edges/triangles. The nodes (0,1), (0,2) etc are "places" in the world. The edges between the nodes are possible travel paths. The only time the user would see the hexagon is around themselves showing their immediate area of influence and the paths (edges) they can travel. They don't move from hex tile to hex tile, they move from node to node which is kind of a half hexagon step that leaves them on a new hexagon which overlaps with the one they came from if that makes sense. Not sure if it will all work out in the end but it's been a fun little programming challenge.

0
TheMouse
#7•7y ago•7,279 posts

I'm thinking.....at some point...somebody must have made a hex coordinate wumpus cave system.. or other game have you googled, just a thought

0
1 day later
D
#8•7y ago•59,174 posts

Just a postscript for those of you who had been maybe subconsciously bothered by the shape of my hexagons like I had: I implemented map rotation in my app today and the shape of the hexagons was even more obviously wrong. The hex's looked more like tie fighter wings than regular hexagons. So I finally bothered to measure the sides and they were indeed irregular. I played around with it until I discovered that multiplying the row by 0.88 when producing the y value gave me pretty close to a perfect hexagon. I had named this magic number, 0.88, as Hog's Constant and fully expected that one day I'd write an award winning paper on it. But then I remembered reading somewhere about the square root of 3 over 2 being an important ratio in hexagons and sure enough, it was pretty close to Hog's Constant so I'm using that instead. Updated code:

Updated results:

5
Liked:
Pakoon
Gators1
Wingmann
Tazz
Jam
Tazz
#9•7y ago•70,432 posts
1
Liked:
Kilemall
Pakoon
#10•7y ago•40,546 posts

I don't see any hexagons. I see only triangles.

1
Liked:
Kilemall
Stu
#11•7y ago•8,923 posts
@pakoonsaidin@pakoon

I don't see any hexagons. I see only triangles.

That's because of The Pentagon.

0
D
#12•7y ago•59,174 posts

I need to work out how to make a living as an indie game dev. It's too much fun.

After writing this little test prog that renders sine waves in 3d, I finally understand understand the sine function. I'd previously only ever used it in finding lengths in triangles.

2
Liked:
tigger
eWildcat
Tazz
#13•7y ago•70,432 posts

@hog cool !! My first intro to computers was with a Tandy CoCo2 which ran on the Basic language. Programs and files were saved on a cassette tape. Small programs were found in PC magazines, some were a full page of code, and one was this sin wave similar to what you have. I named the file "3hours" because that's how long it took to render that same pic.

1
Liked:
Gators1
Kilemall
#14•7y ago•35,803 posts
@tazzsaidin@tazz

@hog cool !! My first intro to computers was with a Tandy CoCo2 which ran on the Basic language. Programs and files were saved on a cassette tape. Small programs were found in PC magazines, some were a full page of code, and one was this sin wave similar to what you have. I named the file "3hours" because that's how long it took to render that same pic.

Damn kids got no idea how good they got it! We had to code through blizzards walking uphill both ways while holding onto our punch cards! And we liked it that way!

My first playtime with computers, not counting the various 70s pong games hooked up to the family TV, was running Trek games at high school on the local keyboard/terminal with no monitor, printer display only, where it was hooked up to a Dallas area educational computer service called Region 10. It still exists. https://www.region10.org/

First work computer was a 1MB NCR mainframe. We had 640K assignable memory in partitions (so we could multiprogram, sorta, more like run 6 virtual machines). B2 online system and B3 batch. I never got my hands on the hot stuff, VRX, but I saw the election machine in Austin during a job interview.

http://www.thecorememory.com/html/ncr_criterion_series.html

So ya, all those morons that think virtual servers are so cool and clever and grandpa mainframe can't do stuff- mainframes been there done that from literally the first days.

Damn punks.

1
Liked:
Tazz
D
#15•7y ago•59,174 posts

@tazz Ha. Yeah I started on a similar machine. I learned my first programming in Basic by working through the manual that came with the computer. It was an unknown brand re-badged for the Aussie market but it was a z-80 based machine with cassette storage and a basic interpreter. My monochrome monitor was orange which I think in retrospect might have been unusual. I think a lot of them back then were green screens (or black and white.)

I owe a lot to my Dad for buying his 11 year old kid that computer. I probably would never have ended up with a career in programming if it weren't for that first exposure which wasn't all that common back then.

1
Liked:
Tazz
Lithu
LithuADMIN
#16•7y ago•25,710 posts

Just wondering, do you ever use React versus JS?

0
TheMouse
#17•7y ago•7,279 posts
@pakoonsaidin@pakoon

I don't see any hexagons. I see only triangles.

I see cubes

0
TheMouse
#18•7y ago•7,279 posts
@tazzsaidin@tazz

@hog cool !! My first intro to computers was with a Tandy CoCo2 which ran on the Basic language. Programs and files were saved on a cassette tape. Small programs were found in PC magazines, some were a full page of code, and one was this sin wave similar to what you have. I named the file "3hours" because that's how long it took to render that same pic.

Mine was an 8k commodore PET https://i.ytimg.com/vi/YZyaeB1K31w/maxresdefault.jpg

8k LOL the fucking kettle's probably got more than 8k of ram these days

2
Liked:
Gators1
Tazz
D
#19•7y ago•59,174 posts
@lithusaidin@lithu

Just wondering, do you ever use React versus JS?

It's very popular for web apps but I tried it a couple of years ago and I don't like it much myself. It's still JS, just a framework for building web apps.

(Reasons I didn't like it are just taste - you either write components in JSX which embeds HTML inside JS (urgh) or using a class-like syntax which I found too verbose. I use VueJs myself which is a very similar framework but I find much much more elegant.)

0
2 weeks later
D
#20•7y ago•59,174 posts

A few weeks ago before my vacation I had an idea for terrain generation using sine waves. I built a test app for modelling sine waves and their constructive/destructive interference. Turns out my original idea isn't going to work so it's almost totally pointless now but I polished up the test app a little and published it here if anyone is a sine wave enthusiast and wants to try it (hey, maybe sine wave groupies are a thing like rail foamers etc):

https://proehlen.github.io/3d-sine-waves/

Some example renderings from the above app:

2 images
1 / 2

Edit: Oh, and it's as slow as hell to load the first time - there's something screwed up with my webpack build. I spent half a day on it but couldn't get it fixed and it's not profitable for me to spend any more time on it right now so I'm leaving it as is.

0