20-12-2021, 11:23 AM
(This post was last modified: 20-12-2021, 11:25 AM by josemendez.)
Hi there Will!
This will only work if you only have one actor per solver and it is not using surface collisions. To get a particle index from a simplex index in the general case, see "Retrieving the particle involved in a contact":
http://obi.virtualmethodstudio.com/manua...icles.html
In your case, assuming you don't use surface collisions the code would be:
If you do use surface collisions, the simplices used by queries and collisions will be groups of 2 particles each, so assuming there's only one particle per simplex no longer works. The general code to get all particles in a simplex (whether there's 1, 2 or 3 particles in the simplex) is:
Since the code to do this for collisions and queries is exactly the same, I will add this info to the queries manual page too as I realized it can be misleading otherwise.
Let me know if I can be of further help!
Code:
solver.positions[results[i].simplexIndex]
This will only work if you only have one actor per solver and it is not using surface collisions. To get a particle index from a simplex index in the general case, see "Retrieving the particle involved in a contact":
http://obi.virtualmethodstudio.com/manua...icles.html
In your case, assuming you don't use surface collisions the code would be:
Code:
// no surface collisions, so we assume only one particle per simplex:
int particleIndex = solver.simplices[results[i].simplexIndex];
var position = solver.positions[particleIndex];
If you do use surface collisions, the simplices used by queries and collisions will be groups of 2 particles each, so assuming there's only one particle per simplex no longer works. The general code to get all particles in a simplex (whether there's 1, 2 or 3 particles in the simplex) is:
Code:
// retrieve the offset and size of the simplex in the solver.simplices array:
int simplexStart = solver.simplexCounts.GetSimplexStartAndSize(contact.bodyA, out int simplexSize);
// starting at simplexStart, iterate over all particles in the simplex:
for (int i = 0; i < simplexSize; ++i)
{
int particleIndex = solver.simplices[simplexStart + i];
// do something with each particle, for instance get its position:
var position = solver.positions[particleIndex];
}
Since the code to do this for collisions and queries is exactly the same, I will add this info to the queries manual page too as I realized it can be misleading otherwise.
Let me know if I can be of further help!