Title: Unexpected Y-axis translation when using `ortho()` and `resetMatrix()` · Issue #891 · processing/processing4 · GitHub
Open Graph Title: Unexpected Y-axis translation when using `ortho()` and `resetMatrix()` · Issue #891 · processing/processing4
X Title: Unexpected Y-axis translation when using `ortho()` and `resetMatrix()` · Issue #891 · processing/processing4
Description: NoteThis 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 clear...
Open Graph Description: NoteThis 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...
X Description: NoteThis 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...
Opengraph URL: https://github.com/processing/processing4/issues/891
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected Y-axis translation when using `ortho()` and `resetMatrix()`","articleBody":"\u003e [!NOTE]\r\n\u003e This issue is a repost of https://github.com/processing/processing/issues/6175 by @usuallyannoyed, updated and edited for tone and clarity.\r\n\r\n## Description \r\nThe `ortho()` function does not behave as expected. \r\n\r\n## Expected Behavior \r\n`ortho(0, width, 0, height)` with a cleared modelview matrix (`resetMatrix`) should allow users to draw within the specified bounds (e.g., `0` to `width` on the x-axis and `0` to `height` on the y-axis). \r\n\r\n## Current Behavior \r\nInstead, 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. \r\n\r\n## Steps to Reproduce \r\n```Processing\r\nvoid setup() {\r\n size(500, 500, P3D);\r\n}\r\n\r\nvoid draw() {\r\n ortho(0, width, 0, height);\r\n resetMatrix(); // clear modelview matrix\r\n fill(255);\r\n \r\n // Uncomment the line below to 'fix' the behavior\r\n // translate(0, -height); \r\n \r\n beginShape(TRIANGLES);\r\n vertex(640, 640);\r\n vertex(0, 640);\r\n vertex(0, 0);\r\n endShape();\r\n}\r\n``` \r\n\r\n### Observed Result \r\nThe triangle only becomes visible when compensating for the unexpected offset by translating the y-axis. \r\n\r\n### Expected Result \r\nThe triangle should appear within the specified `ortho` bounds without additional transformations. \r\n\r\n## Environment \r\n- **Operating System**: macOS 13.4 \r\n- **Processing Version**: 4.3.1 \r\n\r\n## Possible Causes / Solutions \r\nThe issue appears to stem from the following block of code in the Processing source: \r\n\r\nhttps://github.com/processing/processing4/blob/937f528c1638fa96bc8fde5a67483dad9de8b5c9/core/src/processing/opengl/PGraphicsOpenGL.java#L4482-L4486\r\n\r\nDespite 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. \r\n\r\n### Suggested Fix \r\nTo 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: \r\n\r\n```java\r\n// Add a pre-multiplied -1 y scale to flip the y axis in NDC.\r\n projection.set(x, 0, 0, tx,\r\n 0, -y, 0, -ty,\r\n 0, 0, z, tz,\r\n 0, 0, 0, 1);\r\n``` \r\n\r\nThis approach ensures the y-axis behaves as expected without requiring additional transformations. \r\n\r\n### Additional comments\r\nThis 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.","author":{"url":"https://github.com/SableRaf","@type":"Person","name":"SableRaf"},"datePublished":"2024-12-17T20:59:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/891/processing4/issues/891"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7d31406f-0158-c866-6379-0c652ddeb2c2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A08E:FE603:F8DBF6:143F392:696B0F11 |
| html-safe-nonce | a9f3d59e264806ecb1e010958bfc6c9843fed3f937a1534f4d1551fcff7bd72b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDhFOkZFNjAzOkY4REJGNjoxNDNGMzkyOjY5NkIwRjExIiwidmlzaXRvcl9pZCI6IjkyMTIyNTExMDEyNzg3MDMzNzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c718b04f104b35b77950c974bef8c0f8b2effed0667e4266445c49b52f1a851b |
| hovercard-subject-tag | issue:2746045363 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/processing/processing4/891/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d62527d602a7fe21b099a3ef5c4a83120d304e810889c5a1d21aa311439a0762/processing/processing4/issues/891 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d62527d602a7fe21b099a3ef5c4a83120d304e810889c5a1d21aa311439a0762/processing/processing4/issues/891 |
| og:image:alt | NoteThis 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SableRaf |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/processing/processing4 git https://github.com/processing/processing4.git |
| octolytics-dimension-user_id | 1617169 |
| octolytics-dimension-user_login | processing |
| octolytics-dimension-repository_id | 844382769 |
| octolytics-dimension-repository_nwo | processing/processing4 |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 844382769 |
| octolytics-dimension-repository_network_root_nwo | processing/processing4 |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width