Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

Here's a post which has links to papers about similar types of simulations (in engineering/academic contexts rather than for games): http://gamedev.stackexchange.com/a/10350/6398https://gamedev.stackexchange.com/a/10350/6398

Here's a post which has links to papers about similar types of simulations (in engineering/academic contexts rather than for games): http://gamedev.stackexchange.com/a/10350/6398

Here's a post which has links to papers about similar types of simulations (in engineering/academic contexts rather than for games): https://gamedev.stackexchange.com/a/10350/6398

added 4 characters in body
Source Link
raigan
  • 136
  • 5

(I can't fully recall OTOH but you can approach it as follows: find the time t when point a is contained in line passing through b,c, (I think I did this by solving for when dot(a-b,c-b) = 0 to find values of t), and then given a valid time 0<=t<1, find the parametric position s of a on the segment bc, i.e a = b + s*(c1-s)b + sc and if a is between b and c (i.e if 0<=s<=1) it's a valid collision.

(I can't fully recall OTOH but you can approach it as follows: find the time t when point a is contained in line passing through b,c, (I think I did this by solving for when dot(a-b,c-b) = 0 to find values of t), and then given a valid time 0<=t<1, find the parametric position s of a on the segment bc, i.e a = b + s*(c) and if a is between b and c (i.e if 0<=s<=1) it's a valid collision.

(I can't fully recall OTOH but you can approach it as follows: find the time t when point a is contained in line passing through b,c, (I think I did this by solving for when dot(a-b,c-b) = 0 to find values of t), and then given a valid time 0<=t<1, find the parametric position s of a on the segment bc, i.e a = (1-s)b + sc and if a is between b and c (i.e if 0<=s<=1) it's a valid collision.

Source Link
raigan
  • 136
  • 5

Here's a post which has links to papers about similar types of simulations (in engineering/academic contexts rather than for games): http://gamedev.stackexchange.com/a/10350/6398

I've tried at least two different approaches to collision detection+response for this sort of "wire" simulation (as seen in the game Umihara Kawase); at least, I think this is what you're after -- there doesn't seem to be a specific term for this sort of simulation, I just tend to call it "wire" rather than "rope" because it seems like most people consider "rope" to be synonymous with "a chain of particles". And, if you want the stick-ish behaviour of ninja rope (i.e it can push AND pull), this is sort of more like a rigid wire than a rope. Anyway..

Pekuja's answer is good, you can implement continuous collision detection by solving for the time when the signed area of the three points is 0.

(I can't fully recall OTOH but you can approach it as follows: find the time t when point a is contained in line passing through b,c, (I think I did this by solving for when dot(a-b,c-b) = 0 to find values of t), and then given a valid time 0<=t<1, find the parametric position s of a on the segment bc, i.e a = b + s*(c) and if a is between b and c (i.e if 0<=s<=1) it's a valid collision.

AFAICR you can approach it the other way around too (i.e solve for s and then plug this in to find t) but it's a lot less intuitive. (I'm sorry if this doesn't make any sense, I don't have time to dig up my notes and it's been a few years!))

So, you can now calculate all the times at which events happen (i.e rope nodes should be inserted or removed); process the earliest event (insert or remove a node) and then repeat/recurse until there are no more events between t=0 and t=1.

One warning about this approach: if the objects that the rope can wrap around are dynamic (especially if you're simulating them AND their effects on the rope, and vice-versa) then there can be problems if those objects clip/pass through each other -- the wire can become tangled. And it will definitely be challenging to prevent this sort of interaction/movement (the corners of objects slipping through each other) in a box2d-style physics simulation.. small amounts of penetration between objects is normal behaviour in that context.

(At least.. this was a problem with one of my implementations of "wire".)

A different solution, which is much more stable but which misses some collisions in certain conditions is to just use static tests (i.e don't worry about ordering by time, just recursively subdivide each segment in collision as you find them), which can be a lot more robust -- the wire won't tangle at corners and small amounts of penetration will be fine.

I think Pekuja's approach works for this too, however there are alternate approaches. One approach I've used is to add auxiliary collision data: at each convex vertex v in the world (i.e the corners of shapes which the rope can wrap around), add a point u forming the directed line segment uv, where u is some point "inside the corner" (i.e inside the world, "behind" v; to calculate u you can cast a ray inward from v along its interpolated normal and stop some distance after v or before the ray intersects with an edge of the world and exits the solid region. Or, you can just manually paint the segments into the world using a visual tool/level editor).

Anyway, you now have a set of "corner linesegs" uv; for each uv, and each segment ab in the wire, check if ab and uv intersect (i.e static, boolean lineseg-lineseg intersection query); if so, recurse (split the lineseg ab into av and vb, i.e insert v), recording which direction the rope bent at v. Then for each pair of neighbouring linesegs ab,bc in the wire, test if the current bend direction at b is the same as when b was generated (all of these "bend direction" tests are just signed-area tests); if not, merge the two segments into ac (i.e remove b).

Or maybe I merged and then split, I forget -- but it definitely works in at least one of the two possible orders! :)

Given all the wire segments calculated for the current frame, you can then simulate a distance constraint between the two wire endpoints (and you can even involve the interior points, i.e the contact points between the wire and the world, but that's a bit more involved).

Anyway, hopefully this will be of some use... the papers in the post I linked too should also give you some ideas.