public unsafe static void GetLateralFrictionDir1(this ManifoldPoint obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.LateralFrictionDir1;
     }
 }
 public unsafe static void GetPositionWorldOnB(this ManifoldPoint obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.PositionWorldOnB;
     }
 }
 public unsafe static void SetPositionWorldOnA(this ManifoldPoint obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.PositionWorldOnA = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
 public unsafe static void GetLocalPointB(this ManifoldPoint obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.LocalPointB;
     }
 }
 public unsafe static void SetNormalWorldOnB(this ManifoldPoint obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.NormalWorldOnB = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
示例#6
0
 static void CustomMaterialCombinerCallback(ManifoldPoint cp,
     CollisionObjectWrapper colObj0Wrap, int partId0, int index0,
     CollisionObjectWrapper colObj1Wrap, int partId1, int index1)
 {
     // Apply material properties
     if (colObj0Wrap.CollisionShape.ShapeType == BroadphaseNativeType.TriangleShape)
     {
         CollisionShape parent0 = colObj0Wrap.CollisionObject.CollisionShape;
         if (parent0 != null && parent0.ShapeType == BroadphaseNativeType.MultiMaterialTriangleMesh)
         {
             MultimaterialTriangleMeshShape shape = parent0 as MultimaterialTriangleMeshShape;
             BulletMaterial props = shape.GetMaterialProperties(partId0, index0);
             cp.CombinedFriction = CalculateCombinedFriction(props.Friction, colObj1Wrap.CollisionObject.Friction);
             cp.CombinedRestitution = props.Restitution * colObj1Wrap.CollisionObject.Restitution;
         }
     }
     else if (colObj1Wrap.CollisionShape.ShapeType == BroadphaseNativeType.TriangleShape)
     {
         CollisionShape parent1 = colObj1Wrap.CollisionObject.CollisionShape;
         if (parent1 != null && parent1.ShapeType == BroadphaseNativeType.MultiMaterialTriangleMesh)
         {
             MultimaterialTriangleMeshShape shape = parent1 as MultimaterialTriangleMeshShape;
             BulletMaterial props = shape.GetMaterialProperties(partId1, index1);
             cp.CombinedFriction = CalculateCombinedFriction(props.Friction, colObj0Wrap.CollisionObject.Friction);
             cp.CombinedRestitution = props.Restitution * colObj0Wrap.CollisionObject.Restitution;
         }
     }
 }
 public unsafe static void SetLocalPointB(this ManifoldPoint obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.LocalPointB = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
 public unsafe static void SetLateralFrictionDir2(this ManifoldPoint obj, ref OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         obj.LateralFrictionDir2 = *(BulletSharp.Math.Vector3 *)valuePtr;
     }
 }
示例#9
0
        public void CheckGround(ManifoldPoint cp)
        {
            if (HaveGround)
            {
                return;
            }

            Matrix inverse = _controller.RigidBody.WorldTransform;

            inverse.Invert();
            Vector3 localPoint = Vector3.TransformCoordinate(cp.PositionWorldOnB, inverse);

            localPoint = new Vector3(localPoint.X, localPoint.Y + _controller.CapsuleHalfHeight, localPoint.Z);

            float r        = localPoint.Length;
            float cosTheta = localPoint.Y / r;

            if (System.Math.Abs(r - _controller.CapsuleRadius) <= _controller.GroundSearchMargin &&
                cosTheta < _controller.MaxCosGround)
            {
                HaveGround   = true;
                GroundPoint  = cp.PositionWorldOnB;
                GroundNormal = cp.NormalWorldOnB;
            }
        }
 public override float AddSingleResult(ManifoldPoint cp, CollisionObject colObj0, int partId0, int index0, CollisionObject colObj1, int partId1, int index1)
 {
     if (colObj0.UserObject != null && colObj0.UserObject is IPhysicObject)
     {
         objs.Add(colObj0.UserObject as IPhysicObject);
     }
     return 0;
 }
 public override float AddSingleResult(ManifoldPoint cp,
     CollisionObjectWrapper colObj0Wrap, int partId0, int index0,
     CollisionObjectWrapper colObj1Wrap, int partId1, int index1)
 {
     Vector3 ptA = cp.PositionWorldOnA;
     Vector3 ptB = cp.PositionWorldOnB;
     world.DebugDrawer.DrawLine(ref ptA, ref ptB, System.Drawing.Color.Blue);
     return 0;
 }
        // MyContactCallback is just an example to show how to get access to the child shape that collided
        void MyContactCallback(ManifoldPoint cp, CollisionObjectWrapper colObj0Wrap, int partId0, int index0, CollisionObjectWrapper colObj1Wrap, int partId1, int index1)
        {
            if (colObj0Wrap.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                CompoundShape compound = colObj0Wrap.CollisionObject.CollisionShape as CompoundShape;
                CollisionShape childShape = compound.GetChildShape(index0);
            }

            if (colObj1Wrap.CollisionObject.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                CompoundShape compound = colObj1Wrap.CollisionObject.CollisionShape as CompoundShape;
                CollisionShape childShape = compound.GetChildShape(index1);
            }
        }
        public void Resolve(ManifoldPoint cp)
        {
            _stepPos    = cp.PositionWorldOnB;
            _stepNormal = cp.NormalWorldOnB;

            _originHeight = _controller.CapsuleHalfHeight + _controller.CapsuleRadius;
            var transform = _controller.RigidBody.WorldTransform;

            IsStep = CheckPreconditions(ref transform) && FindRealPoint(ref transform) && canFit(ref transform);
            if (IsStep)
            {
                Vector3 origin = transform.Origin;
                origin.Y = origin.Y - _originHeight;
                DistSqr  = (origin - RealPosWorld).Length;
            }
        }
        //! Called with each contact for your own processing (e.g. test if contacts fall in within sensor parameters)
        public override float AddSingleResult(ManifoldPoint cp,
            CollisionObjectWrapper colObj0, int partId0, int index0,
            CollisionObjectWrapper colObj1, int partId1, int index1)
        {
            Vector3 pt; // will be set to point of collision relative to body
            if (colObj0.CollisionObject == body)
            {
                pt = cp.LocalPointA;
                //Console.WriteLine("ContactSensorCallback");
            }
            else
            {
                System.Diagnostics.Debug.Assert(colObj1.CollisionObject == body);
                pt = cp.LocalPointB;
            }

            // do stuff with the collision point
            return 0; // not actually sure if return value is used for anything...?
        }
示例#15
0
        public override float AddSingleResult(ManifoldPoint cp, CollisionObjectWrapper colObj0, int partId0, int index0,
                                              CollisionObjectWrapper colObj1, int partId1, int index1)
        {
            if (colObj0.CollisionObject == _controller.RigidBody)
            {
                CheckGround(cp);
                _resolveStepUp.Resolve(cp);
                if (_resolveStepUp.IsStep)
                {
                    if (!HaveStep || _resolveStepUp.DistSqr < _stepDistSqr)
                    {
                        StepPoint    = _resolveStepUp.RealPosWorld;
                        _stepNormal  = cp.NormalWorldOnB;
                        _stepDistSqr = _resolveStepUp.DistSqr;
                    }
                    HaveStep = true;
                }
            }

            // By looking at btCollisionWorld.cpp, it seems Bullet ignores this value
            return(0);
        }
        private void OnContactAdded(ManifoldPoint cp, CollisionObjectWrapper colObj0Wrap, int partId0, int index0,
            CollisionObjectWrapper colObj1Wrap, int partId1, int index1)
        {
            //Debug.WriteLine("OnContactAdded");
            int numManifolds = BtWorld.Dispatcher.NumManifolds;

            for (int i = 0; i < numManifolds; i++)
            {
                PersistentManifold contactManifold = BtWorld.Dispatcher.GetManifoldByIndexInternal(i);
                int numContacts = contactManifold.NumContacts;
                if (numContacts > 0)
                {
                    cp.UserPersistentData = 1;

                    CollisionObject obA = (CollisionObject) contactManifold.Body0;
                    CollisionObject obB = (CollisionObject) contactManifold.Body1;
                    RigidBody btRigidBodyA = (RigidBody) obA;
                    RigidBody btRigidBodyB = (RigidBody)obB;
                    RigidBodyImp rigidBodyA = new RigidBodyImp();
                    RigidBodyImp rigidBodyB = new RigidBodyImp();
                    rigidBodyA._rbi = btRigidBodyA;
                    rigidBodyB._rbi = btRigidBodyB;
                    rigidBodyA.OnCollision(rigidBodyB);
                }
            }
        }
 public abstract float AddSingleResult(ManifoldPoint cp, CollisionObjectWrapper colObj0Wrap, int partId0, int index0, CollisionObjectWrapper colObj1Wrap, int partId1, int index1);
示例#18
0
 public abstract double AddSingleResult(ManifoldPoint cp, CollisionObjectWrapper colObj0Wrap, int partId0, int index0, CollisionObjectWrapper colObj1Wrap, int partId1, int index1);
示例#19
0
 public ManifoldPoint GetContactPoint(int index)
 {
     return(ManifoldPoint.FromPtr(btPersistentManifold_getContactPoint(Native, index)));
 }
 public static void SetLocalPointB(this ManifoldPoint obj, OpenTK.Vector3 value)
 {
     SetLocalPointB(obj, ref value);
 }
 public static void SetLateralFrictionDir2(this ManifoldPoint obj, OpenTK.Vector3 value)
 {
     SetLateralFrictionDir2(obj, ref value);
 }
 public int AddManifoldPoint(ManifoldPoint newPoint)
 {
     return btPersistentManifold_addManifoldPoint(_native, newPoint._native);
 }
示例#23
0
 public bool ValidContactDistance(ManifoldPoint pt)
 {
     return(btPersistentManifold_validContactDistance(Native, pt.Native));
 }
 public void ClearUserCache(ManifoldPoint pt)
 {
     btPersistentManifold_clearUserCache(_native, pt._native);
 }
 public void ReplaceContactPoint(ManifoldPoint newPoint, int insertIndex)
 {
     btPersistentManifold_replaceContactPoint(_native, newPoint._native, insertIndex);
 }
示例#26
0
 private static bool ContactProcessedUnmanaged(IntPtr cp, IntPtr body0, IntPtr body1)
 {
     _contactProcessed.Invoke(ManifoldPoint.FromPtr(cp), CollisionObject.GetManaged(body0), CollisionObject.GetManaged(body1));
     return(false);
 }
 public int AddManifoldPoint(ManifoldPoint newPoint, bool isPredictive)
 {
     return btPersistentManifold_addManifoldPoint2(_native, newPoint._native, isPredictive);
 }
        //! Called with each contact for your own processing (e.g. test if contacts fall in within sensor parameters)
#if BT_USE_DOUBLE_PRECISION
        public override double AddSingleResult(ManifoldPoint cp,
 public int GetCacheEntry(ManifoldPoint newPoint)
 {
     return btPersistentManifold_getCacheEntry(_native, newPoint._native);
 }
示例#30
0
        // MyContactCallback is just an example to show how to get access to the child shape that collided
        bool MyContactCallback(ManifoldPoint cp, CollisionObject colObj0, int partId0, int index0, CollisionObject colObj1, int partId1, int index1)
        {
            if (colObj0.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                CompoundShape compound = colObj0.CollisionShape as CompoundShape;
                CollisionShape childShape = compound.GetChildShape(index0);
            }

            if (colObj1.CollisionShape.ShapeType == BroadphaseNativeType.CompoundShape)
            {
                CompoundShape compound = colObj1.CollisionShape as CompoundShape;
                CollisionShape childShape = compound.GetChildShape(index1);
            }

            return true;
        }
 public bool ValidContactDistance(ManifoldPoint pt)
 {
     return btPersistentManifold_validContactDistance(_native, pt._native);
 }
 public static void SetPositionWorldOnB(this ManifoldPoint obj, OpenTK.Vector3 value)
 {
     SetPositionWorldOnB(obj, ref value);
 }
示例#33
0
        protected bool RecoverFromPenetration(CollisionWorld collisionWorld)
        {
            Vector3 minAabb, maxAabb;

            m_convexShape.GetAabb(m_ghostObject.WorldTransform, out minAabb, out maxAabb);
            collisionWorld.Broadphase.SetAabbRef(m_ghostObject.BroadphaseHandle,
                                                 ref minAabb,
                                                 ref maxAabb,
                                                 collisionWorld.Dispatcher);

            bool penetration = false;

            collisionWorld.Dispatcher.DispatchAllCollisionPairs(m_ghostObject.OverlappingPairCache, collisionWorld.DispatchInfo, collisionWorld.Dispatcher);

            m_currentPosition = m_ghostObject.WorldTransform.Origin;

            float maxPen = 0f;

            for (int i = 0; i < m_ghostObject.OverlappingPairCache.NumOverlappingPairs; i++)
            {
                m_manifoldArray.Clear();

                BroadphasePair collisionPair = m_ghostObject.OverlappingPairCache.OverlappingPairArray[i];

                CollisionObject obj0 = collisionPair.Proxy0.ClientObject as CollisionObject;
                CollisionObject obj1 = collisionPair.Proxy1.ClientObject as CollisionObject;

                if ((obj0 != null && !obj0.HasContactResponse) || (obj1 != null && !obj1.HasContactResponse))
                {
                    continue;
                }

                collisionPair.GetAllContactManifolds(m_manifoldArray);

                for (int j = 0; j < m_manifoldArray.Count; j++)
                {
                    var manifoldId  = AlignedManifoldArray.btAlignedManifoldArray_at(m_manifoldArray._native, j);
                    var bodyId      = PersistentManifold.btPersistentManifold_getBody0(manifoldId);
                    var numContacts = PersistentManifold.btPersistentManifold_getNumContacts(manifoldId);

                    float directionSign = bodyId == m_ghostObject._native ? -1f : 1f;
                    for (int p = 0; p < numContacts; p++)
                    {
                        var   manifoldPointId = PersistentManifold.btPersistentManifold_getContactPoint(manifoldId, p);
                        float dist            = ManifoldPoint.btManifoldPoint_getDistance(manifoldPointId);
                        if (dist < 0.0f)
                        {
                            Vector3 normalWorldOnB;
                            ManifoldPoint.btManifoldPoint_getNormalWorldOnB(manifoldPointId, out normalWorldOnB);
                            if (dist < maxPen)
                            {
                                maxPen = dist;
                            }

                            var counterPenDir = normalWorldOnB * directionSign;;
                            m_currentPosition += counterPenDir * dist;
                            penetration        = true;
                            if (counterPenDir.Dot(Vector3.UnitY) > 0)
                            {
                                m_verticalVelocity = 0;
                            }
                        }
                    }
                }
            }
            Matrix newTrans = m_ghostObject.WorldTransform;

            newTrans.Origin = m_currentPosition;
            m_ghostObject.WorldTransform = newTrans;
            return(penetration);
        }
 public static OpenTK.Vector3 GetLateralFrictionDir2(this ManifoldPoint obj)
 {
     OpenTK.Vector3 value;
     GetLateralFrictionDir2(obj, out value);
     return(value);
 }
        protected bool RecoverFromPenetration(CollisionWorld collisionWorld)
        {
            Vector3 minAabb, maxAabb;

            m_convexShape.GetAabb(m_ghostObject.WorldTransform, out minAabb, out maxAabb);
            collisionWorld.Broadphase.SetAabbRef(m_ghostObject.BroadphaseHandle,
                                                 ref minAabb,
                                                 ref maxAabb,
                                                 collisionWorld.Dispatcher);

            bool penetration = false;

            collisionWorld.Dispatcher.DispatchAllCollisionPairs(m_ghostObject.OverlappingPairCache, collisionWorld.DispatchInfo, collisionWorld.Dispatcher);

            m_currentPosition = m_ghostObject.WorldTransform.Origin;

            float maxPen = 0f;

            for (int i = 0; i < m_ghostObject.OverlappingPairCache.NumOverlappingPairs; i++)
            {
                m_manifoldArray.Clear();

                BroadphasePair collisionPair = m_ghostObject.OverlappingPairCache.OverlappingPairArray[i];

                CollisionObject obj0 = collisionPair.Proxy0.ClientObject as CollisionObject;
                CollisionObject obj1 = collisionPair.Proxy1.ClientObject as CollisionObject;

                if ((obj0 != null && !obj0.HasContactResponse) || (obj1 != null && !obj1.HasContactResponse))
                {
                    continue;
                }

                if (collisionPair.Algorithm != null)
                {
                    collisionPair.Algorithm.GetAllContactManifolds(m_manifoldArray);
                }

                for (int j = 0; j < m_manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = m_manifoldArray[j];
                    float directionSign         = manifold.Body0 == m_ghostObject ? -1f : 1f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);

                        float dist = pt.Distance;

                        if (dist < 0.0f)
                        {
                            if (dist < maxPen)
                            {
                                maxPen           = dist;
                                m_touchingNormal = pt.NormalWorldOnB * directionSign;//??
                            }
                            m_currentPosition += pt.NormalWorldOnB * directionSign * dist * 0.2f;
                            penetration        = true;
                        }
                        else
                        {
                            //printf("touching %f\n", dist);
                        }
                    }

                    //manifold.ClearManifold();
                }
            }
            Matrix newTrans = m_ghostObject.WorldTransform;

            newTrans.Origin = m_currentPosition;
            m_ghostObject.WorldTransform = newTrans;
            //	printf("m_touchingNormal = %f,%f,%f\n",m_touchingNormal[0],m_touchingNormal[1],m_touchingNormal[2]);
            return(penetration);
        }
 public static OpenTK.Vector3 GetLocalPointB(this ManifoldPoint obj)
 {
     OpenTK.Vector3 value;
     GetLocalPointB(obj, out value);
     return(value);
 }
 public override float AddSingleResult(ManifoldPoint cp,
     CollisionObjectWrapper colObj0Wrap, int partId0, int index0,
     CollisionObjectWrapper colObj1Wrap, int partId1, int index1)
 {
     Vector3 ptA = cp.PositionWorldOnA;
     Vector3 ptB = cp.PositionWorldOnB;
     UnityEngine.Debug.Log("Contact!");
     world.DebugDrawer.DrawLine(ref ptA, ref ptB, ref ptA);
     return 0;
 }
