旋转/平移矩阵的适当乘法 [英] Appropriate multiplication of matrices for rotation/translation

查看:55
本文介绍了旋转/平移矩阵的适当乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了旋转/平移对象(仅围绕 z 轴旋转和仅在 xy 平面中平移)不仅针对全局中心(设备中心)而且还针对其他任意点,我创建了一个算法,它是正确的(因为我讨论过的所有高级编码人员都认为它是正确的),但是在实现中删除一个不需要的翻译需要很多时间(算法是在 8 月 4 日创建的并在同一天实施,此后代码修改了15次).

In order to rotate/translate object (rotation only about z-axis and translation only in xy plane) not just w.r.t to global center (device center) but also w.r.t other arbitrary points, I created an algorithm, which is correct (because all senior coders I have discussed with consider it correct), but it is taking a lot of time to remove an undesired translation in the implementation (algorithm was created on August 4 and was implemented on the same day, since then the code has been revised 15 times).

这里是实现 http://www.pixdip.com/opengles/transform.php#ALGO1

Here is the implementation http://www.pixdip.com/opengles/transform.php#ALGO1

产生不需要的翻译的代码行在里面:

The lines of code that are producing undesired translation are inside:

private static void updateModel(int upDown, float xAngle, float yAngle, float zAngle) {

并在下面列出:

  1. Matrix.multiplyMV(GLES20Renderer._uBodyCentreMatrix, 0, GLES20Renderer._ModelMatrixBody, 0, GLES20Renderer._uBodyCentre, 0);

objX = GLES20Renderer._uBodyCentreMatrix[0];

objY = GLES20Renderer._uBodyCentreMatrix[1];

即使进行了以下更改,沿 +Y 的不良翻译仍然存在:

  1. objY = _uBodyCentreMatrix[1] - _uBodyCentre[1];

zAngle = 0;

ds = 0;

-0.545867f 会在每次调用 onDrawFrame() 时添加到 Y 坐标,因为 Renderer 类的这些字段:

The value -0.545867f is added to the Y coordinate on every call to onDrawFrame(), because of these fields of the Renderer class:

private static final float[] _uBodyCentre = new float[]{-0.019683f, -0.545867f, -0.000409f, 1.0f};

受保护的静态浮点[] _uBodyCentreMatrix = new float[4];

http://www.pixdip.com/opengles/transform.php#FIELDS

in http://www.pixdip.com/opengles/transform.php#FIELDS

我需要帮助来了解为什么会发生这种不希望的转换,转换到底出了什么问题,或者是算法有问题.

Gimbal 锁可能是个问题吗?

请不要让我执行/练习更简单的示例,因为我已经准备好了 Renderer 类,用于关于全局 z 轴的旋转/平移,而我正在进行的这个新任务使用相同的类,在 <代码>updateModel()

Please do not ask me to perform/practice simpler examples, because I have prepared the Renderer class for rotation/translation about global z-axis, and this new task that I am into, uses the same class with slight modification in updateModel()

(请注意,所需的旋转仅围绕 z 轴,并且仅在 xy 平面上平移)

(Please note that the desired rotation is only about z-axis and translation only in xy plane)

[API 10->15]

[API 10->15]

实际的 Renderer 类有两个对象:tank turret(nozzle) 和 tank body,而 turret(nozzle) 有不需要的向前平移,身体有不需要的向后平移

The actual Renderer class has two objects: tank turret(nozzle) and tank body, while turret(nozzle) has undesired forward translation, the body has undesired backward translation

关于设备中心的平移/旋转 Apk(在 opengles 2.0 中很容易制作):http://www.pixdip.com/opengles/global.php

Apk for translation/rotation about device center (which is easy to make in opengles 2.0): http://www.pixdip.com/opengles/global.php

用于关于任意点的平移/旋转的 Apk(沿 +Y 有不希望的平移):http://www.pixdip.com/opengles/local.php

Apk for translation/rotation about arbitrary points (which has undesired translation along +Y): http://www.pixdip.com/opengles/local.php

用于平移/旋转的 Apk,其中 updateModel() 仅被调用 4 次:http://www.pixdip.com/opengles/limited.php和所需的代码(应该足够了)在这里:http://www.pixdip.com/opengles/code.php

Apk for translation/rotation about arbitrary points in which updateModel() is called 4 times only: http://www.pixdip.com/opengles/limited.php and required code (which should be sufficient) is here: http://www.pixdip.com/opengles/code.php

对象的一部分(喷嘴/炮塔,身体)当前围绕它们自己的中心而不是对象的中心(即_playerCentre)旋转,我稍后会修改它.

Parts of object (nozzle/turret,body) are currently rotating about their own centres not the centre of object (which is _playerCentre), I will modify that later.

我试图证明逻辑 http://www.pixdip.com/opengles/images.php

I have tried to demonstrate logic http://www.pixdip.com/opengles/images.php

推荐答案

[已解决]java浮点错误是唯一的原因

[SOLVED] java floating point errors were the only cause

M = T * I * T[inv]

M = T * I * T[inv]

没有产生单位矩阵,所以不要使用 Matrix.MultiplyMM

did not result into an identity matrix, so instead of using Matrix.MultiplyMM

我输入矩阵之间的所有乘法

I type all the multiplications between the matrices

这篇关于旋转/平移矩阵的适当乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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