Finding the correct direction of the surface normal?
Posted: Tue Apr 26, 2011 10:37 pm
I'm firing a projectile sphere at a triangle surface and I wish to know the normal of the collision based on the triangle but inside the event attached to the sphere.
If I find the contact normal in this event then it can often be in the opposite direction in relation to the triangle. Should I detect which of the two entities in the pair is the same as the one for which the event is attached and swap the direction of the normal as appropriate?
Or is there a better way to approach this?
If I find the contact normal in this event then it can often be in the opposite direction in relation to the triangle. Should I detect which of the two entities in the pair is the same as the one for which the event is attached and swap the direction of the normal as appropriate?
Code: Select all
protected void Events_InitialCollisionDetected(EntityCollidable info, BroadPhaseEntry entry, INarrowPhasePair pair)
{
CollidablePairHandler collidablePair = pair as CollidablePairHandler;
if (collidablePair == null)
{
return;
}
Vector3 normal = collidablePair.Contacts[0].Contact.Normal;
Vector3 position = collidablePair.Contacts[0].Contact.Position;
EntityCollidable a = pair.BroadPhaseOverlap.EntryA as EntityCollidable;
EntityCollidable b = pair.BroadPhaseOverlap.EntryB as EntityCollidable;
if (a.Entity == this.Entity)
{
normal = -normal; // Surface normal for triangle
}
}
Or is there a better way to approach this?