Ejemplo n.º 1
0
        /// <summary>
        /// Gets or sets the <see cref="vec2"/> column at the specified index.
        /// </summary>
        /// <value>
        /// The <see cref="vec2"/> column.
        /// </value>
        /// <param name="column">The column index.</param>
        /// <returns>The column at index <paramref name="column"/>.</returns>
        public vec2 this[int column]
        {
            get
            {
                if (column == 0) { return this.col0; }
                if (column == 1) { return this.col1; }

                throw new ArgumentOutOfRangeException();
            }
            set
            {
                if (column == 0) { this.col0 = value; }
                else if (column == 1) { this.col1 = value; }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Ejemplo n.º 2
0
 public vec2(vec2 v)
 {
     this.x = v.x;
     this.y = v.y;
 }
Ejemplo n.º 3
0
 public mat2(float a, float b, float c, float d)
 {
     this.col0 = new vec2(a, b);
     this.col1 = new vec2(c, d);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="mat2"/> struct.
 /// The matrix is initialised with the <paramref name="cols"/>.
 /// </summary>
 /// <param name="cols">The colums of the matrix.</param>
 public mat2(vec2[] cols)
 {
     this.col0 = cols[0];
     this.col1 = cols[1];
 }
Ejemplo n.º 5
0
 public mat2(vec2 a, vec2 b)
 {
     this.col0 = a;
     this.col1 = b;
 }
Ejemplo n.º 6
0
 public override string ToString()
 {
     var builder = new System.Text.StringBuilder();
     var cols = new vec2[] { col0, col1};
     for (int i = 0; i < cols.Length; i++)
     {
         builder.Append(cols[i]);
         builder.Append(" + ");
     }
     return builder.ToString();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="mat2"/> struct.
 /// This matrix is the identity matrix scaled by <paramref name="scale"/>.
 /// </summary>
 /// <param name="scale">The scale.</param>
 public mat2(float scale)
 {
     this.col0 = new vec2(scale, 0);
     this.col1 = new vec2(0, scale);
 }
Ejemplo n.º 8
0
 public static float dot(vec2 x, vec2 y)
 {
     vec2 tmp = new vec2(x * y);
     return tmp.x + tmp.y;
 }
Ejemplo n.º 9
0
 public static vec2 normalize(vec2 v)
 {
     float sqr = v.x * v.x + v.y * v.y;
     return v * (1.0f / (float)Math.Sqrt(sqr));
 }
Ejemplo n.º 10
0
        protected override void DoInitialize()
        {
            base_prog = GL.CreateProgram();

            ShaderHelper.vglAttachShaderSource(base_prog, ShaderType.VertexShader, quad_shader_vs);
            ShaderHelper.vglAttachShaderSource(base_prog, ShaderType.FragmentShader, quad_shader_fs);

            GL.GenBuffers(1, quad_vbo);
            GL.BindBuffer(BufferTarget.ArrayBuffer, quad_vbo[0]);

            var quad_data = new UnmanagedArray<vec2>(8);
            quad_data[0] = new vec2(1.0f, -1.0f);
            quad_data[1] = new vec2(-1.0f, -1.0f);
            quad_data[2] = new vec2(-1.0f, 1.0f);
            quad_data[3] = new vec2(1.0f, 1.0f);
            quad_data[4] = new vec2(0.0f, 0.0f);
            quad_data[5] = new vec2(1.0f, 0.0f);
            quad_data[6] = new vec2(1.0f, 1.0f);
            quad_data[7] = new vec2(0.0f, 1.0f);

            GL.BufferData(BufferTarget.ArrayBuffer, quad_data, BufferUsage.StaticDraw);

            GL.GenVertexArrays(1, vao);
            GL.BindVertexArray(vao[0]);

            GL.VertexAttribPointer(0, 2, GL.GL_FLOAT, false, 0, IntPtr.Zero);
            GL.VertexAttribPointer(1, 2, GL.GL_FLOAT, false, 0, new IntPtr(8 * sizeof(float)));

            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);

            GL.LinkProgram(base_prog);

            StringBuilder buf = new StringBuilder(1024);
            GL.GetProgramInfoLog(base_prog, 1024, IntPtr.Zero, buf);

            vglImageData image = new vglImageData();

            tex = vgl.vglLoadTexture(@"media\test.dds", 0, ref image);

            GL.TexParameteri(image.target, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR_MIPMAP_LINEAR);

            vgl.vglUnloadImage(ref image);
        }
Ejemplo n.º 11
0
        public static vec2 ToVec2(this float[] array, int startIndex = 0)
        {
            vec2 result = new vec2(array[startIndex], array[startIndex + 1]);

            return(result);
        }
Ejemplo n.º 12
0
        public static float Magnitude(this vec2 vector)
        {
            double result = Math.Sqrt(vector.x * vector.x + vector.y * vector.y);

            return((float)result);
        }
Ejemplo n.º 13
0
 public vec3(vec2 xy, float z)
 {
     this.x = xy.x;
     this.y = xy.y;
     this.z = z;
 }
Ejemplo n.º 14
0
        private void InitVAO()
        {
            this.mode = DrawMode.Quads;
            this.vertexCount = 4;

            //  Create a vertex buffer for the vertex data.
            UnmanagedArray<vec3> in_Position = new UnmanagedArray<vec3>(this.vertexCount);
            UnmanagedArray<vec2> in_TexCoord = new UnmanagedArray<vec2>(this.vertexCount);
            Bitmap bigBitmap = this.ttfTexture.BigBitmap;

            float factor = (float)this.ttfTexture.BigBitmap.Width / (float)this.ttfTexture.BigBitmap.Height;
            float x1 = -factor;
            float x2 = factor;
            float y1 = -1;
            float y2 = 1;

            in_Position[0] = new vec3(x1, y1, 0);
            in_Position[1] = new vec3(x2, y1, 0);
            in_Position[2] = new vec3(x2, y2, 0);
            in_Position[3] = new vec3(x1, y2, 0);

            in_TexCoord[0] = new vec2(0, 0);
            in_TexCoord[1] = new vec2(1, 0);
            in_TexCoord[2] = new vec2(1, 1);
            in_TexCoord[3] = new vec2(0, 1);

            if (vao[0] != 0)
            { GL.DeleteBuffers(1, vao); }
            if (vbo[0] != 0)
            { GL.DeleteBuffers(vbo.Length, vbo); }

            GL.GenVertexArrays(1, vao);
            GL.BindVertexArray(vao[0]);

            GL.GenBuffers(2, vbo);

            uint in_PositionLocation = shaderProgram.GetAttributeLocation(strin_Position);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, in_Position, BufferUsage.StaticDraw);
            GL.VertexAttribPointer(in_PositionLocation, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero);
            GL.EnableVertexAttribArray(in_PositionLocation);

            uint in_TexCoordLocation = shaderProgram.GetAttributeLocation(strin_TexCoord);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, in_TexCoord, BufferUsage.StaticDraw);
            GL.VertexAttribPointer(in_TexCoordLocation, 2, GL.GL_FLOAT, false, 0, IntPtr.Zero);
            GL.EnableVertexAttribArray(in_TexCoordLocation);

            GL.BindVertexArray(0);

            in_Position.Dispose();
            in_TexCoord.Dispose();
        }