/// <summary> /// Called when show lights is changed. /// </summary> protected void OnShowLightsChanged() { this.lightsVisual.Children.Clear(); if (this.ShowLights) { foreach (var light in this.lightGroup.Children) { var pl = light as PointLight; if (pl != null) { var sphere = new SphereVisual3D(); sphere.BeginEdit(); sphere.Center = pl.Position; sphere.Radius = 1.0; sphere.Fill = new SolidColorBrush(pl.Color); sphere.EndEdit(); this.lightsVisual.Children.Add(sphere); } var dl = light as DirectionalLight; if (dl != null) { var dir = dl.Direction; dir.Normalize(); var target = new Point3D(0, 0, 0); var source = target - (dir * 20); var p2 = source + (dir * 10); var sphere = new SphereVisual3D(); sphere.BeginEdit(); sphere.Center = source; sphere.Radius = 1.0; sphere.Fill = new SolidColorBrush(dl.Color); sphere.EndEdit(); this.lightsVisual.Children.Add(sphere); var arrow = new ArrowVisual3D(); arrow.BeginEdit(); arrow.Point1 = source; arrow.Point2 = p2; arrow.Diameter = 0.5; arrow.Fill = new SolidColorBrush(dl.Color); arrow.EndEdit(); this.lightsVisual.Children.Add(arrow); } var al = light as AmbientLight; if (al != null) { var pos = new Point3D(0, 0, 20); this.lightsVisual.Children.Add( new CubeVisual3D { Center = pos, SideLength = 1.0, Fill = new SolidColorBrush(al.Color) }); } } } }
/// <summary> /// Called when the light changed. /// </summary> protected virtual void OnLightChanged() { this.Children.Clear(); if (this.Light == null) { return; } var dl = this.Light as DirectionalLight; if (dl != null) { var arrow = new ArrowVisual3D(); double distance = 10; double length = 5; arrow.BeginEdit(); arrow.Point1 = new Point3D() + dl.Direction * distance; arrow.Point2 = arrow.Point1 - dl.Direction * length; arrow.Diameter = 0.1 * length; arrow.Fill = new SolidColorBrush(dl.Color); arrow.EndEdit(); this.Children.Add(arrow); } var sl = this.Light as SpotLight; if (sl != null) { var sphere = new SphereVisual3D(); sphere.BeginEdit(); sphere.Center = sl.Position; sphere.Fill = new SolidColorBrush(sl.Color); sphere.EndEdit(); this.Children.Add(sphere); var arrow = new ArrowVisual3D(); arrow.BeginEdit(); arrow.Point1 = sl.Position; arrow.Point2 = sl.Position + sl.Direction; arrow.Diameter = 0.1; arrow.EndEdit(); this.Children.Add(arrow); } var pl = this.Light as PointLight; if (pl != null) { var sphere = new SphereVisual3D(); sphere.BeginEdit(); sphere.Center = pl.Position; sphere.Fill = new SolidColorBrush(pl.Color); sphere.EndEdit(); this.Children.Add(sphere); } var al = this.Light as AmbientLight; }