简体   繁体   English

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

[英]Attach an object to the view platform in Java3D

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. 在我的Java3D应用程序中,我有一个可移动的查看平台(例如,感谢“OrbitBehavior”和“KeyNavigatorBehavior”行为),所以我可以将我的观点改为场景。 Now, I would like to add an object which is "static" over my view, ie always viewed the same way when I move my view (for example, like the gun of the player in a FPS). 现在,我想在我的视图中添加一个“静态”的对象,即在我移动视图时总是以相同的方式查看(例如,像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). 1 /直接将我的对象附加到ViewingPlatform(通过专用BranchGroup加一个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) 代码:( 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/ 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. 2 /在我的对象上应用相同的变换(旋转+平移;通过getViewPlatformTransform()上的getTransform()检索 - 我也尝试了一些更复杂的东西,这些变换与视图PF和对象的初始位置之间的操作)作为观察平台的一个。 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). 在这里,当我移动视图时,我的对象消失,然后当我使用KeyNavigator的缩放/缩小动作时,有时会再次出现(但是以一种非常不稳定的方式)。

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) (PS:由于英语不是我的母语,我在解释我的问题时可能会非常混乱:不要犹豫,让我再写一些不可理解的部分)

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. 我不是100%确定这是否有效,但我查看了一些文档 - ( http://graphcomp.com/info/specs/java3d/j3dguide/Intro.doc.html#47470 ),我想你必须反转场景图中的顺序。 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. 如果将ColorCube附加到该变换组,然后将视图平台附加到该颜色多维数据集,则视图和多维数据集应一起移动。 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. 控制相机的用户正在操纵变换组在分支的上方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM