public static void SetLaserLength(Scene scene, Laserbeam beam) { Level level = scene as Level; beam.Length = MaxBeamLength(level, beam); float shortestWidth = MaxBeamLength(level, beam); foreach (Solid s in scene.Tracker.GetEntities <Solid>()) { if (beam.CollideCheck(s)) { if (s.Collider is Grid) { shortestWidth = Math.Min(shortestWidth, GetLaserLengthDACOnGrid(beam, s.Collider as Grid, shortestWidth)); } else { shortestWidth = Math.Min(shortestWidth, LengthCalculatingFunctions[beam.Direction](beam, s.Collider)); } } } foreach (LaserDetectorActor entity in scene.Tracker.GetEntities <LaserDetectorActor>()) { Collider origCollider = entity.Collider; Collider collider = entity.GetLaserBlockingCollider(beam); ColliderList colliderList = collider as ColliderList; if (colliderList == null) { entity.Collider = collider; if (beam.CollideCheck(entity)) { shortestWidth = Math.Min(shortestWidth, LengthCalculatingFunctions[beam.Direction](beam, collider)); } } else { foreach (Collider c in colliderList.colliders) { entity.Collider = c; if (beam.CollideCheck(entity)) { shortestWidth = Math.Min(shortestWidth, LengthCalculatingFunctions[beam.Direction](beam, c)); } } } entity.Collider = origCollider; } beam.Length = shortestWidth; }
public static void SetLaserLengthDAQ(Scene scene, Laserbeam beam) { Level level = scene as Level; float maxLength = LaserHelper.MaxBeamLength(level, beam); float offset = maxLength / 2f; beam.Length = offset; while (offset >= 1f) { bool colliding = beam.CollideCheck <Solid>() || LaserHelper.LaserBlockingCheck(scene, beam); int sign = colliding ? -1 : 1; offset /= 2f; beam.Length += sign * offset; } beam.Length = (float)Math.Round(beam.Length); }