Dealing with the XY origin coordinate issue when coding (in high level lang)

Discussion in 'Technical Discussion' started by 0xfedbeef, Jan 4, 2020.

  1. 0xfadec0de

    0xfadec0de

    Previously 0xfedbeef Member
    6
    1
    1
    I have tried to coding a Mario 3 clone (and would love to do a Sonic game) in Java, or maybe C++. However, using Java's AWT & Javax.swing, the coordinate is at the top-left of the viewport. That blocked the entire project, as I could not think of a way to make it so the origin is at Cartesian 0,0. My attempt to handle it resulted in problems w/ sprite locations given that some sprites are different heights.

    What tactics could people suggest as a workaround or alternative (provided it's free)?
     
  2. Billy

    Billy

    RIP Oderus Urungus Member
    1,879
    12
    18
    Colorado, USA
    Indie games
    You could always write methods that convert to/from the two coordinate systems. Or, because it sounds like you're not doing so, drop in a library focused around writing games.
     
  3. 0xfadec0de

    0xfadec0de

    Previously 0xfedbeef Member
    6
    1
    1
    I tried to think of a method that would do that; I couldn't think of one bc it would have to alter AWT/Javax's functionality (or so I thought). Is there a good library you might recommend?
     
  4. MarkeyJester

    MarkeyJester

    ♡ ! Resident Jester
    While in mathematics, it is customary for the ordinate (Y axis) to be positive up and negative down, TV monitors using cathode ray tubes tend to be rendered in reverse of this principle whereby the ordinate is positive down and negative up. This might have been influenced by the way us as humans read text which mostly (if not always) is from top to bottom. While some monitors might have rendered in reverse, or even in some cases the ordinate and abscissa (X axis) are swapped where the rendering is left to right (I believe some arcade machines have used this method), it's mostly the top to bottom method used.

    Because of this, some of the earliest software for rendering direct to the display needs careful timing and the calculations need to be fast. Rather than having to negate or recalculate the ordinate position in real-time, it just made sense to have everything calculated in parallel to the screen, and have the data constructed in the same ordered direction. After video hardware took over the display role from the CPU, the principles of top to bottom were kept.

    One exception might be IBM where according to this:

    So they wanted to keep the classical mathematical representation and have everything render from bottom to top, but top to bottom was still in use by the majority. This is of course until 3D rendering became prevalent, and the ordinate axis became positive up again, but since the 3D environment needs to be recalculated into a 2D display, and because the ordinate axis can render in any direction (not just up now), it really didn't matter that it conflicted with the rendering of the display.

    With that in mind, I would like to suggest using 3D rendering, and render quads (or two triangles) for your display/sprites, up is always positive in a 3D environment, though, you may have to work with floating point as opposed to a fixed point integer, but it sounds to me like the polarity of the ordinate axis is likely more of a problem for you than working with floating point.