Determining Sender & Other in InitialCollisionDetected event
Posted: Wed Oct 05, 2011 8:08 pm
Hi,
I'm currently working on a default implementation of BEPUPhysics in my framework (IGF for SunBurn http://igf.codeplex.com)
Question I: Sender & Other identification
As part of it, I'm hooking the Entity.CollisionInformation.Events.InitialCollisionDetected event and I'm wondering in the handler how I can identify which of the "sender" and "other" Collidable instance passed to the delegate signature is the one I'm currently in.
Say, I have a CollisionEntity class that wraps an Entity instance and I hook the above event in the CollisionEntity constructor to a OnEntityInitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler pair) method.
Should I always test in this method:
if(sender == this)
To know which of the sender or other is the currently wrapped entity instance.
Or is there any rule that ensures that the sender is always the Entity that is attached to the hooked event?
Question II: Modifying CollisionRules once InitialCollisionDetected
Moreover, let's say I don't want to apply the Collision effects else "trigger" an event (useful for bullet collisions for instance). Would it make sense to apply a CollisionRules.NoSolver to the Entity.CollisionRules inside the InitialCollisionDetected event?
I know that I can set this before but that would save me an extra call in my API.
Thanks
I'm currently working on a default implementation of BEPUPhysics in my framework (IGF for SunBurn http://igf.codeplex.com)
Question I: Sender & Other identification
As part of it, I'm hooking the Entity.CollisionInformation.Events.InitialCollisionDetected event and I'm wondering in the handler how I can identify which of the "sender" and "other" Collidable instance passed to the delegate signature is the one I'm currently in.
Say, I have a CollisionEntity class that wraps an Entity instance and I hook the above event in the CollisionEntity constructor to a OnEntityInitialCollisionDetected(EntityCollidable sender, Collidable other, CollidablePairHandler pair) method.
Should I always test in this method:
if(sender == this)
To know which of the sender or other is the currently wrapped entity instance.
Or is there any rule that ensures that the sender is always the Entity that is attached to the hooked event?
Question II: Modifying CollisionRules once InitialCollisionDetected
Moreover, let's say I don't want to apply the Collision effects else "trigger" an event (useful for bullet collisions for instance). Would it make sense to apply a CollisionRules.NoSolver to the Entity.CollisionRules inside the InitialCollisionDetected event?
I know that I can set this before but that would save me an extra call in my API.
Thanks