Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Spatial Query on multiple Actors
#2
Hi there Will! Sonrisa

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!
Reply


Messages In This Thread
Spatial Query on multiple Actors - by cgwill - 20-12-2021, 09:35 AM
RE: Spatial Query on multiple Actors - by josemendez - 20-12-2021, 11:23 AM
RE: Spatial Query on multiple Actors - by cgwill - 21-12-2021, 07:30 PM