现在的位置: 首页 > 综合 > 正文

在Mascot Capsule V3中围绕任意轴旋转

2013年12月02日 ⁄ 综合 ⁄ 共 1080字 ⁄ 字号 评论关闭

 作者:merry  文章来源:http://www.j2medev.com/Article/ShowArticle.asp?ArticleID=764

Mascot Capsule V3里有一些让物体旋转的方法。这里我们讨论怎样使物体围绕任意轴旋转。

    Mascot Capsule V3采用仿射变换矩阵使物体移动、缩放和旋转。它可以直接设置相关值,但是在这个例子中,我们将使用AffineTrans类里的rotation方法。

    旋转应该始终设定在±2880度范围之内。在MascotCapsule中,4096就等于360度。

    下面是一个关于使用仿射变换矩阵来处理旋转和平移的动态物体的例子。

Rotation

Rotation

Rotation

Translation

m00: (y),(z), (scaleX)

m01: (z)

m02: (y)

m03: (x)

m10: (z)

m11: (x), (z), (scaleY)

m12: (x)

m13: (y)

m20: (y)

m21: (x)

m22: (x), (y), (scaleZ)

m23: (z)

 

 

 

 

 

 

 

在该例中,我们使用一个主类transformation,该类被layout对象所引用。

layout = new FigureLayout();
trans = new AffineTrans();

      

trans.setIdentity();
layout.setAffineTrans( trans );

 

同时我们使用3个AffineTrans类的对象来做旋转:
rotationX = new AffineTrans();
rotationY = new AffineTrans();
rotationZ = new AffineTrans();

    之所以使用好几个矩阵类是因为旋转方法只是简单的设定了矩阵中的适当值。对于同一个矩阵来说当每秒执行该旋转方法时就只是简单的覆盖掉前一个旋转的值。每一次旋转必须作用在单个的矩阵上,然后这些矩阵共同作用来产生最后的结果。

    在主线程中,我们使这些矩阵相乘来达到平移的目的。

rotationX.rotationX(23);

rotationY.rotationY(23);

rotationZ.rotationZ(23);

trans.mul(rotationX);

trans.mul(rotationY);

trans.mul(rotationZ);

 

下载范例程序和源代码:

http://developer.sonyericsson.com/getDocument.do?docId=71222

原文地址:点击这里

原文地址:点击这里

抱歉!评论已关闭.