旋转三角形时出现意外结果

时间:2014-01-04 14:25:13

标签: opengl opentk

//my triangle
let vertdata = 
    [| new Vector3(-1.0f, -1.0f,0.0f)
       new Vector3(1.0f, -1.0f,0.0f)
       new Vector3(0.0f, 1.0f,0.0f) |]
//VertexShader
..
uniform mat4 mview;
...
gl_Position =  mview * vec4(vPosition, 1.0);
..

使用Identity矩阵渲染它看起来像

mview = Matrix4.Identity

enter image description here

正如所料。

mview = Matrix4.CreateTranslation(Vector3(0.0f,1.0f,0.0f))

enter image description here

在y中翻译为1。但是,如果我将它旋转90°,它会以某种方式转换为x方向。

mview = Matrix4.CreateTranslation(Vector3(0.0f,1.0f,0.0f))
        * Matrix4.CreateRotationZ(toRad(90.0f))

enter image description here

知道为什么这样做吗?如果我在脑子里做数学应该是。

Matrix4.CreateRotationZ(toRad(90.0f)) 
* Vector3(0.0f, 1.0f,0.0f) = Vector3(-1.0f, 0.0f,0.0f)

Matrix4.CreateTranslation(Vector3(0.0f,1.0f,0.0f)) 
* Vector3(-1.0f, 0.0f,0.0f) = Vector3(-1.0f, 1.0f,0.0f) 
//but it seems to be Vector3(-2.0f, 0.0f,0.0f)

1 个答案:

答案 0 :(得分:3)

您需要颠倒组合矩阵的顺序。