-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Split Ray
into Ray2d
and Ray3d
and simplify plane construction
#10856
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the split: more consistent and efficient.
I think these From
impls should be cut though.
I removed the |
I updated the PR to match the direction constructor changes. I opted to make the If the changes look fine, everything should now be ready :) |
How common is it to convert between Ray2 to Ray3? Do we need helper methods for that like glam's |
I don't think it's particularly common, but it'd be nice to have. It would also make sense to implement for other types, like planes, lines, line segments and even rectangle/cuboid. But extending/truncating rays would also require extending/truncating directions, which is probably out of scope for this PR. |
Objective
A better alternative version of #10843.
Currently, Bevy has a single
Ray
struct for 3D. To allow better interoperability with Bevy's primitive shapes (#10572) and some third party crates (that handle e.g. spatial queries), it would be very useful to have separate versions for 2D and 3D respectively.Solution
Separate
Ray
intoRay2d
andRay3d
. These new structs also take advantage of the new primitives by usingDirection2d
/Direction3d
for the direction:and by using
Plane2d
/Plane3d
inintersect_plane
:Changelog
Added
Ray2d
andRay3d
Ray2d::new
andRay3d::new
constructorsPlane2d::new
andPlane3d::new
constructorsRemoved
Ray
in favor ofRay3d
Changed
direction
is now aDirection2d
/Direction3d
instead of a vector, which provides guaranteed normalizationintersect_plane
now takes aPlane2d
/Plane3d
instead of just a vector for the plane normalDirection2d
andDirection3d
now deriveSerialize
andDeserialize
to preserve ray (de)serializationMigration Guide
Ray
has been renamed toRay3d
.Ray creation
Before:
After:
Plane intersections
Before:
After: