Matrices

1218 ワード

https://github.com/glium/glium/blob/master/book/tuto-04-matrices.md
三角形へのジオメトリの追加
  • Scaling : position *= factor;
  • Rotating : new_position = vec2(pos.x cos(angle) - pos.y sin(angle), pos.x sin(angle) + pos.y cos(angle));
  • Skewing : position.x += position.y * factor;
  • 上記の演算を4 x 4マトリクスで一括処理する
    頂点シェーダコードを修正するには
    let vertex_shader_src = r#"
        #version 140
    
        in vec2 position;
    
        uniform mat4 matrix;
    
        void main() {
            gl_Position = matrix * vec4(position, 0.0, 1.0);
        }
    "#;
    draw関数の変更
    let uniforms = uniform! {
        matrix: [
            [ t.cos(), t.sin(), 0.0, 0.0],
            [-t.sin(), t.cos(), 0.0, 0.0],
            [0.0, 0.0, 1.0, 0.0],
            [0.0, 0.0, 0.0, 1.0f32],
        ]
    };
    
    target.draw(&vertex_buffer, &indices, &program, &uniforms,
                &Default::default()).unwrap();