gpt4 book ai didi

java - 在 Java 3d 中旋转对象

转载 作者:行者123 更新时间:2023-11-30 04:34:47 24 4
gpt4 key购买 nike

我尝试在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,上下

谢谢!

最佳答案

这对我有用......

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

;-)

关于java - 在 Java 3d 中旋转对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13749865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com