Example #1
0
        /// <summary>
        /// 把连续4个float值按照列优先的顺序转换为mat2
        /// </summary>
        /// <param name="values"></param>
        /// <param name="startIndex"></param>
        /// <returns></returns>
        public static mat2 ToMat2(this float[] values, int startIndex = 0)
        {
            mat2 result = new mat2(
                values.ToVec2(startIndex + 0), values.ToVec2(startIndex + 2));

            return(result);
        }
Example #2
0
        /// <summary>
        /// 把连续4个float值按照列优先的顺序转换为mat2
        /// </summary>
        /// <param name="values"></param>
        /// <param name="startIndex"></param>
        /// <returns></returns>
        public static mat2 ToMat2(this float[] values, int startIndex = 0)
        {
            mat2 result = new mat2(
                values.ToVec2(startIndex + 0), values.ToVec2(startIndex + 2));

            return result;
        }
Example #3
0
        /// <summary>
        /// Multiplies the <paramref name="lhs"/> matrix by the <paramref name="rhs"/> matrix.
        /// </summary>
        /// <param name="lhs">The LHS matrix.</param>
        /// <param name="rhs">The RHS matrix.</param>
        /// <returns>The product of <paramref name="lhs"/> and <paramref name="rhs"/>.</returns>
        public static mat2 operator *(mat2 lhs, mat2 rhs)
        {
            mat2 result = new mat2(
                new vec2(
                    lhs[0][0] * rhs[0][0] + lhs[1][0] * rhs[0][1],
                    lhs[0][1] * rhs[0][0] + lhs[1][1] * rhs[0][1]
                    ),
                new vec2(
                    lhs[0][0] * rhs[1][0] + lhs[1][0] * rhs[1][1],
                    lhs[0][1] * rhs[1][0] + lhs[1][1] * rhs[1][1]
                    )
                );

            return(result);
        }
        public bool GetUniformMat2ArrayValue(string varNameInShader, out mat2[] value)
        {
            value = null;
            bool gotUniform = false;

            foreach (var item in this.uniformVariables)
            {
                if (item.VarName == varNameInShader)
                {
                    value = (item as UniformMat2Array).Value;
                    gotUniform = true;
                    break;
                }
            }

            return gotUniform;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="varNameInShader"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool GetUniformMat2ArrayValue(string varNameInShader, out mat2[] value)
        {
            //if ((!this.Initialized) && (!this.Initializing)) { this.Initialize(); }

            value = null;
            bool gotUniform = false;

            foreach (UniformVariable item in this.uniformVariables)
            {
                if (item.VarName == varNameInShader)
                {
                    value = (item as UniformMat2Array).Value.Array;
                    gotUniform = true;
                    break;
                }
            }

            return gotUniform;
        }
Example #6
0
        internal override bool SetValue(ValueType value)
        {
            if (value.GetType() != typeof(mat2))
            {
                throw new ArgumentException(string.Format("[{0}] not match [{1}]'s value.",
                                                          value.GetType().Name, this.GetType().Name));
            }

            var v = (mat2)value;

            if (v != this.value)
            {
                this.value   = v;
                this.Updated = true;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool SetUniform(string varNameInShader, mat2[] value)
        {
            bool gotUniform = false;
            bool updated = false;
            if (value.Length <= 0) { return updated; }

            foreach (var item in this.uniformVariables)
            {
                if (item.VarName == varNameInShader)
                {
                    (item as UniformMat2Array).Value = value;
                    updated = true;
                    gotUniform = true;
                    break;
                }
            }

            if (!gotUniform)
            {
                int location = ShaderProgram.GetUniformLocation(varNameInShader);
                if (location < 0)
                {
                    throw new Exception(string.Format(
                        "uniform variable [{0}] not exists!", varNameInShader));
                }

                var variable = GetVariableArray(value, varNameInShader) as UniformMat2Array;
                variable.Value = value;
                this.uniformVariables.Add(variable);
                updated = true;
            }

            return updated;
        }
Example #8
0
        /// <summary>
        /// Multiplies the <paramref name="lhs"/> matrix by the <paramref name="rhs"/> matrix.
        /// </summary>
        /// <param name="lhs">The LHS matrix.</param>
        /// <param name="rhs">The RHS matrix.</param>
        /// <returns>The product of <paramref name="lhs"/> and <paramref name="rhs"/>.</returns>
        public static mat2 operator *(mat2 lhs, mat2 rhs)
        {
            mat2 result = new mat2(
                new vec2(
                    lhs[0][0] * rhs[0][0] + lhs[1][0] * rhs[0][1],
                    lhs[0][1] * rhs[0][0] + lhs[1][1] * rhs[0][1]
                    ),
                new vec2(
                    lhs[0][0] * rhs[1][0] + lhs[1][0] * rhs[1][1],
                    lhs[0][1] * rhs[1][0] + lhs[1][1] * rhs[1][1]
                    )
                    );

            return result;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="varNameInShader"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetUniform(string varNameInShader, mat2[] value)
        {
            //if ((!this.Initialized) && (!this.Initializing)) { this.Initialize(); }

            bool gotUniform = false;
            bool updated = false;
            if (value.Length <= 0) { return updated; }

            foreach (UniformVariable item in this.uniformVariables)
            {
                if (item.VarName == varNameInShader)
                {
                    (item as UniformMat2Array).Value = new NoisyArray<mat2>(value);
                    updated = true;
                    gotUniform = true;
                    break;
                }
            }

            if (!gotUniform)
            {
                //int location = Program.GetUniformLocation(varNameInShader);
                //if (location < 0)
                {
                    //throw new Exception(string.Format(
                    //"niform variable [{0}] not exists! Remember to invoke RendererBase.Initialize(); before this method.", varNameInShader));
                }

                var variable = GetVariableArray(value, varNameInShader) as UniformMat2Array;
                variable.Value = new NoisyArray<mat2>(value);
                this.uniformVariables.Add(variable);
                updated = true;
            }

            return updated;
        }