Skip to main content

Background position

2 replies [Last post]
diesel_boy
Offline
Joined: 2013-05-31
Points: 0

Hi everyone, houpe for your help.

My task is to make 3d scene backgound from picture (background.png), that have less size, than canvas3d area have. Like that:

class onScreenCanvas3D extends Canvas3D {};
  BranchGroup objRoot = new BranchGroup();
  ***
   // init block
  canvas3D = new onScreenCanvas3D(config, true);
  canvas3D.setSize(1000, 1000); // Size of canvas 1000px / 1000px
  canvas3D.getScreen3D().setSize(1000, 1000);
  canvas3D.getScreen3D().setPhysicalScreenWidth(2f);
  canvas3D.getScreen3D().setPhysicalScreenHeight(2f / 10000);

  ***
  public void add_background( BufferedImage pic )
   {
    // Size of pic is: 100 px / 100 px
    Background bgImage = new Background(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, pic));
    bgImage.setApplicationBounds(new BoundingBox());
    objRoot.addChild(bgImage);
   }

And my question is: how can i change the position of Background object in my 3d space? Because my picture only shown in top left corner, and i need it to be in center of coordinates.

Sorry for my Eanglish.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
interactivemesh
Offline
Joined: 2006-06-07
Points: 0

Check out the Java 3D apidoc for Background.setImageScaleMode(int imageScaleMode).

bgImage.setImageScaleMode(Background.SCALE_NONE_CENTER);

bgImage.setImageScaleMode(Background.SCALE_FIT_ALL);

August

diesel_boy
Offline
Joined: 2013-05-31
Points: 0

Amazing, some things are so hard for my intuition.
Thanks a lot! You're realy helpful!