|
|
This thread is locked; no one can reply to it.
|
1
2
|
| I'm Just so Close (more Physics) |
|
Anomie
Member #9,403
January 2008
|
I've been having trouble with collision detection/response in my spring system, but I think I finally found a solution. James Lohr previously suggested that I use a method to find a reference point in each object made of springs, so that any point attached to the same object would know which side of a line segment (ground, something like that) to rest on. It occured to me that no spring should ever penetrate another in my system, and so I can find the appropriate resting side of a point by simply checking for a point it's attached to. In my head, this should work with any closed shape built of springs, and with any rope, as long as at least one point on the rope is fixed in the environment. (If a rope were lying on a resting surface, all of the connected points could pass through the ground at the same moment.) The way I implemented this was to - first of all - change my collision testing function to accept springs (rather than points), so as to test pairs of connected points. Then, after my old collision checking, I find the direction of both points from the line segment (before and after velocity). If I find that point 1 (after velocity) has moved to a side of the line opposite point 2 (before velocity), I move point 1 to the point of collision between the line segment that is testing for collision, and the line segment formed between the two points I'm testing. The same is reversed for the case of point 2 moving over the line. And uhm... It doesn't work. Doesn't really make a difference at all. I'm soooo close to having this thing working, and I've been wracking my brain on this - with no results.
(And I attached the rest of that file (which has become a grotesque monster), just in case...) So...can anyone help me out? ______________ |
|
kenmasters1976
Member #8,794
July 2007
|
I'm having myself my share of problems with springs right now. I don't think I can help you, but I'll be waiting for a demo of your spring system.
|
|
Anomie
Member #9,403
January 2008
|
Oh, everything was going really well...the springs are fantastically elegant (in my opinion) for representing...pretty much anything... Even the collision detection/response was going fine until... Gravity... Totally wrecked the thing. It doesn't play well with my infinitely small points and lines. 80% of the time I've spent working on this system, I've just been attempting to deal with the monkey wrench that gravity threw at me. ______________ |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Gravity shouldn't be too bad , just add the acceleration of gravity to all the particles in your system , find out how much force it causes according to their mass , calculate resultant counter-forces from fixed points and tension in connected objects , sum all the forces on each object , calculate their accelerations and then you can find their new positions. Geez , it's so simple , cmon. Quote: It doesn't play well with my infinitely small points and lines. What are you using the tiny points and lines for? Also , how are you simulating ropes? Are they a collection of connected springs to propagate tension along the points of the rope? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
Anomie
Member #9,403
January 2008
|
Oh, the problem isn't with the gravity itself, it's just that the gravity causes undesirable reactions all over the place. (like, for instance, my points falling through lines that they should be resting on) Quote: What are you using the tiny points and lines for? I want the points and springs to be used to make objects, so...I want them to be as non-object-like as possible? Like atoms connected by some mysterious cosmic force. Quote: Also , how are you simulating ropes? Are they a collection of connected springs to propagate tension along the points of the rope? Yeah, just like that little rope demo I posted here. I wouldn't really be implementing it... But...when the user's building, either they make closed shapes or 'ropes', right? ______________ |
|
Stas B.
Member #9,615
March 2008
|
From my experience, handling bodies during collision detection as a set of points and lines is really a pain in the butt. [EDIT] Consider these cases: In the bottom illustration, you see plenty of intersection points but it's not so obvious what to move where. |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Is this a typo in your code? // And after velocity float dir1b = (a*b)-(b*c); Isn't that supposed to be the dot product of the two vectors like the previous one (the assignment of dir1a)? Also , you could simplify those direction checks a little : float dir1a = (a*d >= b*c) ? 1 : -1; // instead of float dir1a = (a*d)-(b*c); if (dir1a >= 0) dir1a = 1; else dir1a = -1; It only gets rid of the subtraction , but it does the same thing anyway. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
Anomie
Member #9,403
January 2008
|
Quote: In the top case, the collision would just be missed. Well...it'd catch the collision, but nothing would happen...but that's just because I still haven't gotten around to having the point impart force on springs they collide with. Soon as that's handled (which is something I need to do anyway...any two moving objects smacking into each other will behave awkwardly in my system at the moment), it'll work. Quote: In the bottom illustration, you see plenty of intersection points but it's not so obvious what to move where. Yeah, that'd work just fine. Each point would get properly deflected, and the springs would do the rest. Quote: Is this a typo in your code? Yeah! I'd have been mad as hell if that was the problem... But strangely, it didn't seem to make a difference, really...hmm... Quote: Also , you could simplify those direction checks a little ... Well...that's handy! It seems like I've seen something like that somewhere... It tests (a*d >= b*c) for true or false, and gives the first or second value based on the result, right? [edit] Actually... I don't think it'd catch that top collision... I should change the checks to make them use relative velocity, rather than absolute velocity. That'd fix it, I think. ______________ |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Yes , the a?b:c operator returns b if a is true and c if a is false. Although I wonder what the > operator actually does for floats. Quote: and so I can find the appropriate resting side of a point by simply checking for a point it's attached to Won't that let the other end pass over the line as much as the length of the distance between the points though?
/___
/
I seem to get the impression that you're not checking all moving points for collisions but only one part of each object? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
OnlineCop
Member #7,919
October 2006
|
|
Anomie
Member #9,403
January 2008
|
Quote: Won't that let the other end pass over the line as much as the length of the distance between the points though? The idea is that...when the two points are just hanging out, not colliding, they both have the same direction from the line. If one of them crosses, it can check itself against at least one of the points it's attached to to find which side of the line it should actually be on. If point1 (after adding velocity) is on the opposite side of the line, compared to point2 (before velocity), then point1 crossed the line during the last update, and needs to be placed back on the line. (in the case of a totally unattached rope, the entire thing may cross the line at the same time, ruining my idea...) Quote: I seem to get the impression that you're not checking all moving points for collisions but only one part of each object? I'm actually checking each point several times. I'm checking every spring, and in any closed shape the endpoint of one spring will be the start-point of another, so on and so on. Especially in my cube, with it's cross-struts. (This is why I used that spring->p2->checked = true; bit.) Quote: You may look at some 2D and 3D engines. I thought those were both rigid-body engines...? I was considering seeing if I could ask this person some questions. It looks like they made just what I want to make. [edit] Woooah, Bullet's got cloth and soft-body stuff! I'm sure it's still polygon-based, though... ______________ |
|
Stas B.
Member #9,615
March 2008
|
Well, you see, relative velocity is great, but it basically means that you have to treat one object as static, and the other object as moving with the relative velocity. [EDIT] Some more bad cases: |
|
Anomie
Member #9,403
January 2008
|
Quote: it basically means that you have to treat one object as static, and the other object as moving with the relative velocity. Let's say spring1 is the spring that is checking for collision (as in 'Hey, what's colliding with me?') and it accepts spring2 as the springs it's checking for a collision with. (as in 'Hmm...is spring2 going to run into me?') I figured it would work fine if I always treat spring1 as the static object, and spring2 as the dynamic one. I'd check every single spring's relationship with every other spring, (as in spring1 vs. spring2 and spring2 vs. spring1) but when it comes to collision response, I'd just use the absolute velocities for both. With the relative velocities, both those cases would be handled just fine...I think. I don't see why they wouldn't. It might not be terribly fast, but it'd be just as elegant as what I've got going now. If you haven't looked at the code, it might be important for me to mention that the 'line-line collision' check I use is actually between the line segment checking for collision and every single point. (the second line is between the point's position before and after velocity) ______________ |
|
Stas B.
Member #9,615
March 2008
|
Doing silly redundant tests would solve one problem, but introduce a new one: [EDIT] This is how I see it: |
|
Anomie
Member #9,403
January 2008
|
Quote: ... your system is flawed. Definitely. But all I've got to go on is what I can come up with, because the only alternative I've heard - or been able to find - is to model everything as rectangles and spheres. (which seems like a real big leap from 'Simpleville' to 'Complicated-land') Would doing polygon vs. sphere collision really be that much faster than doing my line tests twice? (and besides, since I pass my collision function the whole spring object, I can just test for collisions between 'spring1's points against 'spring2' right in the same check...so I don't really need the two collision passes for everything) Quote: ... getting incorrect collision data. The only 'collision data' I really get is just whether or not the two things collided. Everything else I figure from the current variables of the points involved. (still need to find a way for points to impart force to springs, though...I don't know what complications that'll bring into focus) [edit]Oh, oh, oh...here... ______________ |
|
Stas B.
Member #9,615
March 2008
|
Time steps have been taken into account. P.S.: |
|
Anomie
Member #9,403
January 2008
|
Indeed, that appears to be a better plan! Quote: And if you have some lines that stand alone (like rope segments), SAT can handle them just fine the same way it handles polygons. Would I be able to do all is my individual segments like this? I don't want to have to separate all my potential objects into polygons. ______________ |
|
Stas B.
Member #9,615
March 2008
|
If you really don't want to treat every object as a whole, I guess you could treat them as sets of line segments and still use SAT, but you'd lose some of its important advantages, plus, you'd have to tweak it a bit and make the collision detection dynamic. |
|
Anomie
Member #9,403
January 2008
|
In what sense is it not dynamic? And what advantages would I be losing? ______________ |
|
Stas B.
Member #9,615
March 2008
|
Your algorithm is dynamic. But the simple, straight-forward implementation of SAT is not dynamic in the sense that it doesn't take velocities into account, just handles overlaps. Static tests work just fine for polygons at reasonable velocities, they'd work fine for line-vs-polygon, too, but not for line-vs-line cases. [EDIT] Found that soft body demo. |
|
Anomie
Member #9,403
January 2008
|
Will circle(point, given some size) vs. line not be workable in the same way as line vs. polygon? The only things I ever actually test for are collisions with points hitting lines. [edit]I've seen that before! Huh...wonder where... No springs? ______________ |
|
Stas B.
Member #9,615
March 2008
|
No, it would work perfectly fine... [EDIT] Maybe you've seen it at the Depot? [EDIT 2] There's no much point discussing SAT... If you want to, read about it a bit, to understand the principle, then decide if you need it or not. |
|
Anomie
Member #9,403
January 2008
|
In your opinion, would it be worth the effort of finding a method of dynamically recognizing complex convex or concave polygons full of cross-struts (which really don't need to be checked for collision) to avoid the inefficiency of that method? (the system runs very fast as it is, but I haven't gotten to the point where I can check on the demand of complex polygons interacting) ______________ |
|
Stas B.
Member #9,615
March 2008
|
Oh, damn, I forgot... |
|
Anomie
Member #9,403
January 2008
|
What I have now really doesn't work any better than it did before I turned it into a huge monster, so if SAT is faster and cleaner than what I have now, I'll try it. ______________ |
|
|
1
2
|