Skip to main content
GameDev.net gamedev.net
🔒 Locked

Position Based Dynamics collision

Started by BRabbit27 Oct 9, 2014 at 6:40 PM 3 replies 6.1k views
Original Post
BRabbit27
BRabbit27

I have read about Position-Based dynamics from this paper but I got a little bit confused on how can I use it to implement collision detection and response. I could follow the math for the case of a distance constrain but it got a bit confusing when trying to apply the same principle to collision.

They mention 2 types of collision detection: continuous and static. The former is when at time t the particle is in the valid zone and in time t+1 is not. The latter is just when at both times the position is invalid and thus the continuous collision detection failed.

To check whether a collision existed I can compute the distance from the particle's position pi to the plane. This is achieved with the following equation (po-pi) . n = d where po is a point in the plane and "n" is the normal of the plane. So far so good.

If I got it correctly I can add a constraint of type unilateral as follows C(pi) = (po-pi) . n >= 0. However, it mentions two conditions.

- If particle pi comes from a valid to an invalid position, compute qc and add an unilateral constraint C(p) = (p-qc) . nc >= 0

- If particle pi has been in an invalid position, compute qs (closest point to pi) and add an unilateral constraint C(p) = (p-qs) . ns >= 0

So, my questions are

1) In the previous constraints what is P ? Is this the point in the plane or the particle's position? Since I know I have to have a point in the plane to be able to compute the distance from the particle to the plane I would say it is a point in the plane, nevertheless, the constraints are applied to the positions of the particles, so my previous statement makes no sense.

2) If I have to compute qc (or qs) then the constrain is solved right? why would I need to create a constraint when I already have the valid point?

3) For any constrain I want my system to be subject to, is the method described like a recipe? What I mean, I just take the constraint, compute the gradient, compute lambda, and then solve iteratively?

BRabbit27
BRabbit27

After some reading and thinking I figure out the idea behind those lines (I hope).

Since we have a particle at position xi and after updating velocity and predicted the new position pi we want to know whether there is a collision and if so move the particle back to the collision point qc and then using position-based dynamics compute a new valid position for the particle.

To check whether the particle when moving from xi to pi collides, we check if there is an intersection of the ray given by r = xi + t(pi-xi) and the plane P = (p-p0) dot n where t will tell us if there is a collision (0 <= t <= 1) or not.

Once we get the collision point qc we can create an inequality constrain C(p) = (p-qc) dot ncwhere nc is the same as the normal of the plane. With this constrain I can get the correction position DeltaP. Now the only question remaining is

- If I have two different constraints, each will give a DeltaP then, how to mix them in order to have the final correction position?

matejd
matejd

First time posting here, but I've been reading position-based dynamics recently as well.

If I understand your last question about constraint mixing correctly, the answer is that this is what the repeated constraint projection is for (solverIterations times going through the

list of constraints and projecting them). Solving one constraint might mean that another one needs to be solved again, but after several iterations, all should be satisfied (at least

approximately).

Also, this lecture might be useful:

BRabbit27
BRabbit27

After some more thinking and reading your answer, so basically, for a single particle I will do something like

  1. While iter < solverIteration do
  2. Take constraint C1 compute DeltaP
  3. Update particle's tmpPosition
  4. Take constraint C2 compute DeltaP
  5. Update particle's tmpPosition
  6. End while

and, as you said, after a certain number of iterations, the system will have the best approximation of tmpPosition that satisfies both constraints, right?

BTW, thanks for the video, I'll watch it right away !

matejd
matejd

Yes, updated position is immediately visible to other constraints - the authors call it a Gauss-Seidel-type iteration in section 3.2 (vs Jacobi-type). These slides have more on this iteration.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.