|
I want to use the J3D library (www.j3d.org) to add some
2D overlays to my scene. my problems is, that I
just can't
figure out, why even the provided example does not
display
any overlays. anybody got suggestions
please?
here is the sample code, I use (it actually is same
as the
example provided with the J3D code
repository):
public class LabelDemo extends
DemoFrame
{ private static final double BACK_CLIP_DISTANCE = 100.0; /** The overlay we're putting
labels on */
private LabelOverlay overlay; /**
* Construct a new demo with no geometry currently showing, but the * default type is set to quads. */ public LabelDemo() { super("Label test window");
buildScene();
overlay.initialize();
} /**
* Build the scenegraph for the canvas */ private void buildScene() { Color3f white = new Color3f(1, 1, 1);
VirtualUniverse universe = new
VirtualUniverse();
Locale locale = new Locale(universe);
BranchGroup view_group = new
BranchGroup();
BranchGroup world_object_group = new BranchGroup();
ViewPlatform camera = new ViewPlatform();
Transform3D angle = new
Transform3D();
angle.setTranslation(new Vector3d(0, 2, 10));
TransformGroup view_tg = new
TransformGroup(angle);
view_tg.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND); view_tg.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); view_tg.addChild(camera);
//
com.sun.j3d.utils.geometry.ColorCube cc = new com.sun.j3d.utils.geometry.ColorCube(10.0); Transform3D cc_tr = new Transform3D(); cc_tr.setTranslation(new Vector3d(0.0, 0.0, -30.0)); TransformGroup cc_grp = new TransformGroup(cc_tr); cc_grp.addChild(cc);
view_group.addChild(view_tg);
view_group.addChild(cc_grp); Point3d
origin = new Point3d(0, 0, 0);
BoundingSphere light_bounds = new BoundingSphere(origin, BACK_CLIP_DISTANCE); DirectionalLight headlight = new DirectionalLight(); headlight.setColor(white); headlight.setInfluencingBounds(light_bounds); view_tg.addChild(headlight); // And
the axis...
Axis axis = new Axis(); world_object_group.addChild(axis); world_object_group.compile(); // Add
them to the locale
PhysicalBody body = new PhysicalBody(); PhysicalEnvironment env = new PhysicalEnvironment(); View
view = new View();
view.setBackClipDistance(BACK_CLIP_DISTANCE); view.setPhysicalBody(body); view.setPhysicalEnvironment(env); view.addCanvas3D(canvas); view.attachViewPlatform(camera); overlay
= new
LabelOverlay(canvas,
new Rectangle(10, 10, 100, 50), "hello world"); overlay.setVisible(true);
view_tg.addChild(overlay.getRoot());
overlay.repaint(); locale.addBranchGraph(view_group);
locale.addBranchGraph(world_object_group);
} public static void main(String[]
argv)
{ LabelDemo demo = new LabelDemo(); demo.setVisible(true); } } greets,
barney
|
- Re: [JAVA3D] Troubles with 2D overlay Gerhard Gelbmann
- Re: [JAVA3D] Troubles with 2D overlay Alan Hudson
- Re: [JAVA3D] Troubles with 2D overlay Gerhard Gelbmann