示例#38
0
 public int AddManifoldPoint(ManifoldPoint newPoint, bool isPredictive = false)
 {
     return(btPersistentManifold_addManifoldPoint(Native, newPoint.Native,
                                                  isPredictive));
 }
 void OnContactProcessed(ManifoldPoint cp, CollisionObject body0, CollisionObject body1)
 {
     // Debug.WriteLine("OnContactProcessed");
     cp.UserPersistentData = 1;
 }
示例#40
0
 public int GetCacheEntry(ManifoldPoint newPoint)
 {
     return(btPersistentManifold_getCacheEntry(Native, newPoint.Native));
 }
 public int AddManifoldPoint(ManifoldPoint newPoint)
 {
     return(btPersistentManifold_addManifoldPoint(_native, newPoint._native));
 }
示例#42
0
 private float AddSingleResultUnmanaged(IntPtr cp, IntPtr colObj0Wrap, int partId0, int index0, IntPtr colObj1Wrap, int partId1, int index1)
 {
     return(AddSingleResult(ManifoldPoint.FromPtr(cp),
                            new CollisionObjectWrapper(colObj0Wrap), partId0, index0,
                            new CollisionObjectWrapper(colObj1Wrap), partId1, index1));
 }
示例#43
0
 public void ClearUserCache(ManifoldPoint pt)
 {
     btPersistentManifold_clearUserCache(Native, pt.Native);
 }
 public static OpenTK.Vector3 GetNormalWorldOnB(this ManifoldPoint obj)
 {
     OpenTK.Vector3 value;
     GetNormalWorldOnB(obj, out value);
     return(value);
 }
示例#45
0
 public void ReplaceContactPoint(ManifoldPoint newPoint, int insertIndex)
 {
     btPersistentManifold_replaceContactPoint(Native, newPoint.Native, insertIndex);
 }
 public static OpenTK.Vector3 GetPositionWorldOnA(this ManifoldPoint obj)
 {
     OpenTK.Vector3 value;
     GetPositionWorldOnA(obj, out value);
     return(value);
 }
        protected bool RecoverFromPenetration(CollisionWorld collisionWorld)
        {
            // Here we must refresh the overlapping paircache as the penetrating movement itself or the
            // previous recovery iteration might have used setWorldTransform and pushed us into an object
            // that is not in the previous cache contents from the last timestep, as will happen if we
            // are pushed into a new AABB overlap. Unhandled this means the next convex sweep gets stuck.
            //
            // Do this by calling the broadphase's setAabb with the moved AABB, this will update the broadphase
            // paircache and the ghostobject's internal paircache at the same time.    /BW

            Vector3 minAabb, maxAabb;

            m_convexShape.GetAabb(m_ghostObject.WorldTransform, out minAabb, out maxAabb);
            collisionWorld.Broadphase.SetAabbRef(m_ghostObject.BroadphaseHandle,
                                                 ref minAabb,
                                                 ref maxAabb,
                                                 collisionWorld.Dispatcher);

            bool penetration = false;

            collisionWorld.Dispatcher.DispatchAllCollisionPairs(m_ghostObject.OverlappingPairCache, collisionWorld.DispatchInfo, collisionWorld.Dispatcher);

            m_currentPosition = m_ghostObject.WorldTransform.Origin;

            //  btScalar maxPen = btScalar(0.0);
            for (int i = 0; i < m_ghostObject.OverlappingPairCache.NumOverlappingPairs; i++)
            {
                m_manifoldArray.Clear();

                BroadphasePair collisionPair = m_ghostObject.OverlappingPairCache.OverlappingPairArray[i];

                CollisionObject obj0 = collisionPair.Proxy0.ClientObject as CollisionObject;
                CollisionObject obj1 = collisionPair.Proxy1.ClientObject as CollisionObject;

                if ((obj0 != null && !obj0.HasContactResponse) || (obj1 != null && !obj1.HasContactResponse))
                {
                    continue;
                }

                if (!NeedsCollision(obj0, obj1))
                {
                    continue;
                }

                if (collisionPair.Algorithm != null)
                {
                    collisionPair.Algorithm.GetAllContactManifolds(m_manifoldArray);
                }

                for (int j = 0; j < m_manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = m_manifoldArray[j];
                    float directionSign         = manifold.Body0 == m_ghostObject ? -1.0f : 1.0f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);

                        float dist = pt.Distance;

                        if (dist < -m_maxPenetrationDepth)
                        {
                            // to do: cause problems on slopes, not sure if it is needed
                            //if (dist < maxPen)
                            //{
                            //  maxPen = dist;
                            //  m_touchingNormal = pt.m_normalWorldOnB * directionSign;//??

                            //}
                            m_currentPosition += pt.NormalWorldOnB * directionSign * dist * 0.2f;
                            penetration        = true;
                        }
                        else
                        {
                            //System.Console.WriteLine("touching " + dist);
                        }
                    }

                    //manifold.ClearManifold();
                }
            }
            Matrix newTrans = m_ghostObject.WorldTransform;

            newTrans.Origin = m_currentPosition;
            m_ghostObject.WorldTransform = newTrans;
            //System.Console.WriteLine("m_touchingNormal = " + m_touchingNormal);
            return(penetration);
        }
        /// <summary>
        /// Fired every frame when an object is inside another object.
        /// </summary>
        bool ContactAdded(ManifoldPoint point, CollisionObject objectA, int partId0, int index0, CollisionObject objectB, int partId1, int index1)
        {
            // if one of the two objects is deactivated, we don't care
            if (!objectA.IsActive && !objectB.IsActive)
                return false;

            int objectACollisionGroup = (int) objectA.GetCollisionGroup();
            int objectBCollisionGroup = (int) objectB.GetCollisionGroup();

            // do we have any events that care about these groups? if not, then skip this collision pair
            if (reporters[objectACollisionGroup, objectBCollisionGroup] == null
                    && reporters[objectBCollisionGroup, objectACollisionGroup] == null)
                return false;

            // when the actual bodies are touching and not just their AABB's
            if (point.Distance <= 0.05) {
                // get the lists
                HashSet<CollisionObject> objectAList = GetCollisionListForObject(objectA, CurrentlyCollidingWith),
                                         newObjectAList = GetCollisionListForObject(objectA, NewCollidingWith),
                                         objectBList = GetCollisionListForObject(objectB, CurrentlyCollidingWith),
                                         newObjectBList = GetCollisionListForObject(objectB, NewCollidingWith);

                // see if the other object is in there
                if (!objectAList.Contains(objectB) || !objectBList.Contains(objectA)) {
                    /*
                     * if it isn't, add it! this means we have a new collision and need to fire off an event!
                     * okay now we need to get the point where it contacted!
                     * Limitation with this system: if we're already colliding with B and then collide with it in a different place without
                     * leaving the original place, we won't get another event. Why? Well because what if something's sliding along?
                     * Don't need loads of events for that
                     */
                    // make sure we add it to our collections! The hashset means we don't have to worry about duplicates
                    objectAList.Add(objectB);
                    objectBList.Add(objectA);
                    newObjectAList.Add(objectB);
                    newObjectBList.Add(objectA);

                    // update the dictionaries (is this necessary?)
                    CurrentlyCollidingWith[objectA] = objectAList;
                    CurrentlyCollidingWith[objectB] = objectBList;
                    NewCollidingWith[objectA] = newObjectAList;
                    NewCollidingWith[objectB] = newObjectBList;

                    Vector3 pos = point.PositionWorldOnA.MidPoint(point.PositionWorldOnB);
                    Vector3 normal = point.NormalWorldOnB;

                    // woop woop they started touching, so we fire off an event!
                    SetupAndFireEvent(objectA, objectB, pos, normal, ObjectTouchingFlags.StartedTouching);
                }
                else {
                    // already in the dictionary, no new collisions. Add it to the new dictionary anyway though, because if we don't then it thinks
                    // they stopped colliding. Which we don't want!
                    newObjectAList.Add(objectB);
                    newObjectBList.Add(objectA);

                    NewCollidingWith[objectA] = newObjectAList;
                    NewCollidingWith[objectB] = newObjectBList;
                }
            }
            // This means they're still inside each other's AABB's, but they aren't actually touching
            //else {

            //}

            return false;
        }