Rotation matrix problem, besides rotation my object gets translated too.
Matrix m = new Matrix();
m.SetRotate(new Vector(0, 0, 1), Math.PI / 4);
m.PrintMatrix();
for (int i = 0; i < 6; i++)
{
_spaceship.VertexPositions[i] *= m;
}
I create an identity matrix.
SetRotate makes it a rotation matrix, for rotation pi/4 around z axis.
I printed more matrices to check if SetRotate does work, it does indeed, so SetRotate does it's job well, something else must be causing the problem.
_spaceship is a sprite with 6 vertices(two triangles), and each of them i multiply with the rotation matrix. VertexPositions stores Vectors for each vertex position.
So the rotation matrix is fine, i have checked the vector ma开发者_JAVA技巧trix multiplication also fine, I don't understand where that extra translation could come from. My object does get rotated pi/4, but it gets translated X:-14.1421356237309, Y:-16.6170093578839, Z:0, and it is supposed to be all zeroes X:0, Y:0, Z:0 just like before the rotation.
Are your spaceship's vertex positions already offset? If you want to rotate your model around it's center, make sure that the model vertices are relative to the center.
You probably need to normalize your vec3 before making the rotation.
精彩评论