English 中文(简体)
gle角
原标题:quaternion to angle

诚然,这就是我是如何这样做的:

float xrot = 0;
float yrot = 0;
float zrot = 0;

Quaternion q = new Quaternion().fromRotationMatrix(player.model.getRotation());
if (q.getW() > 1) {
    q.normalizeLocal();
}

float angle = (float) (2 * Math.acos(q.getW()));
double s = Math.sqrt(1-q.getW()*q.getW());

// test to avoid divide by zero, s is always positive due to sqrt
// if s close to zero then direction of axis not important
if (s < 0.001) {
    // if it is important that axis is normalised then replace with x=1; y=z=0;
    xrot = q.getXf(); 
    yrot = q.getYf();
    zrot = q.getZf();
    // z = q.getZ();
} else {
    xrot = (float) (q.getXf() / s); // normalise axis
    yrot = (float) (q.getYf() / s);
    zrot = (float) (q.getZf() / s);
}

但是,在我试图将其付诸实施时,这似乎并没有奏效:

player.model.addTranslation(xrot * player.speed, 0, zrot * player.speed);

添加字数为3个,将我的模型移至多个空间(x、 y、z),但当我给它提供上述数字时,该模型并没有朝它轮值的方向移动(关于XZ飞机)。

为什么不这样做?

Edit: 新的法典,虽然现在有大约45度。

Vector3 move = new Vector3();
move = player.model.getRotation().applyPost(new Vector3(1,0,0), move);
move.multiplyLocal(-player.speed);
player.model.addTranslation(move);
最佳回答

<代码>xrot,yrot, 和zrot, 界定了胎数规定的轮换轴。 我不认为你希望将其用于您的<代码> 附加翻译()中。

What I mean by that is: your 3-D object -- let s say for the sake of argument that it s an airplane -- will have a certain preferred direction of motion in its original coordinate system. So if the original orientation has the center of mass at the origin, and the propeller somewhere along the +X axis, the plane wants to fly in the +X direction.

Now you introduce some coordinate transformation that rotates the airplane into some other orientation. That rotation is described by a rotation matrix, or equivalently, by a quaternion. Which way does the plane want to move after the rotation?

You could find that by taking a unit vector in the +X direction: (1.0, 0.0, 0.0), then applying the rotation matrix or quaternion to that vector to transform it into the new coordinate system. (Then scale it by the speed, as you re doing above.) The X, Y, and Z components of the transformed, scaled vector give the desired incremental motion along each axis. That transformed vector is generally not going to be the rotation axis of the quaternion, and I think that s probably your problem.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签