From b8786c2aaff266fbe5611acf409c146741515871 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Thu, 17 May 2012 20:39:54 -0500 Subject: [PATCH] Adding Contact extension --- axios/Engine/Extensions/Contact.cs | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 axios/Engine/Extensions/Contact.cs diff --git a/axios/Engine/Extensions/Contact.cs b/axios/Engine/Extensions/Contact.cs new file mode 100644 index 0000000..e8c16a8 --- /dev/null +++ b/axios/Engine/Extensions/Contact.cs @@ -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; + } + } +}