Unexpected Y-axis translation when using ortho()
and resetMatrix()
#891
Labels
bug
Something isn't working
ortho()
and resetMatrix()
#891
Note
This issue is a repost of processing/processing#6175 by @usuallyannoyed, updated and edited for tone and clarity.
Description
The
ortho()
function does not behave as expected.Expected Behavior
ortho(0, width, 0, height)
with a cleared modelview matrix (resetMatrix
) should allow users to draw within the specified bounds (e.g.,0
towidth
on the x-axis and0
toheight
on the y-axis).Current Behavior
Instead, the drawing area behaves incorrectly, requiring adjustments (e.g., translating
-height
on the y-axis) to achieve the expected results. This behavior makes it unintuitive for users who expect the specified bounds to align with the visible viewport.Steps to Reproduce
Observed Result
The triangle only becomes visible when compensating for the unexpected offset by translating the y-axis.
Expected Result
The triangle should appear within the specified
ortho
bounds without additional transformations.Environment
Possible Causes / Solutions
The issue appears to stem from the following block of code in the Processing source:
processing4/core/src/processing/opengl/PGraphicsOpenGL.java
Lines 4482 to 4486 in 937f528
Despite the comment saying that
The minus sign is needed to invert the Y axis.
, this implementation does not fully invert the y-axis as intended. Instead, it flips the y-axis around zero, resulting in all the y-coordinates being offset into negative space.Suggested Fix
To invert the y-axis properly in normalized device coordinates (NDC), pre-multiply the projection matrix with a
-1
scale for the y-axis. This can be achieved by modifying the projection matrix calculation as follows:This approach ensures the y-axis behaves as expected without requiring additional transformations.
Additional comments
This behavior stems from Processing's choice to have the Y-axis increase downward, consistent with traditional computer graphics. While reasonable, the implementation relies on ad-hoc adjustments throughout the code. Centralizing it at a lower level (NDC or viewport) and exposing it as an optional flag would provide more clarity and flexibility.
The text was updated successfully, but these errors were encountered: