757
Stop using floats (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] gandalf_der_12te@feddit.de 3 points 8 months ago

IMO, floats model real observations.

And since there is no precision in nature, there shouldn't be precision in floats either.

So their odd behavior is actually entirely justified. This is why I can accept them.

[-] jabjoe@feddit.uk 2 points 8 months ago

I just gave up fighting. There is no system that is going to both fast and infinitely precision.

So long ago I worked in a game middleware company. One of the most common problems was skinning in local space vs global space. We kept having customers try and have global skinning and massive worlds, then upset by geometry distortion when miles away from the origin.

[-] swordsmanluke@programming.dev 1 points 8 months ago

How do y'all solve that, out of curiosity?

I'm a hobbyist game dev and when I was playing with large map generation I ended up breaking the world into a hierarchy of map sections. Tiles in a chunk were locally mapped using floats within comfortable boundaries. But when addressing portions of the map, my global coordinates included the chunk coords as an extra pair.

So an object's location in the 2D world map might be ((122, 45), (12.522, 66.992)), where the first elements are the map chunk location and the last two are the precise "offset" coordinates within that chunk.

It wasn't the most elegant to work with, but I was still able to generate an essentially limitless map without floating point errors poking holes in my tiling.

I've always been curious how that gets done in real game dev though. if you don't mind sharing, I'd love to learn!

[-] jabjoe@feddit.uk 2 points 8 months ago

That's pretty neat. Game streaming isn't that different. It basically loads the adjacent scene blocks ready for you to wonder in that direction. Some load in LOD (Level Of Detail) versions of the scene blocks so you can see into the distance. The further away, the lower the LOD of course. Also, you shouldn't really keep the same origin, or you will hit the distort geometry issue. Have the origin as the centre of tha current block.

this post was submitted on 26 Feb 2024
757 points (95.8% liked)

Programmer Humor

19589 readers
431 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS