Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add intersects_ray() method to OpenXRCompositionLayer #90286

Conversation

dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Apr 6, 2024

This is a follow-up to PR #89880

As discussed on this comment, since these composition layers are most likely going to be used for UI, developers will want to cast a ray and get the collision point. And given that two of the layer types (cylinder and equirect) are curved and all can be rotated and moved around, developers aren't going to want to independently figure out the math for that. :-)

So, this PR adds OpenXRCompositionLayer::intersects_ray() which returns UV coordinates where the ray intersects.

The main thing I'm unsure about is that its returns Vector2(-1.0, -1.0) in the case that there is no collision. An alternative would be to change the return type to Variant so we can return Vector2 when there is an intersection and null when there isn't, but that would make it impossible to use proper type hints. I'm not sure which alternative is better, but I have a slight preference for the former, so that's the one I went with.

Here is a test project (doesn't include the 'godot_openxr_vendors' plugin - you'll need to download that yourself):

openxr_composition_layer_test.zip

@dsnopek dsnopek added this to the 4.3 milestone Apr 6, 2024
@dsnopek dsnopek requested review from m4gr3d, Malcolmnixon, BastiaanOlij and a team April 6, 2024 01:25
Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just need to make sure it works in global space.

Also needs a simple demo/test project. Just a simple XR sample that has all 3 composition layers, with a bit of code that uses the UV here to send mouse events/touch events to the viewport so we can verify the obtained UVs are correct.

Coincidentally, I just did that on stream yesterday and remembering the v needed to be 1.0 - v, which may apply here.

modules/openxr/doc_classes/OpenXRCompositionLayer.xml Outdated Show resolved Hide resolved
modules/openxr/scene/openxr_composition_layer_cylinder.cpp Outdated Show resolved Hide resolved
modules/openxr/scene/openxr_composition_layer_equirect.cpp Outdated Show resolved Hide resolved
modules/openxr/scene/openxr_composition_layer_quad.cpp Outdated Show resolved Hide resolved
@dsnopek
Copy link
Contributor Author

dsnopek commented Apr 6, 2024

Looks good, just need to make sure it works in global space.

Since both XRController3D and XRCompositionLayer need to be children of XROrigin3D, I was doing this in XROrigin3D-space. But I think you're right that doing it all in global space would be better.

I'll update the PR and share my demo project soon!

@dsnopek dsnopek force-pushed the openxr-composition-layers-intersects-ray branch from 9dffa90 to 025f2b8 Compare April 6, 2024 13:37
@dsnopek
Copy link
Contributor Author

dsnopek commented Apr 6, 2024

@BastiaanOlij Thanks for the review!

I've made the requested changes and added a demo project to the PR description above.

@BastiaanOlij
Copy link
Contributor

Since both XRController3D and XRCompositionLayer need to be children of XROrigin3D, I was doing this in XROrigin3D-space. But I think you're right that doing it all in global space would be better.

That would probably be true 99% of the time, but just wait for the one person who puts a screen on a moving platform... :)

Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with all the changes :)

@akien-mga akien-mga merged commit ad19934 into godotengine:master Apr 8, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@dsnopek dsnopek deleted the openxr-composition-layers-intersects-ray branch July 22, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants