/// <summary> /// Pefrorms a sweep test using a collider shape and stops at the first hit /// </summary> /// <param name="shape">The shape.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> /// <exception cref="System.Exception">This kind of shape cannot be used for a ShapeSweep.</exception> public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to) { var sh = shape.InternalShape as BulletSharp.ConvexShape; if (sh == null) { throw new Exception("This kind of shape cannot be used for a ShapeSweep."); } var result = new HitResult(); //result.Succeded is false by default using (var rcb = new BulletSharp.ClosestConvexResultCallback(from.TranslationVector, to.TranslationVector)) { collisionWorld.ConvexSweepTest(sh, from, to, rcb); if (rcb.HitCollisionObject == null) { return(result); } result.Succeeded = true; result.Collider = aliveColliders[rcb.HitCollisionObject]; result.Normal = rcb.HitNormalWorld; result.Point = rcb.HitPointWorld; } return(result); }
/// <summary> /// Pefrorms a sweep test using a collider shape and stops at the first hit /// </summary> /// <param name="shape">The shape.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> /// <exception cref="System.Exception">This kind of shape cannot be used for a ShapeSweep.</exception> public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to) { var sh = shape.InternalShape as BulletSharp.ConvexShape; if (sh == null) { throw new Exception("This kind of shape cannot be used for a ShapeSweep."); } var result = new HitResult(); //result.Succeded is false by default var fullDistance = (to.TranslationVector - from.TranslationVector).LengthSquared(); using (var rcb = new BulletSharp.ClosestConvexResultCallback(from.TranslationVector, to.TranslationVector)) { collisionWorld.ConvexSweepTest(sh, from, to, rcb); if (rcb.HitCollisionObject == null) { return(result); } result.Succeeded = true; result.Collider = (PhysicsComponent)rcb.HitCollisionObject.UserObject; result.Normal = rcb.HitNormalWorld; result.Point = rcb.HitPointWorld; result.FullLength = fullDistance; result.StartPoint = from.TranslationVector; result.NormalizedDistance = -1.0f; } return(result); }
/// <summary> /// Pefrorms a sweep test using a collider shape and stops at the first hit /// </summary> /// <param name="shape">The shape.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> /// <exception cref="System.Exception">This kind of shape cannot be used for a ShapeSweep.</exception> public HitResult ShapeSweep(ColliderShape shape, Matrix from, Matrix to) { var sh = shape.InternalShape as BulletSharp.ConvexShape; if (sh == null) throw new Exception("This kind of shape cannot be used for a ShapeSweep."); var result = new HitResult(); //result.Succeded is false by default using (var rcb = new BulletSharp.ClosestConvexResultCallback(from.TranslationVector, to.TranslationVector)) { collisionWorld.ConvexSweepTest(sh, from, to, rcb); if (rcb.HitCollisionObject == null) return result; result.Succeeded = true; result.Collider = (PhysicsComponent)rcb.HitCollisionObject.UserObject; result.Normal = rcb.HitNormalWorld; result.Point = rcb.HitPointWorld; } return result; }