/// <summary> /// Pefrorms a sweep test using a collider shape and never stops until "to" /// </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 List<HitResult> ShapeSweepPenetrating(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 List<HitResult>(); using (var rcb = new BulletSharp.AllHitsConvexResultCallback()) { collisionWorld.ConvexSweepTest(sh, from, to, rcb); var count = rcb.CollisionObjects.Count; for (var i = 0; i < count; i++) { var singleResult = new HitResult { Succeeded = true, Collider = (PhysicsComponent)rcb.CollisionObjects[i].UserObject, Normal = rcb.HitNormalWorld[i], Point = rcb.HitPointWorld[i] }; result.Add(singleResult); } } return result; }
/// <summary> /// Raycasts penetrating any shape the ray encounters. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> public List<HitResult> RaycastPenetrating(Vector3 from, Vector3 to) { var result = new List<HitResult>(); using (var rcb = new BulletSharp.AllHitsRayResultCallback(from, to)) { collisionWorld.RayTest(ref from, ref to, rcb); var count = rcb.CollisionObjects.Count; for (var i = 0; i < count; i++) { var singleResult = new HitResult { Succeeded = true, Collider = (PhysicsComponent)rcb.CollisionObjects[i].UserObject, Normal = rcb.HitNormalWorld[i], Point = rcb.HitPointWorld[i] }; result.Add(singleResult); } } 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; }
/// <summary> /// Raycasts and stops at the first hit. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> public HitResult Raycast(Vector3 from, Vector3 to) { var result = new HitResult(); //result.Succeded is false by default using (var rcb = new BulletSharp.ClosestRayResultCallback(from, to)) { collisionWorld.RayTest(ref from, ref to, rcb); if (rcb.CollisionObject == null) return result; result.Succeeded = true; result.Collider = (PhysicsComponent)rcb.CollisionObject.UserObject; result.Normal = rcb.HitNormalWorld; result.Point = rcb.HitPointWorld; } return result; }