For my game, I need functions to translate between two coordinate systems. Well, this is basically a math question, but I need C ++ code for this and a bit of explanation on how to solve my problem.
Screen coordinates:
a) upper left corner 0,0
b) no negative values
c) right + = x (the larger the value of x, the greater the point on the right)
d) bottom + = y
Cartesian 2D coordinates:
a) midpoint (0, 0)
b) there are minus values
c) right + = x
d) bottom - = y (the less y, the more at the lower point)
I need a simple way to transfer from one system to another and vice versa. For this (I think) I need some knowledge, for example, where is (0, 0) [the upper left corner in the coordinates of the screen] located in Cartesian coordinates.
However, there is a problem that for a certain point in Cartesian coordinates, after translating it into screen coordinates, the position in the screen coordinates may be minus, which is nonsense. I can’t put the top left corner of the screen coordinate in (-inifity, + infinity) Cartesian coordinates ...
How can i solve this? The only solution I can think of is to place the screen (0, 0) in a Cartesian (0, 0) and use only a quarter of the Cartesian system, but in this case using a Cartesian system is pointless ...
I am sure that there are ways to translate the screen coordinates into Cartesian coordinates and vice versa, but I'm doing something wrong in my thoughts with these minus values.
c ++ math algorithm coordinates coordinate-systems
user1873947
source share