Resolve Issue With OrthographicCamera WorldToScreen and ScreenToWorld transitions when using a non-zero positioned viewport #1055
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes coordinate transformation methods (
WorldToScreenandScreenToWorld) inOrthographicCamerato correctly handle viewport offsets based on the viewport adapter type. The previous implementation unconditionally applied viewport offset adjustments, which caused incorrect transformations when using non-scaling viewport adapters likeDefaultViewportAdapter.The root cause was that mouse input from
MouseStateis always in window coordinates. For non-scaling adapters, window coordinates map 1:1 to virtual coordinates, so viewport offset should not affect the transformation. For scaling adapters, the viewport offset defines where the scaled virtual coordinate system is positioned within the window, requiring offset adjustment before scale transformation.Related Issues/Tickets
Changes Made
Bug Fix:
WorldToScreenandScreenToWorldinOrthographicCamerato conditionally apply viewport offset adjustments only forScalingViewportAdapter(and its subclasses likeBoxingViewportAdapter)DefaultViewportAdapterand other non-scaling adapters, viewport offset is now correctly ignored as it represents only the rendering position, not a coordinate transformationScalingViewportAdapter, viewport offset is properly applied to convert between window coordinates and viewport coordinates before scale transformationsTest Coverage:
ScreenToWorld_WithNonZeroViewportOrigin_TransformsCorrectlyto verify behavior with non-zero viewport originsWorldToScreen_RoundTrip_WithNonZeroViewportOrigin_ReturnsOriginalPositionto ensure round-trip consistencyScreenToWorld_WithBoxingViewportAdapter_TransformsCorrectlyto verify correct behavior with scaling viewport adaptersWorldToScreen_RoundTrip_WithBoxingViewportAdapter_ReturnsOriginalPositionto ensure round-trip consistency with boxing adaptersChecklist
Please read and check the following items. Pull requests will not be reviewed if all items are not checked.