Translating between cartesian and screen coordinates

前端 未结 5 537
清歌不尽
清歌不尽 2020-12-28 18:42

For my game I need functions to translate between two coordinate systems. Well it\'s mainly math question but what I need is the C++ code to do it and a bit of explanation h

5条回答
  •  别那么骄傲
    2020-12-28 19:19

    You need to know the width and height of the screen.

    Then you can do:

    cartX =   screenX - (width / 2);
    cartY = -(screenY - (height / 2));
    

    And:

    screenX =  cartX + (width / 2);
    screenY = -cartY + (height / 2);
    

提交回复
热议问题