rb->applyImpulse(i, rel_pos + i*s)

User avatar
Carsten
Posts: 14
Joined: Thu Sep 25, 2008 1:36 pm
Location: Germany

rb->applyImpulse(i, rel_pos + i*s)

Post by Carsten »

Hello all,

I'm currently implementing the effect of explosions (and e.g. of bullets hitting crates) by applying impulse scaled by distance to objects in the vicinity of the explosion.

It works very well, but I want to save computing the exact point in space where the objects are hit by the impact.

Do I understand btRigidBody::applyImpulse() correct in that when
  • rb is a btRigidBody,
  • i is an impulse,
  • s is a scalar,
  • rel_pos is a correct relative position,
then in the call

Code: Select all

 rb->applyImpulse(i, rel_pos + i*s);
the result is the same no matter the value of s?
(Because the implementation computes i.cross(rel_pos + i*s) which reduces to i.cross(rel_pos) ?)

With this argument the following is possible:
When Ob is the origin of the bomb or bullet, the related ray of impact propagation is Ob + i*s.
When Oc is the origin of the hit crate, rel_pos = (Ob + i*s) - Oc for the unknown s.
But as stated above, this reduces to rel_pos = Ob - Oc, saving the computation of s!

Can somebody confirm (or deny) if this is correct?
Any fault or oversight in this use of the applyImpact() method?
Btw., assuming that this is ok, I just tried an experimental implementation in my 3D engine, and it seems to work wonderfully! :D