旋转3D模型与例3中的缩放模型是用的同样的技术。你创建一个AffineTrans对象来控制你的旋转数据,并把它的矩阵添加到模型的主AffineTrans里。
// Rotation value
public final static int SPIN_X_PLUS = 100; // Increase or decrease value of the rotation around X axis
public final static int SPIN_Y_PLUS = 100; // Increase or decrease value of the rotation around Y axis
private static int spinX = 0; // X axis rotation value
private static int spinY = 0; // Y axis rotation value
...
kc = getGameAction(kc);
switch (kc) {
case Canvas.UP: // roll up
setSpinX(-SPIN_X_PLUS);
break;
case Canvas.DOWN: // roll down
setSpinX(SPIN_X_PLUS);
break;
case Canvas.LEFT: // roll left
setSpinY(-SPIN_Y_PLUS);
break;
case Canvas.RIGHT: // roll right
setSpinY(SPIN_Y_PLUS);
break;
default:
break;
}
...
AffineTrans rotTrans = new AffineTrans();
//X roll
rotTrans.setIdentity();
rotTrans.setRotationX(spinX);
affineTrans.mul(rotTrans);
//Y roll
rotTrans.setIdentity();
rotTrans setRotationY(spinY);
affineTrans.mul(rotTrans);
例7 模型中的动画效果