开发者

Rotation matrix problem, besides rotation my object gets translated too

开发者 https://www.devze.com 2023-03-29 04:02 出处:网络
Rotation matrix problem, besides rotation my object gets translated too. Matrix m = new Matrix(); m.SetRotate(new Vector(0, 0, 1), Math.PI / 4);

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;  
}
  1. I create an identity matrix.

  2. SetRotate makes it a rotation matrix, for rotation pi/4 around z axis.

  3. 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.

  4. _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.

0

精彩评论

暂无评论...
验证码 换一张
取 消