1

我尝试根据鼠标在 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,上下

谢谢 !

4

1 回答 1

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);
}

;-)

于 2014-04-29T08:48:36.023 回答