Ejemplo n.º 1
0
        public void CheckMatrixReferenceEquality()
        {
            vec2 v2_1 = new vec2(1, 0);
            vec2 v2_2 = new vec2(1, 0);
            vec2 v2_3 = new vec2(0, 0);
            mat2 m2_1 = new mat2(v2_1, v2_2);
            mat2 m2_2 = new mat2(v2_1, v2_2);
            mat2 m2_3 = new mat2(v2_1, v2_3);

            vec3 v3_1 = new vec3(1, 0, 1);
            vec3 v3_2 = new vec3(1, 0, 1);
            vec3 v3_3 = new vec3(0, 0, 1);
            mat3 m3_1 = new mat3(v3_1, v3_2, v3_2);
            mat3 m3_2 = new mat3(v3_1, v3_2, v3_2);
            mat3 m3_3 = new mat3(v3_1, v3_2, v3_3);


            vec4 v4_1 = new vec4(1, 0, 1, 1);
            vec4 v4_2 = new vec4(1, 0, 1, 1);
            vec4 v4_3 = new vec4(0, 0, 1, 1);
            mat4 m4_1 = new mat4(v4_1, v4_2, v4_2, v4_2);
            mat4 m4_2 = new mat4(v4_1, v4_2, v4_2, v4_2);
            mat4 m4_3 = new mat4(v4_1, v4_2, v4_2, v4_3);

            Assert.AreEqual(m2_1.GetHashCode(), m2_2.GetHashCode(), "Error Hashcodes are not the Same");
            Assert.AreNotEqual(m2_1.GetHashCode(), m2_3.GetHashCode(), "Error Hashcodes are the Same");
            Assert.AreEqual(m3_1.GetHashCode(), m3_2.GetHashCode(), "Error Hashcodes are not the Same");
            Assert.AreNotEqual(m3_1.GetHashCode(), m3_3.GetHashCode(), "Error Hashcodes are the Same");
            Assert.AreEqual(m4_1.GetHashCode(), m4_2.GetHashCode(), "Error Hashcodes are not the Same");
            Assert.AreNotEqual(m4_1.GetHashCode(), m4_3.GetHashCode(), "Error Hashcodes are the Same");
        }
Ejemplo n.º 2
0
        public void Simple()
        {
            /*
             * 1 2
             * 3 4
             */
            var m1 = new mat2(1, 3, 2, 4);

            /*
             * 5 7
             * 6 8
             */
            var m2 = new mat2(5, 6, 7, 8);

            /*
             * 1 2 * 5 7 = 17 23
             * 3 4   6 8   39 53
             */
            var r = m1 * m2;

            Assert.AreEqual(r.m00, 17);
            Assert.AreEqual(r.m01, 39);
            Assert.AreEqual(r.m10, 23);
            Assert.AreEqual(r.m11, 53);
        }
Ejemplo n.º 3
0
Archivo: vmath.cs Proyecto: maihd/vmath
 public DebuggerProxy(mat2 m)
 {
     m00 = m.m00;
     m01 = m.m01;
     m10 = m.m10;
     m11 = m.m11;
 }
Ejemplo n.º 4
0
        public static int Main(string[] args)
        {
            mat2 m = (1, 2, 0, -1);

            poly p1 = (0, 0, 0, 2);
            poly p2 = (0, 0, 3);

            var r0 = p2.Derivative;
            var r1 = p1 << 1;
            var r2 = p1 >> 1;
            var r3 = p1 + p2;
            var r4 = p1 - p2;
            var r5 = p1 * p2;
            var r6 = p1 / p2;
            var r7 = p1 % p2;


            mat3 mat = (
                1, 1, 1,
                1, 0, 1,
                1, 0, 1
                );
            vec3 b = (0, 4, 2);
            var  x = mat.Solve(b);

            poly p3 = (-1, 1);
            poly p4 = (-1, 0, 1);
            poly p5 = (-1, 0, 0, 1);
            poly p6 = (0, 0, 0, 0, 0, 0, 1);
            poly p7 = (2, 1, 8, 3);

            return(0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the transposed matrix.
        /// <para>获取转置矩阵。</para>
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public static mat2 transpose(mat2 m)
        {
            vec2 col0 = m.col0;
            vec2 col1 = m.col1;

            return(new mat2(
                       new vec2(col0.x, col1.x),
                       new vec2(col0.y, col1.y)
                       ));
        }
Ejemplo n.º 6
0
        internal override void 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));
            }

            this.Value = (mat2)value;
        }
