Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Get the rope REAL particle index on colliision
#2
(02-10-2023, 07:58 AM)lacasrac Wrote: var particleIndex = solver.simplices[contact.bodyA];

Hi,

As explained in the manual, you can only assume simplices are the same as particles in case none of the ropes in your solver use surface collisions. In all other cases, the code above will retrieve the wrong index. See "Retreving the particle involved in a contact" for sample code that correctly retrieves all particles in the simplex.

Another problem is that the particle indices you retrieve from solver.simplices are already expressed relative to the solver. If you pass that to GetParticleNeighborIndex() - which assumes you pass the index of a particle in an actor- its first line will attempt to use it to access the actor's solverIndices array:

Code:
var solverIndex = rope.solverIndices[particleIndex];

Leading to an out of bounds access most of the time since the solver always has more particles than a single actor. Assuming you leave GetParticleNeighborIndex unmodified, you must do this:

Code:
// take the index of the bodyA's first particle in the solver:
var particleIndex = solver.simplices[contact.bodyA];

// then use it retrieve the index of that particle in the actor and pass it to GetParticleNeighborIndex
GetParticleNeighborIndex(solver.particleToActor[particleIndex].indexInActor);

instead of

Code:
// take the index of the particle in the solver, then pass it to GetParticleNeighborIndex (which assumes you pass the index of that particle in the actor, causing an exception:
var particleIndex = solver.simplices[contact.bodyA];
GetParticleNeighborIndex(particleIndex);

kind regards,
Reply


Messages In This Thread
RE: Get the rope REAL particle index on colliision - by josemendez - 02-10-2023, 08:17 AM