Hello,
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)