Ejemplo n.º 7
0
 public void Set(string name, mat2 val, bool transpose = false, bool keep_layout = true)
 {
     if (Values.TryGetValue(name, out var v))
     {
         v.Set(val, transpose, keep_layout);
     }
     else
     {
         Values.Add(name, new Value(val, transpose)); Keys.AddLast(name);
     }
 }
Ejemplo n.º 8
0
        public override void mainImage(out vec4 fragColor, vec2 fragCoord)
        {
            //get coords and direction
            vec2 uv = fragCoord.xy / iResolution.xy - .5f;

            uv.y *= iResolution.y / iResolution.x;
            vec3  dir  = new vec3(uv * zoom, 1f);
            float time = iGlobalTime * speed + .25f;

            //mouse rotation
            float a1   = .5f + iMouse.x / iResolution.x * 2f;
            float a2   = .8f + iMouse.y / iResolution.y * 2f;
            mat2  rot1 = new mat2(cos(a1), sin(a1), -sin(a1), cos(a1));
            mat2  rot2 = new mat2(cos(a2), sin(a2), -sin(a2), cos(a2));

            dir.xz *= rot1;
            dir.xy *= rot2;
            vec3 from = new vec3(1f, .5f, 0.5f);

            from    += new vec3(time * 2f, time, -2f);
            from.xz *= rot1;
            from.xy *= rot2;

            //volumetric rendering
            float s = 0.1f, fade = 1f;
            vec3  v = new vec3(0f);

            for (int r = 0; r < volsteps; r++)
            {
                vec3 p = from + s * dir * .5f;
                p = abs(new vec3(tile) - mod(p, new vec3(tile * 2f))); // tiling fold
                float pa, a = pa = 0f;
                for (int i = 0; i < iterations; i++)
                {
                    p  = abs(p) / dot(p, p) - formuparam; // the magic formula
                    a += abs(length(p) - pa);             // absolute sum of average change
                    pa = length(p);
                }
                float dm = max(0f, darkmatter - a * a * .001f); //dark matter
                a *= a * a;                                     // add contrast
                if (r > 6)
                {
                    fade *= 1f - dm;        // dark matter, don't render near
                }
                //v+=vec3(dm,dm*.5,0.);
                v    += fade;
                v    += new vec3(s, s * s, s * s * s * s) * a * brightness * fade; // coloring based on distance
                fade *= distfading;                                                // distance fading
                s    += stepsize;
            }
            v         = mix(new vec3(length(v)), v, saturation); //color adjust
            fragColor = new vec4(v * .01f, 1f);
        }
Ejemplo n.º 9
0
 public static float[] serialize(this mat2 value, float[] array = null)
 {
     array = array ?? new float[4];
     if (array.Length != 4)
     {
         throw new ArgumentException("Invalid array length.");
     }
     for (var c = 0; c < 4; ++c)
     {
         array[c] = value[c / 2, c % 2];
     }
     return(array);
 }
