简体   繁体   English

Android OpenGL:如何绕世界轴旋转?

[英]Android OpenGL: How to rotate around the world axes?

I have a touchRotationMatrix that I do the following:我有一个 touchRotationMatrix,我执行以下操作:

Matrix.setIdentityM(identity, 0);
Matrix.rotateM(identity, 0, x, 0,1,0);
Matrix.multiplyMV(v, 0, identity, 0, v, 0)
Matrix.rotateM(identity, 0, y, 1,0,0);
Matrix.rotateM(identity, 0, y, v[0],v[1],v[2]);     
Matrix.multiplyMM(touchRotationMatrix, 0, identity, 0, touchRotationMatrix, 0);

X and Y are the normalized rotation deltas. X 和 Y 是标准化的旋转增量。

This is applied to my model matrix like so:这适用于我的 model 矩阵,如下所示:

Matrix.multiplyMM(mModelMatrix, 0, mModelMatrix, 0,touchRotationMatrix,0);

The problem here is that any rotation that I do is on its own axes.这里的问题是我所做的任何旋转都是在它自己的轴上。

Let me illustrate why I don't want this:让我说明为什么我不想要这个:

If I rotate from left to right, it's like turning your head which is good.如果我从左到右旋转,就像转动你的头,这很好。 If I rotate up first, then rotate from left to right, I end up looking at the floor or the ceiling.如果我先向上旋转,然后从左向右旋转,我最终会看到地板或天花板。 This makes sense because it is rotating on its axes.这是有道理的,因为它在其轴上旋转。

My question is, how do I make it that the x rotation isn't happening on its own axes?我的问题是,如何使 x 旋转不在它自己的轴上发生?

I hope I am clear, any guidance or help would be very much appreciated!我希望我很清楚,任何指导或帮助将不胜感激! Thanks!谢谢!

PS I'm not an expert in OpenGL nor in LinearAlgebra. PS 我不是 OpenGL 和线性代数方面的专家。

Not so clear but either不太清楚,但要么

Matrix.setRotateM(identity, 0, y, 1,0,0);
Matrix.multiplyMM(touchRotationMatrix, 0, identity, 0, touchRotationMatrix, 0);
Matrix.rotateM(touchRotationMatrix, 0, x, 0,1,0);

or或者

Matrix.setRotateM(identity, 0, x, 0,1,0);
Matrix.multiplyMM(touchRotationMatrix, 0, identity, 0, touchRotationMatrix, 0);
Matrix.rotateM(touchRotationMatrix, 0, y, 1,0,0);

might work as you expect.可能会按您的预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM