在 Java3D 中将对象附加到视图平台

发布于 2024-08-08 00:21:45 字数 1265 浏览 5 评论 0原文

在我的 Java3D 应用程序中,我有一个可移动的查看平台(例如,得益于“OrbitBehavior”和“KeyNavigatorBehavior”行为),因此我可以更改场景的视角。 现在,我想在我的视图上添加一个“静态”的对象,即当我移动视图时总是以相同的方式查看(例如,像 FPS 中玩家的枪)。 到目前为止,我尝试了以下两种方法来解决这个问题,但都不起作用。

1/ 将我的对象直接附加到 ViewingPlatform(通过专用的 BranchGroup 和 TransformGroup)。 在这种情况下,我的对象根本没有显示(我绝对不确定它实际上是否允许执行这样的操作......)。这是我的代码的这一部分:

代码:(使用view ViewingPlatform)

BranchGroup fixedBG = new BranchGroup();
TransformGroup fixedTG = new TransformGroup();
fixedTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
fixedTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D transfo = new Transform3D();
transfo.setTranslation(new Vector3f(0.2f, 0.0f, -1.0f));
fixedTG.setTransform(transfo);
ColorCube fixedCube = new ColorCube(0.2);
fixedTG.addChild(fixedCube);
view.addChild(fixedBG);

2/对我的对象应用相同的转换(旋转+平移) ;通过 getViewPlatformTransform() 上的 getTransform() 检索 - 我在这里还尝试了一些更复杂的操作,将这些转换与视图 PF 和对象的初始位置之间的操作作为查看平台的操作。我通过专用行为实时完成所有这些工作(与修改视图位置的行为相同的唤醒条件)。 在这里,当我移动视图时,我的对象消失,然后当我使用 KeyNavigator 的缩放/缩小操作时有时会再次出现(但以一种非常不稳定的方式)。

我确信我想做的事情是可行的,而且可能非常简单,但现在,我不知道...

提前感谢您的帮助

(PS:因为英语不是我的母语语言,我在解释我的问题时可能会很混乱:请毫不犹豫地要求我再次写下无法理解的部分)

In my Java3D application, I have a movable viewing platform (thanks to "OrbitBehavior" and "KeyNavigatorBehavior" behaviors for example) so I can change my point of view to the scene.
Now, I would like to add an object which is "static" over my view, i.e. always viewed the same way when I move my view (for example, like the gun of the player in a FPS).
By now, I tried the 2 following approaches to this problem, but none of them worked.

1/ Attach directly my object to the ViewingPlatform (via a dedicated BranchGroup plus a TransformGroup).
In this case, my object is simply not displayed (I'm absolutely not sure it's allowed to perform such an operation actually...). This is this part of my code:

Code : (with view the ViewingPlatform)

BranchGroup fixedBG = new BranchGroup();
TransformGroup fixedTG = new TransformGroup();
fixedTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
fixedTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D transfo = new Transform3D();
transfo.setTranslation(new Vector3f(0.2f, 0.0f, -1.0f));
fixedTG.setTransform(transfo);
ColorCube fixedCube = new ColorCube(0.2);
fixedTG.addChild(fixedCube);
view.addChild(fixedBG);

2/ Apply to my object the same transformation (rotation + translation ; retrieved via getTransform() on getViewPlatformTransform() - I also tried something more complex here, with operations between these transformations and initial positions of view PF and object) as viewing platform's one. I do all this in real time, with a dedicated behavior (same wake-up conditions as behaviors modifying the view location).
Here, my object disappears when I move the view, and then appears again sometimes, when I use the zoom/de-zoom action of the KeyNavigator (butin a really unstable way).

I'm sure that what I'm trying to do is doable and probably quite simple, but now, I don't have a clue...

Thanks by advance for your help

(PS: As English is not my native language, I may be quite messy in explaining my problem: do not hesitate to ask me to write again un-understandable parts)

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

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

发布评论

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

评论(1

末蓝 2024-08-15 00:21:45

我不是 100% 确定这是否有效,但我查看了一些文档 - (http://graphcomp.com/info/specs/java3d/j3dguide/Intro.doc.html#47470),我认为您必须反转场景图中的顺序。因此,通常情况下,您的视图平台挂在一个转换组上,该转换组又挂在一个分支组上,而分支组又挂在语言环境上。变换组决定了视图的方向。如果将 ColorCube 连接到该变换组,然后将视图平台连接到该颜色立方体,那么视图和立方体应该一起移动。我认为,您可以插入另一个变换组,以从视图中偏移立方体。控制相机的用户正在操纵分支上方的变换组。

I'm not 100% sure if this would work, but I reviewed some documentation - (http://graphcomp.com/info/specs/java3d/j3dguide/Intro.doc.html#47470) for example, and I think you have to invert the order in the scene graph. So, normally, your view platform hangs off of a transform group that hangs off a branch group that hangs off the locale. The transform group is what orients the view. If you attach your ColorCube to that transform group, then your view platform to that color cube, then the view and the cube should move together. You could interpose another transform group, I think, to offset the cube from the view. The user controlling the camera is manipulating the transform group higher up the branch.

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