diff -r 214995dda98411e0f6eab4c7127ad29882ffaa12 -r 0d5aac94bce0bab58dac1981c36d20e61699e1a8 axios/Engine/Extensions/Contact.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/axios/Engine/Extensions/Contact.cs Thu May 17 20:39:54 2012 -0500 @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FarseerPhysics.Dynamics.Contacts; +using Microsoft.Xna.Framework; + +namespace Axios.Engine.Extensions +{ + public enum CollisionDirection + { + Right, + Left, + Top, + Bottom + } + public static class AxiosExtensions_Contact + { + /// http://farseerphysics.codeplex.com/discussions/281783 + /// + /// Returns the direction that the collision happened. + /// Should be used in the event OnAfterCollision + /// + /// + /// + public static CollisionDirection Direction(this Contact c) + { + CollisionDirection direction; + // Work out collision direction + Vector2 colNorm = c.Manifold.LocalNormal; + if (Math.Abs(colNorm.X) > Math.Abs(colNorm.Y)) + { + // X direction is dominant + if (colNorm.X > 0) + direction = CollisionDirection.Right; + else + direction = CollisionDirection.Left; + } + else + { + // Y direction is dominant + if (colNorm.Y > 0) + direction = CollisionDirection.Top; + else + direction = CollisionDirection.Bottom; + } + + + + return direction; + } + } +}