旋转矩阵问题,除了旋转之外,我的对象也被平移
旋转矩阵问题,除了旋转之外,我的对象也被平移。
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;
}
我创建一个单位矩阵。
SetRotate 使其成为旋转矩阵,绕 z 轴旋转 pi/4。
我打印了更多的矩阵来检查 SetRotate 是否有效,它确实有效,所以 SetRotate 的工作很好,一定是其他原因导致了问题。
_spaceship 是一个有 6 个顶点(两个三角形)的精灵,每个顶点都乘以旋转矩阵。 VertexPositions 存储每个顶点位置的向量。
所以旋转矩阵很好,我检查了向量矩阵乘法也很好,我不明白额外的翻译可能来自哪里。我的对象确实旋转了 pi/4,但它被平移了 X:-14.1421356237309、Y:-16.6170093578839、Z:0,并且它应该全为零 X:0、Y:0、Z:0,就像之前一样旋转。
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 matrix 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的宇宙飞船的顶点位置是否已经偏移?如果要围绕模型的中心旋转模型,请确保模型顶点相对于中心。
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.
在进行旋转之前,您可能需要标准化 vec3。
You probably need to normalize your vec3 before making the rotation.