Title: RE: [JAVA3D] Camera translation and object

Hi,
I do a similar thing in the game I've just started writing.  The code
fragment below creates a ColorCube and adds it to the camera BranchGroup.

I get strange effects (the red side of ColorCube appears to be coloured graduations
of pink) if I set the Z coordinate of the transform to -1.0f,
presumably because the nearest side of the ColorCube is co-planar with
the near clipping plane?

The other thing I notice is that if I move the ColorCube to -1.4f it displays
correctly but the performance is much worse than having it at -1.0f.  I'm running
on Windows using software rendering.  I guess it's something to do with Z-buffering
calculations being more expensive?

    public BranchGroup createSceneGraph(SimpleUniverse su) {
      Vector3f translate = new Vector3f();

      // Create and add the avatar.
      TransformGroup cameraTG = su.getViewingPlatform().getViewPlatformTransform();
      BranchGroup cameraBG = new BranchGroup();

      translate.set( 0.0f, -0.2f, -1.5f);
      Transform3D avatarT3D = new Transform3D();
      avatarT3D.setTranslation( translate);

      Shape3D avatar = new ColorCube(0.1);
      TransformGroup avatarTG = new TransformGroup( avatarT3D);

      avatarTG.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE);
      avatarTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

      avatarTG.addChild( avatar);
      cameraBG.addChild( avatarTG);
      cameraTG.addChild( cameraBG);

Justin.

> TG1 - TG2 - box
> |__________VP
>
> due the following properties:
> BranchGroup myBGCamera = new BranchGroup();
>
> TransformGroup TGfather = null;
> TransformGroup TGson1 = new TransformGroup();;
> TransformGroup TGson2 = new TransformGroup();
>
> TGson2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
> TGson2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
>
> translate2.set( 0.0f, -0.5f, 0.0f);
> T3D2.setTranslation(translate2);
> TGson2.setTransform(T3D2);
> TGson1.addChild(TGson2);
>
> Shape3D myS3d=new ColorCube(0.5);
> TGson2.addChild(myS3d);
>
> translate.set( 0.0f, 0.0f, 0.0f);
> T3D.setTranslation(translate);
> TGson1.setTransform(T3D);
>
> TGson1 = su.getViewingPlatform().getViewPlatformTransform();
>
> KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(TGson1);
> TGfather.addChild(keyNavBeh);
>
> su.getViewingPlatform().setNominalViewingTransform();
> myBGCamera.addChild(TGfather);
>
> Really I compile and run the program without problems. I visualize the
> Simple Universe Scene, with all its contents. Just, the 3D colorcube
> could
> not be see.
>
> Thnx in advance.
>
> Best wishes,
> Thomas

Reply via email to