OpenGL ESの座標系及び座標変換3。

みなさん、こんにちは、次は、OpenGL ES座標系と座標変換3.ご紹介します。

まず、座標系、座標空間:

OpenGLは直交右手座標系に使用されます。

 

5重要なOpenGLの座標空間があります。

ローカル空間(ローカル空間は、物体または空間(オブジェクト空間)と呼びます)。

B:ワールド空間(ワールド・スペース)。

C:(そうでない場合は視空間(アイスペース)として知られているビュースペース、)観測空間。

D:クリップ空間(スペースクリップ)。

E:画面スペース(画面スペース)。

       1は、別の座標系に座標系から座標変換をするために、我々は最も重要なものは観察されたモデル(モデル)、(ビュー)、プロジェクション(投影)3つの行列をしている、いくつかの変換行列を使用する必要があります。

       ここでは、オブジェクトと、初期部分空間(ローカル空間)の頂点座標、それは世界座標になった後(ワールド座標)、ローカル座標(ローカル座標)と呼ばれるが、(ビュー座標)座標測定し、座標をクリッピング(クリップは座標)、そして最後の画面座標(画面Corrdinate)の形で終わります。下の写真は、さまざまなプロセスを示しており、何をすべきかを変換します:

 

第二に、行列演算の例:

public class MatrixState {
    private static float[] mProjMatrix = new float[16]; //投影矩阵
    private static float[] mVMatrix = new float[16]; //视图矩阵
    private static float[] currMatrix; //模型矩阵

    private static float[] mMVPMatrix;
    public static void setCamera(
        float cx, float cy, float cz,
        float tx, float ty, float tz,
        float upx, float upy, float upz
    ){
        Matrix.setLookAtM(mVMatrix, 0, cx, cy, cz, tx, ty, tz, upx, upy, upz);
    }
 
    public static void setProjectOrtho(
        float left, float right,
        float bottom, float top,
        float near, float far
    ){
        Matrix.orthoM(mProjMatrix, 0, left, right, bottom, top, near, far);
    }
 
    public static void setProjectFrustum( 
        float left, float right,
        float bottom, float top,
        float near, float far 
    ){
        Matrix.frustumM(mProjMatrix, 0, left, right, bottom, top, near, far);
    }

    public static void translate(float x, float y, float z)
    {
        Matrix.translateM(currMatrix, 0, x, y, z); 
    }

    public static float[] getFinalMatrix() { //计算产生总变换矩阵的方法
        //摄像机矩阵乘以变换矩阵
        Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, currMatrix, 0);         
        //投影矩阵乘以上一步的结果矩阵
        Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix,
                          0); 
        return mMVPMatrix;
    }

 
}

 

次のように第三に、座標変換プロセスです。

モデル変換行列に対応することである:currMatrix。

ビュー変換行列が対応している:mVMatrixを。

射影変換行列は、対応される:mProjMatrixを。

 

四、例を使用してシェーダ:

#version 330

layout(location = 0) in vec3 position;
layout(location = 1) in vec3 color;
layout(location = 2) in vec2 textCoord;

out vec3 VertColor;
out vec2 TextCoord;

uniform mat4 mvpMatrix;

void main()
{
    gl_Position = mvpMatrix * vec4(position, 1.0);
    VertColor = color;
    TextCoord = textCoord;
}
glUniformMatrix4fv(glGetUniformLocation(shader.programId, "mvpMatrix"),
                     1, GL_FALSE, MatrixState.getFinalMatrix()); // 传递总的变换矩阵

 

マイクロ手紙:最後に、私たちは一緒に学習の交流を歓迎liaosy666を; QQ:2209115372  。

 

 

公開された20元の記事 ウォン称賛30 ビュー10000 +

おすすめ

転載: blog.csdn.net/u010281924/article/details/105300431