【发布时间】:2017-02-10 09:35:17
【问题描述】:
我有一个圆形物体,我想像扇子一样沿着它自己的轴旋转。
我可以使用我的变换矩阵改变任何方向的旋转,即dx, dy, dz。
以下是代码:
Matrix4f matrix = new Matrix4f();
matrix.setIdentity();
Matrix4f.translate(translation, matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
我的顶点代码:
vec4 worldPosition = transformationMatrix * vec4(position,1.0);
vec4 positionRelativeToCam = viewMatrix*worldPosition;
gl_Position = projectionMatrix *positionRelativeToCam;
Main Game Loop:
Object.increaseRotation(dxf,dyf,dzf);
但是,它并没有沿着自己的轴旋转。我在这里想念什么? 我想要这样的东西。请帮忙
【问题讨论】:
-
参见Understanding 4x4 homogenous transform matrices bullet #5 并在那里寻找局部和全局旋转之间的差异。
-
@Spektre 请在答案中解释需要做哪些改变我也面临类似的问题
-
您的问题中的相关代码太少,无法查看问题可能出在哪里。数学的应用是正确的。所以我的猜测是,转换矩阵没有正确加载到着色器的制服中。
-
@datenwolf 我的对象像硬币一样翻转,即在一帧中
Head一侧面向相机,而在第二帧中Tail一侧面向相机,当我仅更改y旋转时, 对于x旋转,它围绕轨道旋转,对于z旋转,它在旋转,但 y 位置也在变化
标签: opengl matrix graphics rotation