Java3D:在世界坐标中旋转对象?

发布于 2024-10-03 17:52:03 字数 781 浏览 2 评论 0原文

我整个晚上都在搜索,但找不到我要找的信息,或者即使有可能,这也很令人苦恼;)

我正在使用 Java3D,不知道如何在世界中旋转相机空间。

我的左/右和上/下旋转都发生在本地空间上。 这意味着如果我左右移动,一切看起来都很好。 然而,如果我向下看 90 度,然后向右看 90 度,一切似乎都在一边。

目前,我正在做以下事情。这将导致上述效果:

TransformGroup cam = universe.getViewingPlatform().getViewPlatformTransform();
Transform3D trfcam = new Transform3D();
cam.getTransform(trfcam);

trfcam.mul(Camera.GetT3D()); //Gets a Transform3D containing how far to rotate left/right and how far to move left/right/forward/back

trfcam.mul(Camera.GetRot()); //Gets a t3d containing how far to rotate up/down

cam.setTransform(trfcam);

或者,我尝试的一件事是旋转根,但它围绕 0 旋转,所以如果我将相机移离 0,它就会变坏。 网络上是否有一些东西可以告诉我如何实现这种目标? 我尝试了很多不同的事情,但似乎根本无法理解它。 我很熟悉这个概念,因为我已经在 Ogre3D 中实现了它,只是不熟悉 J3D 中的土地法。

预先感谢您的回复:)

I've been searching all evening but can't find the information I'm looking for, or even if it's possible, which is quite distressing ;)

I'm using Java3D and can't figure out how to rotate the camera in world space.

My left/right, and up/down rotation both happen on local space.
Meaning that if I move left and right, everything looks fine.
However if I look 90 degrees down, then look 90 degrees right, everything appears to be on its side.

Currently, I'm doing the following. This will result in the above effects:

TransformGroup cam = universe.getViewingPlatform().getViewPlatformTransform();
Transform3D trfcam = new Transform3D();
cam.getTransform(trfcam);

trfcam.mul(Camera.GetT3D()); //Gets a Transform3D containing how far to rotate left/right and how far to move left/right/forward/back

trfcam.mul(Camera.GetRot()); //Gets a t3d containing how far to rotate up/down

cam.setTransform(trfcam);

Alternatively, one thing I tried was rotating the root, but that rotates around 0, so if I ever move the camera away from 0, it goes bad.
Is there something available on the web that would talk me through how to achieve this kind of thing?
I've tried a lot of different things but just can't seem to get my head around it at all.
I'm familiar with the concept, as I've achieved it in Ogre3D, just not familiar with the law of the land in J3D.

Thanks in advance for replies :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛装女皇 2024-10-10 17:52:03

存储绕每个轴(x 和 y)旋转的弹药,例如,当您尝试绕 x 轴旋转时,反转绕 y 的旋转,绕 x 旋转,然后重新绕 y 旋转。

我不确定我是否正确理解你的第二个问题。由于观察者和模型变换是双重的,因此您可以通过变换世界本身来模拟相机移动。如果您不想平移正在旋转的 x 轴和 y 轴,只需将另一个 TransformGroup 添加到您正在使用的主 TransformGroup 中,然后在新的 TransformGroup 中进行变换即可。

编辑:第一个解决方案非常慢,因此您可以从必须执行的 3 个变换中创建 Transform3D:

假设您已绕 x 轴旋转(Translate3D xrot),现在需要绕 y 旋转:

Translate3D yrot = new Translate3D();  
yrot.rotY(angle); 

Translate3D temp = xot; 
xrot.mul(yrot);  // Dont forget the reverse order. xrot is the previous translate 
xrot.mul(yrot);  // xrot = xrot * yrot * xrot^-1
temp.transpose();  // Get the reverse transform of the old transform
xrot.mul(temp);

yrot = xrot;  // Store it for future rotation around x axis
cam.setTransform(yrot); 

它的工作原理类似对于您所做的许多转换:反转之前完成的操作,进行转换,重做旧的转换。我希望它有帮助。

Store the ammound you have rotated around each axis (x and y), and when you try to rotate around the x axis for example, reverse the the rotation around y, do the rotate around x, then redo the rotation around y.

I'm not sure I understand your second question correctly. Since viewer and model transformations are dual, you can simulate camera moves by transforming the world itself. If you dont want to translate the x and y axis you are rotating around, just add another TransformGroup to the main TransformGroup you are using, and do the transforms in the new one.

Edit: The first solution is quite slow, so you can make a Transform3D out of the 3 transform you have to do:

Say you have rotated around the x axis (Translate3D xrot), and now you need to rotate around y:

Translate3D yrot = new Translate3D();  
yrot.rotY(angle); 

Translate3D temp = xot; 
xrot.mul(yrot);  // Dont forget the reverse order. xrot is the previous translate 
xrot.mul(yrot);  // xrot = xrot * yrot * xrot^-1
temp.transpose();  // Get the reverse transform of the old transform
xrot.mul(temp);

yrot = xrot;  // Store it for future rotation around x axis
cam.setTransform(yrot); 

It works similar for many transformations you make: reverse the previous done, do the transform, redo the old one. I hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文