Ejemplo n.º 10
0
        public void CanMultiplyByVector()
        {
            var m = new mat2(new[]
            {
                new vec2(1f, 2f),
                new vec2(3f, 4f)
            });
            var v = new vec2(5f, 6f);

            // 1 3 * 5 = 5  18 = 23
            // 2 4   6   10 24 = 34

            Assert.AreEqual(new vec2(23f, 34f), m * v, "Rank 2 Matrix * Vector results are incorrect.");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the inversed matrix.
        /// <para>获取逆矩阵。</para>
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public static mat2 inverse(mat2 m)
        {
            float OneOverDeterminant = (1f) / (
                +m[0][0] * m[1][1]
                - m[1][0] * m[0][1]);

            mat2 Inverse = new mat2(
                +m[1][1] * OneOverDeterminant,
                -m[0][1] * OneOverDeterminant,
                -m[1][0] * OneOverDeterminant,
                +m[0][0] * OneOverDeterminant);

            return Inverse;
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public static mat2 inverse(mat2 m)
        {
            float OneOverDeterminant = (1f) / (
                +m[0][0] * m[1][1]
                - m[1][0] * m[0][1]);

            mat2 Inverse = new mat2(
                +m[1][1] * OneOverDeterminant,
                -m[0][1] * OneOverDeterminant,
                -m[1][0] * OneOverDeterminant,
                +m[0][0] * OneOverDeterminant);

            return(Inverse);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// </summary>
        /// <param name="uniformName"></param>
        /// <param name="m"></param>
        public int glUniform(string uniformName, mat2 m)
        {
            int location = GetUniformLocation(uniformName);

            if (location >= 0)
            {
                if (glUniformMatrix2fv == null)
                {
                    glUniformMatrix2fv = OpenGL.GetDelegateFor <OpenGL.glUniformMatrix2fv>();
                }
                float[] array = m.ToArray();
                glUniformMatrix2fv(location, 1, false, array);
            }
            return(location);
        }
        /// <summary>
        /// </summary>
        /// <param name="uniformName"></param>
        /// <param name="m"></param>
        internal int glUniform(string uniformName, mat2 m)
        {
            int location = GetUniformLocation(uniformName);

            if (location >= 0)
            {
                if (glUniformMatrix2fv == null)
                {
                    glUniformMatrix2fv = GL.Instance.GetDelegateFor("glUniformMatrix2fv", GLDelegates.typeof_void_int_int_bool_floatN) as GLDelegates.void_int_int_bool_floatN;
                }
                float[] array = m.ToArray();
                glUniformMatrix2fv(location, 1, false, array);
            }
            return(location);
        }
Ejemplo n.º 15
0
        public void MatrixIsColumnMajor()
        {
            //  A pretty critical test as this is fundamental.
            var m = new mat2(new[] {
                new vec2(1f, 2f),
                new vec2(3f, 4f)
            });

            //  1 3
            //  2 4

            Assert.AreEqual(1f, m[0][0], "Matrix does not implement column major semantics");
            Assert.AreEqual(2f, m[0][1], "Matrix does not implement column major semantics");
            Assert.AreEqual(3f, m[1][0], "Matrix does not implement column major semantics");
            Assert.AreEqual(4f, m[1][1], "Matrix does not implement column major semantics");

            Assert.AreEqual(1f, m[0, 0], "Matrix does not implement column major semantics");
            Assert.AreEqual(2f, m[0, 1], "Matrix does not implement column major semantics");
            Assert.AreEqual(3f, m[1, 0], "Matrix does not implement column major semantics");
            Assert.AreEqual(4f, m[1, 1], "Matrix does not implement column major semantics");

            Assert.AreEqual(new vec2(1f, 2f), m[0], "Matrix does not implement column major semantics");
            Assert.AreEqual(new vec2(3f, 4f), m[1], "Matrix does not implement column major semantics");
        }
        /// <summary>
        /// </summary>
        /// <param name="uniformName"></param>
        /// <param name="matrixes"></param>
        internal int glUniform(string uniformName, mat2[] matrixes)
        {
            int location = GetUniformLocation(uniformName);

            if (location >= 0)
            {
                if (glUniformMatrix2fv == null)
                {
                    glUniformMatrix2fv = GL.Instance.GetDelegateFor("glUniformMatrix2fv", GLDelegates.typeof_void_int_int_bool_floatN) as GLDelegates.void_int_int_bool_floatN;
                }

                var values = new float[matrixes.Length * 4];
                for (int index = 0, i = 0; i < matrixes.Length; i++)
                {
                    mat2 matrix = matrixes[i];
                    values[index++] = matrix.col0.x;
                    values[index++] = matrix.col0.y;
                    values[index++] = matrix.col1.x;
                    values[index++] = matrix.col1.y;
                }
                glUniformMatrix2fv(location, matrixes.Length, false, values);
            }
            return(location);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Gets the transposed matrix.
 /// <para>获取转置矩阵。</para>
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public static mat2 transpose(mat2 m)
 {
     vec2 col0 = m.col0;
     vec2 col1 = m.col1;
     return new mat2(
         new vec2(col0.x, col1.x),
         new vec2(col0.y, col1.y)
         );
 }
 /// <summary>Returns the determinant of m. </summary>
 protected float determinant(mat2 m)
 {
     throw _invalidAccess;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Returns a matrix that is the transpose
 /// of m. The input matrix is not
 /// modified.
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public static mat2 transpose(mat2 m)
 {
     return(null);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Returns a matrix that is the inverse of
 /// m. The input matrix is not modified.
 /// The values in the returned matrix are
 /// undefined if the input matrix is
 /// singular or poorly conditioned (nearly
 /// singular).
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public static mat2 inverse(mat2 m)
 {
     return(null);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Multiply matrix x by matrix y
 /// component-wise, i.e., result[i][j] is the
 /// scalar product of x[i][j] and y[i][j].
 /// Note: To get linear-algebraic matrix
 /// multiplication, use the multiply
 /// operator (*).
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static mat2 matrixCompMult(mat2 x, mat2 y)
 {
     return(null);
 }
 protected extern mat2 inverse(mat2 m);
 public extern mat4(mat2 matrix);
 /// <summary>
 /// Returns a matrix that is the transpose of m. 
 /// The input matrix m is not modified.
 /// </summary>
 protected mat2 transpose(mat2 m)
 {
     throw _invalidAccess;
 }
 protected extern mat2 transpose(mat2 m);
 /// <summary>
 /// Multiply matrix x by matrix y component-wise, i.e., result[i][j] is the scalar product of x[i][j] and y[i][j].
 /// Note: to get linear algebraic matrix multiplication, use the multiply operator (*).
 /// </summary>
 protected mat2 matrixCompMult(mat2 x, mat2 y)
 {
     throw _invalidAccess;
 }
Ejemplo n.º 27
0
 /// <summary>Returns the determinant of m. </summary>
 protected float determinant(mat2 m)
 {
     throw _invalidAccess;
 }
 public extern mat3(mat2 matrix);
Ejemplo n.º 29
0
 /// <summary>
 /// </summary>
 /// <param name="uniformName"></param>
 /// <param name="m"></param>
 public int SetUniformMatrix2(string uniformName, mat2[] m)
 {
     int location = GetUniformLocation(uniformName);
     if (location >= 0)
     {
         if (glUniformMatrix2fv == null) { glUniformMatrix2fv = OpenGL.GetDelegateFor<OpenGL.glUniformMatrix2fv>(); }
         var values = new float[m.Length * 4];
         for (int index = 0, i = 0; i < m.Length; i++)
         {
             float[] array = m[i].ToArray();
             for (int j = 0; j < 4; j++)
             {
                 values[index++] = array[j];
             }
         }
         glUniformMatrix2fv(location, m.Length / 4, false, values);
     }
     return location;
 }
Ejemplo n.º 30
0
 /// <summary>initialized the matrix with the upperleft part of m
 /// sets the lower right diagonal component(s) to 1, everything else to 0</summary>
 public mat4x3(mat2 m)
 {
     throw _invalidAccess;
 }
Ejemplo n.º 31
0
 protected mat2 matrixCompMult(mat2 x, mat2 y)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
 public mat3(mat2 matrix)
 {
     throw new NotImplementedException();
 }
    // Matrix Functions

    protected extern mat2 matrixCompMult(mat2 x, mat2 y);
Ejemplo n.º 34
0
 protected mat2 transpose(mat2 m)
 {
     throw new NotImplementedException();
 }
 protected extern mat2 determinant(mat2 m);
Ejemplo n.º 36
0
 protected mat2 determinant(mat2 m)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 37
0
 protected mat2 inverse(mat2 m)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 38
0
 /// <summary>initialized the matrix with the upperleft part of m
 /// sets the lower right diagonal component(s) to 1, everything else to 0</summary>
 public mat3x4(mat2 m)
 {
     throw _invalidAccess;
 }