anx.framework/ANX.Framework/Graphics/DirectionalLight.cs

90 lines
2.2 KiB
C#
Raw Normal View History

2011-10-31 05:36:24 +00:00
using System;
using ANX.Framework.NonXNA.Development;
2011-10-31 05:36:24 +00:00
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
2011-10-31 05:36:24 +00:00
namespace ANX.Framework.Graphics
{
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Untested)]
2011-10-31 05:36:24 +00:00
public sealed class DirectionalLight
{
#region Private
private Vector3 diffuseColor;
2011-10-31 05:36:24 +00:00
private Vector3 direction;
private Vector3 specularColor;
private EffectParameter directionParameter;
private EffectParameter diffuseColorParameter;
private EffectParameter specularColorParameter;
#endregion
2011-10-31 05:36:24 +00:00
#region Public
public bool Enabled { get; set; }
2011-10-31 05:36:24 +00:00
public Vector3 DiffuseColor
{
get { return diffuseColor; }
set
{
diffuseColor = value;
SetValueIfPossible(diffuseColorParameter, ref value);
}
}
2011-10-31 05:36:24 +00:00
public Vector3 Direction
{
get { return direction; }
set
{
direction = value;
SetValueIfPossible(directionParameter, ref value);
}
}
2011-10-31 05:36:24 +00:00
public Vector3 SpecularColor
{
get { return diffuseColor; }
set
{
specularColor = value;
SetValueIfPossible(specularColorParameter, ref value);
}
}
#endregion
2011-10-31 05:36:24 +00:00
#region Constructor
public DirectionalLight(EffectParameter directionParameter, EffectParameter diffuseColorParameter,
EffectParameter specularColorParameter, DirectionalLight cloneSource)
2011-10-31 05:36:24 +00:00
{
this.directionParameter = directionParameter;
this.diffuseColorParameter = diffuseColorParameter;
this.specularColorParameter = specularColorParameter;
2011-10-31 05:36:24 +00:00
if (cloneSource != null)
{
diffuseColor = cloneSource.diffuseColor;
direction = cloneSource.direction;
Enabled = cloneSource.Enabled;
specularColor = cloneSource.specularColor;
}
else
{
diffuseColor = Vector3.One;
direction = Vector3.Down;
specularColor = Vector3.Zero;
}
}
#endregion
#region SetValueIfPossible
private void SetValueIfPossible(EffectParameter parameter, ref Vector3 value)
{
if (Enabled && parameter != null)
parameter.SetValue(value);
}
#endregion
}
2011-10-31 05:36:24 +00:00
}