Comments (4)
I also ran into this issue. Collision detections fail when delta.x == 0
or delta.y = 0
. If they are non-zero then everything works perfectly.
The work-around is to set the near and far values to infinity in such cases. This can lead to false-positives ("ghost collisions") so you also need to add a broad-phase check.
Unfortunately @mreinstein's fix did not work for me; I think some edge-cases are missing.
I got things working in my own code-base. Here is a snippet, which isn't compatible with this repo, but hopefully gives the idea:
// ....
if delta.X = 0.0f
then
xEntry <- Single.NegativeInfinity
xExit <- Single.PositiveInfinity
else
xEntry <- xInvEntry / delta.X
xExit <- xInvExit / delta.X
if delta.Y = 0.0f
then
yEntry <- Single.NegativeInfinity
yExit <- Single.PositiveInfinity
else
yEntry <- yInvEntry / delta.Y
yExit <- yInvExit / delta.Y
// ...
Note the +
and -
infinity, the difference is important due to comparison checks later.
And this is the extra broad-phase check that removes ghost collisions:
let computeBroadphaseBox (delta : Vector2) (box : AABB) =
// TODO: Make this more efficient
let nextBox = { box with Center = box.Center + delta }
let l = min (AABB.left box) (AABB.left nextBox)
let r = max (AABB.right box) (AABB.right nextBox)
let t = min (AABB.top box) (AABB.top nextBox)
let b = max (AABB.bottom box) (AABB.bottom nextBox)
{
Center = box.Center + delta * 0.5f
HalfSize = Vector2.create (r - l) (b - t) * 0.5f
}
let sweepAABBWithBroadphase (dynamicBox : AABB) (staticBox : AABB) (delta : Vector2) : SweepResult option =
let broadphaseBox = computeBroadphaseBox delta dynamicBox
if aabbCheck broadphaseBox staticBox
then
sweepAABB dynamicBox staticBox delta
else
None
from intersect.
@noonat I hate to be a pest but, any thoughts on this?
from intersect.
@noonat I figured out the problem. It's possible for nearTimeY
to get set to NaN
when we attempt to multiply 0 * Infinity
(results in NaN
)
the fix in #10 is pretty simple, we just check to see if nearTimeY
is set to NaN
, and if so set it to Infinity
I also added a unit test to reproduce this problem.
from intersect.
Unfortunately @mreinstein's fix did not work for me; I think some edge-cases are missing.
I got things working in my own code-base. Here is a snippet, which isn't compatible with this repo
@njlr thanks for providing more details! ❤️
It would be helpful if you can submit test(s) that demonstrate what other broken cases you've discovered, using the actual API that intersect
provides. That makes it possible to develop an actionable solution.
The work-around is to set the near and far values to infinity in such cases.
This can lead to false-positives ("ghost collisions")
That makes me a little nervous, because It sounds like this workaround is trading one problem for another. A broadphase collision check shouldn't be required to filter out bad results, that doesn't feel right to me.
from intersect.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intersect.