public ShadowHull CreateHull(float radius, float angle, Vector2 position, Vector2 scale, bool circlular = false) { ShadowHull hull; if (!circlular) { hull = ShadowHull.CreateRectangle(Vector2.One); } else { hull = ShadowHull.CreateCircle(radius, 20); } hull.Position = position; hull.Scale = scale; hull.Angle = angle; hull.MaxRadius = radius; Krypton.Hulls.Add(hull); return(hull); }
public static ShadowHull BuildHull(float size) { return(ShadowHull.CreateCircle(size, 20)); }
void rebuild( ) { _krypton.Lights.Clear( ); _krypton.Hulls.Clear( ); LayerEditor activeLayer = IoC.Model.ActiveLayer; if (activeLayer == null) { return; } activeLayer.OfType <LightEditor>( ).ForEach( light => { var props = (LightProperties)light.ItemProperties; Texture2D texture; if (props.TypeOfLight == TypeOfLight.Point) { texture = LightTextureBuilder.CreatePointLight(_game.GraphicsDevice, props.TextureSize); } else { texture = LightTextureBuilder.CreateConicLight(_game.GraphicsDevice, props.TextureSize, props.FieldOfView); } if (texture == null) { throw new InvalidOperationException(@"Cannot create light of type {0}.".FormatWith(props.TypeOfLight)); } _krypton.Lights.Add(new Light2D { Angle = props.Rotation, Color = props.Color, Intensity = props.Intensity, Fov = props.FieldOfView, Position = props.Position, IsOn = props.IsOn, Range = props.Range, ShadowType = convertShadowType(props.ShadowType), Texture = texture }); }); activeLayer.OfType <RectangularHullEditor>( ).ForEach( light => { var props = (RectangularHullProperties)light.ItemProperties; ShadowHull shadowHull = ShadowHull.CreateRectangle(new Vector2(props.Width, props.Height)); shadowHull.Angle = props.Rotation; shadowHull.Opacity = props.Opacity; shadowHull.Position = props.Position + new Vector2(props.Width / 2, props.Height / 2); shadowHull.Scale = props.Scale; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); activeLayer.OfType <CircularHullEditor>( ).ForEach( light => { var props = (CircularHullProperties)light.ItemProperties; ShadowHull shadowHull = ShadowHull.CreateCircle(props.Radius, props.Sides); shadowHull.Opacity = props.Opacity; shadowHull.Position = props.Position; shadowHull.Scale = props.Scale; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); activeLayer.OfType <ConvexHullEditor>( ).ForEach( light => { var props = (ConvexHullProperties)light.ItemProperties; Vector2[] worldPoints = props.WorldPoints.ToArray( ); // === DON'T SET THE POSITION!! === ShadowHull shadowHull = ShadowHull.CreateConvex(ref worldPoints); shadowHull.Opacity = props.Opacity; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); activeLayer.OfType <PreShapedConvexHullEditor>( ).ForEach( light => { var props = (ConvexHullProperties)light.ItemProperties; Vector2[] worldPoints = props.WorldPoints.ToArray( ); // === DON'T SET THE POSITION!! === ShadowHull shadowHull = ShadowHull.CreateConvex(ref worldPoints); shadowHull.Opacity = props.Opacity; shadowHull.Visible = props.Visible; _krypton.Hulls.Add(shadowHull); }); }