/Controls/HelixToolkit.Wpf/Visual3Ds/LightSetups/SunLight.cs
https://bitbucket.org/kubrakms/thermalconductivity · C# · 151 lines · 79 code · 24 blank · 48 comment · 0 complexity · fd4321eade879a8b639efef3093efe5a MD5 · raw file
- // --------------------------------------------------------------------------------------------------------------------
- // <copyright file="SunLight.cs" company="Helix 3D Toolkit">
- // http://helixtoolkit.codeplex.com, license: Ms-PL
- // </copyright>
- // --------------------------------------------------------------------------------------------------------------------
- namespace HelixToolkit.Wpf
- {
- using System.Windows;
- using System.Windows.Media;
- using System.Windows.Media.Media3D;
- /// <summary>
- /// A visual element that contains a "sunlight" light model.
- /// </summary>
- public class SunLight : LightSetup
- {
- #region Constants and Fields
- /// <summary>
- /// The altitude property.
- /// </summary>
- public static readonly DependencyProperty AltitudeProperty = DependencyProperty.Register(
- "Altitude", typeof(double), typeof(SunLight), new UIPropertyMetadata(60.0, SetupChanged));
- /// <summary>
- /// The ambient property.
- /// </summary>
- public static readonly DependencyProperty AmbientProperty = DependencyProperty.Register(
- "Ambient", typeof(double), typeof(SunLight), new UIPropertyMetadata(0.4, SetupChanged));
- /// <summary>
- /// The azimuth property.
- /// </summary>
- public static readonly DependencyProperty AzimuthProperty = DependencyProperty.Register(
- "Azimuth", typeof(double), typeof(SunLight), new UIPropertyMetadata(130.0, SetupChanged));
- /// <summary>
- /// The brightness property.
- /// </summary>
- public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register(
- "Brightness", typeof(double), typeof(SunLight), new UIPropertyMetadata(0.6, SetupChanged));
- /// <summary>
- /// The altitude axis.
- /// </summary>
- private readonly Vector3D AltitudeAxis = new Vector3D(0, 1, 0);
- /// <summary>
- /// The azimuth axis.
- /// </summary>
- private readonly Vector3D AzimuthAxis = new Vector3D(0, 0, 1);
- #endregion
- #region Public Properties
- /// <summary>
- /// Gets or sets the altitude angle (degrees).
- /// </summary>
- /// <value>The altitude.</value>
- public double Altitude
- {
- get
- {
- return (double)this.GetValue(AltitudeProperty);
- }
- set
- {
- this.SetValue(AltitudeProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the ambient lightness.
- /// </summary>
- /// <value>The ambient.</value>
- public double Ambient
- {
- get
- {
- return (double)this.GetValue(AmbientProperty);
- }
- set
- {
- this.SetValue(AmbientProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the azimuth angle (degrees).
- /// </summary>
- /// <value>The azimuth.</value>
- public double Azimuth
- {
- get
- {
- return (double)this.GetValue(AzimuthProperty);
- }
- set
- {
- this.SetValue(AzimuthProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the brightness.
- /// </summary>
- /// <value>The brightness.</value>
- public double Brightness
- {
- get
- {
- return (double)this.GetValue(BrightnessProperty);
- }
- set
- {
- this.SetValue(BrightnessProperty, value);
- }
- }
- #endregion
- #region Methods
- /// <summary>
- /// Adds the lights to the element.
- /// </summary>
- /// <param name="lightGroup">
- /// The light group.
- /// </param>
- protected override void AddLights(Model3DGroup lightGroup)
- {
- var t1 = new RotateTransform3D(new AxisAngleRotation3D(this.AzimuthAxis, this.Azimuth));
- var t2 = new RotateTransform3D(new AxisAngleRotation3D(this.AltitudeAxis, this.Altitude));
- var dir = t1.Transform(t2.Transform(new Vector3D(1, 0, 0)));
- var i = (byte)(255 * this.Brightness);
- lightGroup.Children.Add(new DirectionalLight(Color.FromRgb(i, i, i), dir));
- var ai = (byte)(255 * this.Ambient);
- lightGroup.Children.Add(new AmbientLight(Color.FromRgb(ai, ai, ai)));
- }
- #endregion
- }
- }