public static bool Raycast(Vector3 source, Vector3 destination, out RaycastHitInfo info) { if (_contextWorld == null) { Log.Core.Error("raycast attempted without world context!"); throw new InvalidOperationException("Raycast attempted without world context."); } BulletVector3 Bdestination = destination.ToBullet(); BulletVector3 Bsource = source.ToBullet(); using (var cb = new ClosestRayResultCallback(ref Bsource, ref Bdestination)) { _contextWorld.RayTestRef(ref Bsource, ref Bdestination, cb); if (cb.HasHit) { info = new RaycastHitInfo(cb.HitPointWorld.ToNumerics(), Vector3.Normalize(cb.HitNormalWorld.ToNumerics()), (RigidBodyComponent)cb.CollisionObject.UserObject, (ColliderComponent)cb.CollisionObject.CollisionShape.UserObject); return(true); } else { info = new RaycastHitInfo(destination, new Vector3(1.0f, 0.0f, 0.0f), null); return(false); } } }
public static bool Raycast(Vector3 source, Vector3 direction, float maxDistance, out RaycastHitInfo info) { BulletVector3 Bdestination = (source + (direction * maxDistance)).ToBullet(); BulletVector3 Bsource = source.ToBullet(); using (var cb = new ClosestRayResultCallback(ref Bsource, ref Bdestination)) { _contextWorld.RayTestRef(ref Bsource, ref Bdestination, cb); if (cb.HasHit) { info = new RaycastHitInfo(cb.HitPointWorld.ToNumerics(), Vector3.Normalize(cb.HitNormalWorld.ToNumerics()), (RigidBodyComponent)cb.CollisionObject.UserObject); return(true); } else { info = new RaycastHitInfo(Bdestination.ToNumerics(), new Vector3(1.0f, 0.0f, 0.0f), null); return(false); } } }