private void SetD3D9Light( int index, Light light )
{
if ( light == null )
{
ActiveD3D9Device.EnableLight( index, false );
}
else
{
var nlight = new D3D.Light();
switch ( light.Type )
{
case LightType.Point:
nlight.Type = D3D.LightType.Point;
break;
case LightType.Directional:
nlight.Type = D3D.LightType.Directional;
break;
case LightType.Spotlight:
nlight.Type = D3D.LightType.Spot;
nlight.Falloff = light.SpotlightFalloff;
nlight.Theta = Utility.DegreesToRadians( light.SpotlightInnerAngle );
nlight.Phi = Utility.DegreesToRadians( light.SpotlightOuterAngle );
break;
} // switch
// light colors
nlight.Diffuse = D3DHelper.ToColor( light.Diffuse );
nlight.Specular = D3DHelper.ToColor( light.Specular );
Vector3 vec;
if ( light.Type != LightType.Directional )
{
vec = light.DerivedPosition;
nlight.Position = new DX.Vector3( vec.x, vec.y, vec.z );
}
if ( light.Type != LightType.Point )
{
vec = light.DerivedDirection;
nlight.Direction = new DX.Vector3( vec.x, vec.y, vec.z );
}
// atenuation settings
nlight.Range = light.AttenuationRange;
nlight.Attenuation0 = light.AttenuationConstant;
nlight.Attenuation1 = light.AttenuationLinear;
nlight.Attenuation2 = light.AttenuationQuadratic;
ActiveD3D9Device.SetLight( index, nlight );
ActiveD3D9Device.EnableLight( index, true );
} // if
}