|
|
This thread is locked; no one can reply to it.
|
1
2
|
| I'm Just so Close (more Physics) |
|
Stas B.
Member #9,615
March 2008
|
I have a ready static implementation of SAT.
|
|
Anomie
Member #9,403
January 2008
|
Could I bother you for a few comments? like... ______________ |
|
Stas B.
Member #9,615
March 2008
|
Umm... You know how projection works, right? What I do there is to basically smash a polygon against an axis. I project every point using the dot product, and the result of the dot product is some value... Now, I find the minimum and maximum and that's the interval of the polygon on an axis. (The 'x' there is the minimum, the 'y' is the maximum. That's stupid, I know. {"name":"satgb8.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/f\/4f0defde056eec6feb1c754cf233dea3.png","w":706,"h":269,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/f\/4f0defde056eec6feb1c754cf233dea3"} [EDIT] As for how dynamic SAT works... {"name":"dynfs9.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/2\/92000938028336e60ab953d375cf379a.png","w":273,"h":249,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/2\/92000938028336e60ab953d375cf379a"} So why only one extra axis if we have a whole quad now to check? I gotta go now. I'll be back later. |
|
Anomie
Member #9,403
January 2008
|
Alright, I have to go for the night (1:22 here, and I have to be up in the morning), but I'll try and work through this, or write my own. I generally have a big problem working out how other peoples' code works. (that'd be why I didn't look into other engines when I started working on this) Thanks for the help. ______________ |
|
Stas B.
Member #9,615
March 2008
|
I'll try to make things clearer... Let's suppose that we're dealing with overlaps in one dimension.
Checking whether two intervals overlap is very straight-forward: int intervals_intersect(INTERVAL int0, INTERVAL int1) { if(int0.min > int1.max || int1.min > int0.max) return 0; return 1; }
Now, let's move on to two dimensions. http://img520.imageshack.us/img520/9764/slgj7.png So we can state our problem this way: Check every potential separating line: if the line checked separates the polygons, terminate the
. {"name":"seplinerj5.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/4\/84cdd11457f968e7f7146198b6e7ecfb.png","w":245,"h":229,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/4\/84cdd11457f968e7f7146198b6e7ecfb"} It can be proven that while there's an infinite number of such lines we could test, we only need to test a handful:
|
|
OnlineCop
Member #7,919
October 2006
|
Wow, Stas B., I don't think even Wikipedia was able to explain it to me that clearly. Bookmarked! (And good use of simple-but-efficient graphics!)
|
|
Anomie
Member #9,403
January 2008
|
Damn. You didn't have to go through that much trouble, though I think you've just written a good SAT resource. And did a good job, too! Yeah, all of those snippets make perfect sense now. Hang on, I'm going to go look at the rest... I think the only stuff that I don't get at this point is involved with the projection, but I never got around to looking into how that stuff works. ______________ |
|
Stas B.
Member #9,615
March 2008
|
I knew I should have written something about projection. The red point is the point we are projecting. P.S.: |
|
Anomie
Member #9,403
January 2008
|
Oh, sorry...I should have been more clear. By 'projection', I meant the process of projecting the objects out of collision. (But that bit you just posted is actually exactly what I'm doing in my Geometry class right now...kinda funny...) ______________ |
|
Stas B.
Member #9,615
March 2008
|
I have a feeling this is going to be a lot less clear... To resolve an overlap between two polygons, what we need to do is to turn one of the potential separating lines we discussed earlier into a real separating line. To do so, we need to make sure that the intervals of the polygons on the normal of that line stop overlapping. {"name":"resoverip8.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/a\/3a352044bcb17bfa86fd0ea827deaa78.png","w":553,"h":208,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/a\/3a352044bcb17bfa86fd0ea827deaa78"} Note that in the picture, the blue rectangle is penetrating the red one from the right, so we would push it in the direction of the normal, to the right. int intervals_intersect(INTERVAL int0, INTERVAL int1, double *depth) { double d0, d1; if(int0.min > int1.max || int1.min > int0.max) return 0; d0 = int0.max - int1.min; d1 = int1.max - int0.min; *depth = (d0 < d1) ? -d0 : d1; return 1; }
Note that 'depth' could be either positive or be negative, with plus meaning "in the direction of the normal" and minus meaning "in the opposite direction". So here's an updated version of the 'poly_intersection_test', which would not only tell us if the objects overlap, but also how much and in
Note that you can apply the resulting translation vector is several ways. |
|
Anomie
Member #9,403
January 2008
|
Awesome! That makes things much clearer. I'm probably going to rewrite this stuff myself (just because I'm awkward), but I'm thinking the background of the demo (if I ever release this thing) is going to be filled with "80% of this system thanks to: Stas B. and James Lohr" in huge glowing letters...or something... Thanks again! ______________ |
|
Stas B.
Member #9,615
March 2008
|
You're welcome. P.S.:
|
|
GullRaDriel
Member #3,861
September 2003
|
Usefull code, indeed. Thanks Stas B ! "Code is like shit - it only smells if it is not yours" |
|
Stas B.
Member #9,615
March 2008
|
Sorry, Anomie, but it turns out to be totally not worth it. [EDIT] Now that I think of it, your algorithm would suffer from the "points with different velocities" problem too. |
|
Anomie
Member #9,403
January 2008
|
Quote: it's gonna be as slow as your original algorithm eventually. Meh...that doesn't really bother me too much. Quote: Also, dynamic SAT wouldn't work right for you, because it assumes that all points of a given object are moving at the same velocity, but in your case, a line segment might rotate, so each point would move with a different velocity. But the way I was thinking of doing it, I would only check points (totally separate from eachother and anything else) against lines (totally separate from eachother and everything else). The only 'objects' I would have would be singles lines, and single points. Would that still be a problem? (or would it work at all? (or would it really just fix everything if I used polygons/circles for my points/lines? (and could I model my lines as having sub-pixel width?))) In any case, you've written a good new resource here! Not a total waste of time, even if it can't be used in my little thingy. ______________ |
|
Tobias Dammers
Member #2,604
August 2002
|
You guys draw nice colorful pictures. I love this thread. --- |
|
Stas B.
Member #9,615
March 2008
|
Points and lines bring us back to the problems we were trying to avoid. |
|
Anomie
Member #9,403
January 2008
|
Damn... It sounds like the dynamic SAT won't work if things can rotate, and even if I used full polygons, the standard static SAT can't be trusted unless I make my lines out of really thick rectangles... I know people have done this before me! Argh! I need to think more. ______________ |
|
Stas B.
Member #9,615
March 2008
|
SAT does perfectly well for objects that rotate, unless they rotate really really fast. But if they rotate that fast, you can treat them like circles. So that's really not a concern. [EDIT] Okay, this might sound like a crazy idea, but... well... you COULD break your objects into lots of lots of little circles and test those for collision. |
|
Anomie
Member #9,403
January 2008
|
Quote: SAT does pefectly well for objects that rotate ... The 'two different velocities' thing? Unless it's a perfect square, I guess...but I know that people have made systems where everything is made of point-masses/springs. I guess the solution may really be to find a way to separate everything into convex polygons dynamically...but gawd. It seems so ridiculous that the whole thing was made so much more complicated by gravity. It looks like 95% of the code in this system is going to be for the collision stuff. [edit] As in...having even my lines made of tiny circles? Huh... I guess, if I really wanted to, I could move things at a fifth their normal speed, and do five times as many ticks per second, to try and avoid missing collisions due to high speeds... Could that really work? [edit2] Wait, how would that be different from a simple distance-to-line check? ______________ |
|
Stas B.
Member #9,615
March 2008
|
[EDIT] You won't have missed collision problems if you FILL the areas of your objects with circles. [EDIT 2] You'll need to think of a smart way to fill in your circles, so you can cover the whole area of the object with as small number of circles as possible. [EDIT 3] |
|
Anomie
Member #9,403
January 2008
|
Oooooooh, I see! That makes more sense. So then... It still seems like I'd have to identify the shapes with enough accuracy to separate them into polygons...the hard part would be finding the center of a connected shape, with respect to the possibility of something like a box and a pole, attached by a rope of springs...which would each need to be registered separately for the circles, right? [edit] I must just be real slow with my posting. ______________ |
|
Stas B.
Member #9,615
March 2008
|
The difference is that you won't encounter any of those old problems that way. |
|
|
1
2
|