noonat / intersect Goto Github PK
View Code? Open in Web Editor NEWAn explanation of 2D collision tests in JavaScript
Home Page: http://noonat.github.io/intersect/
License: zlib License
An explanation of 2D collision tests in JavaScript
Home Page: http://noonat.github.io/intersect/
License: zlib License
I think it would be helpful for there to be an additional section for the intersection of AABBs and circles.
I'm currently following this tutorial in hopes of accurately recreating it in Lua. However, immediately starting from the AABB vs Point section, I had issues with the coordinate system.
The point would be detected when it shouldn't, wouldn't be when it should, hit values aren't accurate, etc.
So I ask, what exactly is the coordinate system used here? Is it based on the center? The top-left?
I'm guessing the latter since this is likely used with canvas, but I have issues there, too.
I think the easiest way for me to debug this is to ask: how did you create the visualization in the AABB vs Point section? If I can know that, I'd be able to debug it, I think.
Thanks for the great tutorial!
I've been using this library for years, it's amazing! Today while looking through the commit history of this project, I noticed there is one change made that actually has to do with intersection test changes: a67d18c
The commit message is fix hit delta calculations
, but looking at the changes it's unclear to me what bug is being resolved. Could you clarify this one change please?
Thanks again for an amazing resource!
The annotated source says "If the sweep isn’t actually moving anywhere, just do a static test. It’s faster and will give us a better result for that case."
and then the code goes on to show:
if delta.x == 0 and delta.y == 0
sweep.pos.x = box.pos.x
sweep.pos.y = box.pos.y
sweep.hit = this.intersectAABB(box)
if sweep.hit?
sweep.time = sweep.hit.time = 0
else
sweep.time = 1
Shouldn't sweep.pos.x = box.pos.x actually be sweep.pos.x = this.pos.x? If the object isn't moving, why would the position be the object you are colliding with?
(BTW, this has been a great resource! I've ported it more or less directly to a single C header file along with the tests: https://github.com/sponge/sdlgame/blob/master/src/sweep.h it mostly seems to be working besides a couple of weird edge cases that I'm not sure are my fault or are present in the original. I won't make any claims about how good my C is, though!)
I was looking at your article all day long and found it again, so happy ;) thx
my setup data:
pos = new Point(907.5, 318.5)
half = new Point(7.5, 17.5)
myAabb = new AABB(pos, half)
start = new Point(531, 301)
delta = new Point(16, 0)
result = myAabb.intersectSegment(start, delta)
console.log('result:', result)
/*
prints:
result: Hit {
collider: AABB {
pos: Point { x: 907.5, y: 318.5 },
half: Point { x: 7.5, y: 17.5 }
},
pos: Point { x: NaN, y: NaN },
delta: Point { x: NaN, y: NaN },
normal: Point { x: 0, y: -1 },
time: NaN
}
*/
Any ideas what's going on here? When I look at the internal implementation I see nearTimeY
is being set to NaN
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.