You need to reverse the order of how you combine the matrices.
Unexpected result when rotating a triangle
Pregunta
//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
as expected.
mview = Matrix4.CreateTranslation(Vector3(0.0f,1.0f,0.0f))
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))
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)
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow