旋转& OpenGL 矩阵
我有一个类,其中包含用于缩放和平移的 4x4 矩阵。 我将如何在此类中实现旋转方法? 我应该将旋转实现为单独的矩阵吗?
I have a class that holds a 4x4 matrix for scaling and translations. How would I implement rotation methods to this class? And should I implement the rotation as a separate matrix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以将当前矩阵与旋转矩阵相乘。 看看http://en.wikipedia.org/wiki/Rotation_matrix
You can multiply Your current matrix with a rotation matrix. Take a look at http://en.wikipedia.org/wiki/Rotation_matrix
每次当我需要查找 3D 转换的详细信息时,我都会使用一个名为 http://www.euclideanspace.com 的网站。 euclideanspace.com。 有关矩阵旋转的特定页面可以在此处找到。
编辑:绕给定轴旋转,查看轴和 角度表示。 此页面还链接到有关如何将一种表示形式转换为另一种表示形式的说明。
如果需要绕多个轴旋转,只需将相应的矩阵相乘即可。
There's a site which I use every time when I need to look up the details of a 3D transformation, called http://www.euclideanspace.com. The particular page on matrix rotations can be found here.
Edit: Rotation around a given axis, look at the axis & angle representation. This page also links to a description on how to translate one representation to another.
If you need to rotate around mutiple axes, simply multiply the corresponding matrices.
回答问题的后半部分,单个 4x4 矩阵完全能够进行缩放、平移和旋转。 因此,除非您对可以处理的 4x4 矩阵类型设置了特殊限制,否则单个 4x4 就可以满足您的需求。
至于关于任意向量的旋转(正如您在评论中询问的那样),请查看维基百科文章 yabcok 链接中的“关于任意向量的旋转”部分。 您需要将其扩展为 4x4 矩阵,方法是用零填充它,4,4(缩放)位置除外,该位置应该是 1。 然后使用矩阵乘法和 4x4 缩放/平移来生成新的 4x4 矩阵。
Answering the second half of the question, a single 4x4 matrix is perfectly capable of holding a scaling, a translation, and a rotation. So unless you've put special limitations on what sort of 4x4 matrices you can handle, a single 4x4 is a fine for what you want.
As for rotation about an arbitrary vector (as you are asking in comments), look at the "Rotation about an arbitrary vector" section in the Wikipedia article yabcok links to. You will want to extend that to a 4x4 matrix by padding it out with zeros except for the 4,4 (scaling) position, which should be one. Then use matrix multiplication with your scaling/translation 4x4 to generate a new 4x4 matrix.
您需要确保找到一个参考资料,其中讨论了用于计算机图形学的正确矩阵类型(即使用 4x4 变换矩阵进行旋转/平移/倾斜的 3D 齐次坐标)。
请参阅计算机图形“圣经”,例如 Foley 和 Van Dam (第 213 页),或其中之一:
You want to make sure you find a reference which talks about the right kind of matrix that's used for computer graphics (namely 3D homogeneous coordinates using a 4x4 transformation matrix for rotation/translation/skewing).
See a computer graphics "bible" such as Foley and Van Dam (pg. 213), or one of these:
此页面有很多有用的信息:
http://knol.google.com/k/matrices-for -3d-应用程序-平移-旋转
This page has quite a bit of useful information:
http://knol.google.com/k/matrices-for-3d-applications-translation-rotation