/// <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) { TransformStateBase transformState = (TransformStateBase)sceneCtx.GraphicsStateStack.Current[TransformStateBase.StateSetIndex]; LightsState.LightSpot light = new LightsState.LightSpot(); SetLightParameters(sceneCtx, light); IModelMatrix worldModel = transformState.LocalModelView; IMatrix3x3 normalMatrix = worldModel.GetComplementMatrix(3, 3).GetInverseMatrix().Transpose(); light.Direction = ((Vertex3f)normalMatrix.Multiply((Vertex3f)Direction)).Normalized; light.Position = (Vertex3f)worldModel.Multiply(Vertex3f.Zero); light.AttenuationFactors = AttenuationFactors; light.FallOff = new Vertex2f((float)Math.Cos(Angle.ToRadians(FalloffAngle)), FalloffExponent); // Shadow mapping if (_ShadowMap != null && _ShadowViewMatrix != null) { // Determined later: light.ShadowMapIndex light.ShadowMapMvp.Set(_ShadowViewMatrix); light.ShadowMap2D = _ShadowMap; } else { light.ShadowMapIndex = -1; light.ShadowMap2D = null; } return(light); }
/// <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); TransformStateBase transformState = (TransformStateBase)sceneCtx.GraphicsStateStack.Current[TransformStateBase.StateSetIndex]; IMatrix3x3 normalMatrix = transformState.NormalMatrix; light.Direction = ((Vertex3f)normalMatrix.Multiply((Vertex3f)Direction)).Normalized; light.HalfVector = (Vertex3f.UnitZ + light.Direction).Normalized; return(light); }
/// <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); }
static void Main(string[] args) { Console.WriteLine("I want to find a solution of system of:\n 1) TWO linear equations \n 2) THREE linear equations"); int userChoice = Convert.ToInt32(Console.ReadLine()); if (userChoice == 1) { double x1; double x2; Equation eq = new Equation(); IMatrix2x2 eq2 = (IMatrix2x2)eq; eq2.SetValues(ref eq); eq2.Solution(out x1, out x2); Console.WriteLine(); eq2.EquationOutput(); Console.WriteLine(); Console.WriteLine($"x = {x1}, y = {x2}"); } else if (userChoice == 2) { double x1; double x2; double x3; Equation eq = new Equation(); IMatrix3x3 eq3 = (IMatrix3x3)eq; eq3.SetValues(ref eq); eq3.Solution(out x1, out x2, out x3); Console.WriteLine(); eq3.EquationOutput(); Console.WriteLine($"x = {x1}, y = {x2}, z = {x3}"); } else { Console.WriteLine("Try again!"); } }
/// <summary> /// Set uniform state variable (variant type). /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for operations. /// </param> /// <param name="uniformName"> /// A <see cref="String"/> that specify the variable name in the shader source. /// </param> /// <param name="m"> /// A <see cref="IMatrix3x3"/> holding the uniform variabile data. /// </param> public void SetVariantUniform(GraphicsContext ctx, string uniformName, IMatrix3x3 m) { if (ctx == null) { throw new ArgumentNullException("ctx"); } UniformBinding uniform = GetUniform(uniformName); switch (uniform.UniformType) { case ShaderUniformType.Mat3x3: SetUniform(ctx, uniformName, (Matrix3x3)m); break; case ShaderUniformType.DoubleMat3x3: SetUniform(ctx, uniformName, (MatrixDouble3x3)m); break; default: throw new ShaderException("unable to set double-precision floating-point matrix 3x3 data to uniform of type {0}", uniform.UniformType); } }
/// <summary> /// Set uniform state variable (variant type). /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for operations. /// </param> /// <param name="uniformName"> /// A <see cref="String"/> that specify the variable name in the shader source. /// </param> /// <param name="m"> /// A <see cref="IMatrix3x3"/> holding the uniform variabile data. /// </param> public void SetVariantUniform(GraphicsContext ctx, string uniformName, IMatrix3x3 m) { if (ctx == null) throw new ArgumentNullException("ctx"); UniformBinding uniform = GetUniform(uniformName); switch (uniform.UniformType) { case ShaderUniformType.Mat3x3: SetUniform(ctx, uniformName, (Matrix3x3)m); break; case ShaderUniformType.DoubleMat3x3: SetUniform(ctx, uniformName, (MatrixDouble3x3)m); break; default: throw new ShaderException("unable to set double-precision floating-point matrix 3x3 data to uniform of type {0}", uniform.UniformType); } }