我尝试根据Java3D中鼠标的移动对立方体进行旋转。无论立方体旋转,我都希望当我向上拖动光标时,立方体会以相同的方向旋转。这适用于所有可能的动作。
我该怎么办?我想它必须放在相机坐标中......
这是我的功能:
public void objectRotate(TransformGroup objectInInteraction, double dh,
double dp, double dr) {
Transform3D oldT3D = new Transform3D();
objectInInteraction.getTransform(oldT3D);
Transform3D tx = new Transform3D();
Transform3D ty = new Transform3D();
Transform3D tz = new Transform3D();
Transform3D tc = new Transform3D();
//camera.getTransform(tc);
double x = 0, y = 0, z = 0;
x = Math.PI * dh / 180;
y = Math.PI * dp / 180;
z = Math.PI * dr / 180;
tx.rotX(x);
tc.mul(tx);
ty.rotY(y);
tc.mul(ty);
tz.rotZ(z);
tc.mul(tz);
oldT3D.mul(tc);
objectInInteraction.setTransform(oldT3D);
}
dh是左右移动,dp,上下
谢谢!
答案 0 :(得分:2)
对我有用......
public void objectRotate(TransformGroup objectInInteraction, double dh,
double dp, double dr)
{
// Transform3D oldT3D = new Transform3D();
// objectInInteraction.getTransform(oldT3D);
Transform3D tx = new Transform3D();
Transform3D ty = new Transform3D();
Transform3D tz = new Transform3D();
Transform3D tc = new Transform3D();
//camera.getTransform(tc);
double x = 0, y = 0, z = 0;
x = Math.PI * dh / 180;
y = Math.PI * dp / 180;
z = Math.PI * dr / 180;
tx.rotX(x);
tc.mul(tx);
ty.rotY(y);
tc.mul(ty);
tz.rotZ(z);
tc.mul(tz);
// oldT3D.mul(tc);
objectInInteraction.setTransform(tc);
}
- )