Thursday, August 2, 2018

2d top-down map: normalisation or not?


I am an absolute beginner with game programming, should this question be poorly formulated, be aware it was not sloppiness by my side, but lack of game programming experience.


The game I am planning to code will use a top-down 2D map as "world". The world might be larger than the window (the window can zoom in or out) and the vehicles can be located at any point of the world (= it's not a tiled map, the space is "continuous").


To clarify with an example: if the world is a terrain of 1000x1000 metres, a vehicle could be at location (327.31, 720.4) metres.



My question is: what is the most convenient way to represent the world internally? I could think to these possibilities:



  • do nothing and use metres as if I were working with the physical object,

  • normalise to pixels defining the world size as the number of pixels for representing 1000 metres at maximum zoom,

  • normalise to 1 defining the word as a square of size 1


...but I am sure there might be some other ones / some of mine could make no sense. It's just that being my first game I don't have a clear pictures of the problems ahead of me, and I would like some guidance in making a reasonably correct initial choice.


Thank you for your time.



Answer



I agree with using a real-world value (meters, feet, etc.) as your basis for distance. The problem with your other two suggestions is that they are both variables. Working with a world size of 1 will cause all of your arithmetic to be floating-point between -1 and 1, which may lead to more floating-point errors. Also, should you ever decide to make variable world sizes ("Large" worlds for longer games, etc.) you will introduce many problems to your code. Likewise, if you use pixels, even at a maximum/minimum zoom level, you will run into confusion as well as problems should you decide to increase or decrease zoom levels.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...