旋转4x4矩阵导致随时间的缩放 [英] Rotating a 4x4 Matrix Causes Scaling Over Time

查看:248
本文介绍了旋转4x4矩阵导致随时间的缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 glm :: rotate 旋转场景中多维数据集的转换矩阵。



cube-> t = glm :: rotate(cube-> t,stepTime * 50.f,glm :: vec3(0.f,1.f,0.f)); 每帧调用一次,其中 cube-> t 是所讨论的矩阵。



奇怪的是,在20分钟的过程中(如果我旋转 stepTime * 5000.f 而不是 stepTime *立方体在X和Z轴上显着地缩放,其中在这两个轴上的缩放总是相同的(立方体的高度从不改变,但是宽度和深度改变完全相同的量)。在 5000.f 的情况下,变得更小,并且正常 50.f 100.f ,变大。



我认为这可能是舍入错误的问题,但除此之外,我不知道什么可能导致它。这是舍入错误吗?我可以解决它通过规则化矩阵定期吗? glm是否有一个矩阵规范化的函数,或者我自己写一个?

解决方案

,精度损失:而不是就地更新立方体,保持原始未旋转的立方体,并跟踪总旋转角度。然后在每个步骤从原始未旋转的立方体创建立方体,由总累积旋转角度变换。

编辑:为了回应与Miles的讨论,一个更合适的答案:

/ p>

如果你可以分离转换矩阵的旋转和平移分量,问题主要在于旋转积累引入剪切或缩放,你可以通过提取与旋转分量的角度,并用该角度但单位长度重新创建旋转矩阵。


I am using glm::rotate to rotate a transformation matrix for a cube in a scene.

"cube->t = glm::rotate(cube->t, stepTime * 50.f, glm::vec3(0.f, 1.f, 0.f));" is called once per frame, where cube->t is the matrix in question.

The strange thing is that over the course of 20 minutes (or two minutes if I rotate by stepTime * 5000.f instead of stepTime * 50.f), the cube scales noticeably on the X and Z axes, where the scaling on those two axes is the same at all times (the height of the cube never changes, but the width and depth change by exactly the same amount). In the case of 5000.f, becoming smaller, and with the normal 50.f or 100.f, becoming larger.

I thought this might be a question of rounding error, but other than that I have no idea what could be causing it. Is this rounding error? Can I solve it by normalizing the matrix on a regular basis? Does glm have a function for normalizing matrices, or do I have to write one myself?

解决方案

If it is an incremental, cumulative, loss of precision: instead of in-place updating the cube, keep an original un-rotated cube and keep track of the total rotational angle. Then on each step create a cube from the original un-rotated cube, transformed by the total accumulated rotational angle. In this way your cube will not suffer from cumulative rounding problems.

Edit: In response to discussion with Miles, a more appropriate answer:

If you can separate the rotational and translation components of the transformation matrix, and the problem is primarily with the accumulation of rotation introducing shear or scaling, you can rectify the problem by extracting the angle from the rotational component and re-creating the rotation matrix with that angle but unit length.

这篇关于旋转4x4矩阵导致随时间的缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