views:

251

answers:

1

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)

+1  A: 

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.

Mikeb
Yes !It is exactly that: in fact, the ViewPlatform is a child of ViewPlatformTransform node, so by attaching my object (cube) to this transform group, it works fine.Thank you very much for your help.
Sobe