سؤال

//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);
..

Rendered with the Identity matrix it looks like

mview = Matrix4.Identity

enter image description here

as expected.

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

enter image description here

Translated by 1 in the y. But If I rotate it by 90° it somehow translates in the x direction.

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

enter image description here

Any idea why it does that? If I do the math in my head it should be.

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)
هل كانت مفيدة؟

المحلول

You need to reverse the order of how you combine the matrices.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top