-
-
Notifications
You must be signed in to change notification settings - Fork 899
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
feat: Add Ray2
class to be used in raytracing/casting
#1788
Conversation
Nit: in the title capitalize Ray2 |
Ray2
class to be used in raytracing/casting
return t1; | ||
} | ||
return null; | ||
} |
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.
This method should probably need to be tested too. In particular, I'm not sure whether the sign of t1
is correct.
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.
Added some simple tests for it, please have a look to see whether they are testing what you were wondering about.
Co-authored-by: Pasha Stetsenko <stpasha@google.com>
Hmm, seems like something is still off with |
Nvm me, it was just the direction inverse that wasn't properly updated when a |
/// [LineSegment] or null if there is no intersection. | ||
/// | ||
/// A ray that is parallel and overlapping with the [segment] is considered to | ||
/// not intersect. |
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 wonder if we can handle this edge case better? For example, adding if (dot == 0) { ... }
.
Or was this a deliberate choice?
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.
That would be nice, what should we return in that case though, would t1
still be a valid point on the line segment?
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.
Ah, obviously it can't return t1
since that would be having a division by zero.
I'll try around a bit, if you have a good idea of how it can be done I'm all ears.
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.
What do you think about the solution that I pushed now?
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.
Hmm, maybe it makes sense that it doesn't collide with parallel rays, because it will always collide with one of the line segments connecting to it anyways?
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 guess it makes sense, esp since the intersection in this case is not a single point but rather a segment, so returning a single point would be wrong.
But we should probably explain this in a comment, because I suspect we'll soon forget what the reason was.
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.
Good idea, I added that in #1785
final dot = _v2.dot(_v3); | ||
|
||
if (dot == 0) { | ||
// ray is parallel to line |
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.
Sorry I'm on the phone rn, but I'd do smth like this here:
- Let dot2=v1.dot(v3). Then if dot2!=0 there's no intersection and we can return null.
- Otherwise, let t1=direction.dot(segment.from-ray.origin) and t2=direction.dot(segment.to-ray.origin). (These can be expressed in terms of v1 and v2). Then if both t1 and t2 positive, return the min of them; if both negative return null; otherwise, return 0 because the Ray's origin is inside the segment.
This ensures that we return a point closest to Ray's origin, and correctly handle the case when ray and segment are on parallel lines.
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.
Hmm, maybe it makes sense that it doesn't collide with parallel rays, because it will always collide with one of the line segments connecting to it anyways? I'll remove it again for now and then we can re-add it again later if we choose to.
Description
Introduces the
Ray2
class which later will be used to see whether a ray intersects a hitbox.Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change
Related Issues