/// <summary>
        /// Create the corresponding <see cref="LightsState.Light"/> for this object.
        /// </summary>
        /// <returns>
        /// It returns the <see cref="LightsState.Light"/> equivalent to this SceneObjectLight.
        /// </returns>
        public override LightsState.Light ToLight(GraphicsContext ctx, SceneGraphContext sceneCtx)
        {
            LightsState.LightDirectional light = new LightsState.LightDirectional();

            SetLightParameters(sceneCtx, light);

            TransformState transformState = (TransformState)sceneCtx.GraphicsStateStack.Current[TransformState.StateSetIndex];
            Matrix3x3f     normalMatrix   = transformState.NormalMatrix;

            light.Direction  = (normalMatrix * (Vertex3f)Direction).Normalized;
            light.HalfVector = (Vertex3f.UnitZ + light.Direction).Normalized;

            return(light);
        }
Beispiel #2
0
        /// <summary>
        /// Create the corresponding <see cref="LightsState.Light"/> for this object.
        /// </summary>
        /// <returns>
        /// It returns the <see cref="LightsState.Light"/> equivalent to this SceneObjectLight.
        /// </returns>
        public override LightsState.Light ToLight(SceneGraphContext sceneCtx)
        {
            LightsState.LightDirectional light = new LightsState.LightDirectional();

            SetLightParameters(sceneCtx, light);

            // Note: avoiding to invert the view matrix twice
            IMatrix3x3 normalMatrix = sceneCtx.CurrentView.LocalModel.GetComplementMatrix(3, 3).Transpose();

            light.Direction  = ((Vertex3f)normalMatrix.Multiply((Vertex3f)Direction)).Normalized;
            light.HalfVector = (Vertex3f.UnitZ + light.Direction).Normalized;

            return(light);
        }