【发布时间】:2020-05-30 02:45:15
【问题描述】:
缩放对象时我得到不同的结果。
对象有四个不同的 glm::vec3 值
1) Position , Rotation , Scaling , Center Point
这是对象的变换矩阵
TransformationMatrix = PositionMatrix() * RotationMatrix() * ScalingMatrix();
旋转和缩放矩阵是这样的。
glm::vec3 pivotVector(pivotx, pivoty, pivotz);
glm::mat4 TransPivot = glm::translate(glm::mat4x4(1.0f), pivotVector);
glm::mat4 TransPivotInverse = glm::translate(glm::mat4x4(1.0f), -pivotVector);
glm::mat4 TransformationScale = glm::scale(glm::mat4(1.0), glm::vec3(scax, scay, scaz));
return TransPivot * TransformationScale * TransPivotInverse;
第一种情况。
我将矩形对象移动到以 x 为单位的 200 个单位。
比我缩放位置 x = 0.0 的组
所以矩形对象的最终矩阵是
finalMatrix = rectangleTransformationMatrix * groupTransformationMatrix
结果符合我的预期。矩形缩放并向屏幕中心移动。
现在如果我用三个容器做同样的事情。
在这里我将组容器移动到 200 并缩放位于位置 0.0 的顶部容器
finalMatrix = rectangleTransformationMatrix * groupTransformationMatrix * TopTransformationMatrix
矩形在自己的位置缩放,就好像屏幕的中心点也移动了 200 个单位。
如果我将 -200 个单位添加到顶部容器的轴心点 x 上,我会得到预期的结果。
矩形向屏幕中心移动并缩放。
如果有人能解释一下为什么我需要在顶部容器的中心点添加 -200 个单位。而在第一种情况下,我不需要向缩放容器的枢轴点添加任何值。
当两个操作本质上相同时。
/////////////////////////////////////// ///////////////////////////////////////// //////////////////////p>
第一种情况
Rectangle - > position( x = 200 , y = 0, z = 0) , scaling( 1.0 , 1.0 , 1.0 ) , Rotation( 0.0 , 0.0 , 0.0 )
glm::mat4 PositionMatrix = glm::position( // fill the values);
glm::mat4 ScalingMatrix = glm::scaling( // fill the values);
glm::mat4 RotationMatrix = glm::rotate( // fill the values);
RectangleMatrix = PositionMatrix() * RotationMtrix() * ScalingMatrix();
组的矩阵
froup - > position( x = 0.0 , y = 0, z = 0) , scaling( 0.5 , 1.0 , 1.0 ) , Rotation( 0.0 , 0.0 , 0.0 )
groupMatrix = PositionMatrix() * RotationMtrix() * ScalingMatrix();
最终结果 finalMatrix = 矩形矩阵 * 组矩阵
/////////////////////////////////////// ///////////////////////////////////////// //////////////////////p>
第二种情况
Rectangle - > position( x = 0 , y = 0, z = 0) , scaling( 1.0 , 1.0 , 1.0 ) , Rotation( 0.0 , 0.0 , 0.0 )
glm::mat4 PositionMatrix = glm::position( // fill the values);
glm::mat4 ScalingMatrix = glm::scaling( // fill the values);
glm::mat4 RotationMatrix = glm::rotate( // fill the values);
RectangleMatrix = PositionMatrix() * RotationMtrix() * ScalingMatrix();
组的矩阵
group - > position( x = 200.0 , y = 0, z = 0) , scaling( 1.0 , 1.0 , 1.0 ) , Rotation( 0.0 , 0.0 , 0.0 )
groupMatrix = PositionMatrix() * RotationMtrix() * ScalingMatrix();
Top 的矩阵
Top - > position( x = 0.0 , y = 0, z = 0) , scaling( 0.5 , 1.0 , 1.0 ) , Rotation( 0.0 , 0.0 , 0.0 )
TopMatrix = PositionMatrix() * RotationMtrix() * ScalingMatrix();
最终结果 finalMatrix = RectangleMatrix * groupMatrix * TopMatrix
【问题讨论】:
-
如果
groupTransformationMatrix包含缩放,那么TopTransformationMatrix的翻译也会缩放 -
@Rabbid76 我可以请你详细解释一下,为什么在第一种情况下没有发生。
-
@Rabbid76 groupTransformationMatrix = positionMatrix() * rotationMatrix() * scalingMatrix() ,但所有轴的缩放值为 1.0。
-
您的问题不清楚。看不懂
groupTransformationMatrix和TopTransformationMatrix的内容。在第一种情况下,根本没有TopTransformationMatrix。注意,如果M7 = M1 * M2 * M3和M8 = M4 * M5 * M6,那么M7 * M8 = M1 * M2 * M3 * M4 * M5 * M6。将转换写在一行中以查看差异。 -
@Rabiib76 谢谢,我会用两个矩阵的内容更新我的问题。