Example usage for javax.media.j3d BoundingSphere BoundingSphere

List of usage examples for javax.media.j3d BoundingSphere BoundingSphere

Introduction

In this page you can find the example usage for javax.media.j3d BoundingSphere BoundingSphere.

Prototype

public BoundingSphere(Point3d center, double radius) 

Source Link

Document

Constructs and initializes a BoundingSphere from a center and radius.

Usage

From source file:ObjLoad.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.7);/*from w ww  .  j av  a  2 s . co  m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    int flags = ObjectFile.RESIZE;
    if (!noTriangulate)
        flags |= ObjectFile.TRIANGULATE;
    if (!noStripify)
        flags |= ObjectFile.STRIPIFY;
    ObjectFile f = new ObjectFile(flags, (float) (creaseAngle * Math.PI / 180.0));
    Scene s = null;
    try {
        s = f.load(filename);
    } catch (FileNotFoundException e) {
        System.err.println(e);
        System.exit(1);
    } catch (ParsingErrorException e) {
        System.err.println(e);
        System.exit(1);
    } catch (IncorrectFormatException e) {
        System.err.println(e);
        System.exit(1);
    }

    objTrans.addChild(s.getSceneGroup());

    bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    if (spin) {
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
                (float) Math.PI * 2.0f);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);
    }

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    return objRoot;
}

From source file:ConfigObjLoad.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.7);//w  w  w. j av a 2s  .  c  o  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    int flags = ObjectFile.RESIZE;
    if (!noTriangulate)
        flags |= ObjectFile.TRIANGULATE;
    if (!noStripify)
        flags |= ObjectFile.STRIPIFY;
    ObjectFile f = new ObjectFile(flags, (float) (creaseAngle * Math.PI / 180.0));
    Scene s = null;
    try {
        s = f.load(filename);
    } catch (FileNotFoundException e) {
        System.err.println(e);
        System.exit(1);
    } catch (ParsingErrorException e) {
        System.err.println(e);
        System.exit(1);
    } catch (IncorrectFormatException e) {
        System.err.println(e);
        System.exit(1);
    }

    objTrans.addChild(s.getSceneGroup());

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    if (spin) {
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
                (float) Math.PI * 2.0f);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);
    }

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    return objRoot;
}

From source file:GearTest.java

public BranchGroup createSceneGraph(int toothCount) {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);//from  w w  w .j  a va  2  s . co  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objScale.addChild(bgNode);

    // Set up the global lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
    Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f);
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);

    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objScale.addChild(ambientLightNode);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objScale.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objScale.addChild(light2);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objScale.addChild(objTrans);

    // Create an Appearance.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));

    // Create a gear, add it to the scene graph.
    //   SpurGear gear = new SpurGear(toothCount, 1.0f, 0.2f,
    SpurGear gear = new SpurGearThinBody(toothCount, 1.0f, 0.2f, 0.05f, 0.05f, 0.3f, 0.28f, look);
    objTrans.addChild(gear);

    // Create a new Behavior object that will rotate the object and
    // add it into the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 8000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:Text3DLoad.java

public BranchGroup createSceneGraph() {
    float sl = textString.length();
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    t3d.setScale(1.2 / sl);/*from ww  w  .  ja  v  a  2 s  .  c  o  m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    Font3D f3d;
    if (tessellation > 0.0) {
        f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), tessellation, new FontExtrusion());
    } else {
        f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    }
    Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, -1.f, -1.f));
    Shape3D sh = new Shape3D();
    Appearance app = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    app.setMaterial(mm);
    sh.setGeometry(txt);
    sh.setAppearance(app);
    objTrans.addChild(sh);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    if (false) {
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
                (float) Math.PI * 2.0f);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);
    }

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.3f, 0.3f, 0.3f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    return objRoot;
}

From source file:MultiView.java

public BranchGroup createSceneBranchGroup() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    //Make the scene graph
    try {//w w  w.j a  va2s .  c om
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objRoot.addChild(objTrans);

        // Create appearance object for textured cube
        Appearance app = new Appearance();

        Texture tex = new TextureLoader("Dog.jpg", this).getTexture();
        app.setTexture(tex);

        // Create a simple shape leaf node, add it to the scene graph.
        Box textureCube = new Box(2, 3, 4, Box.GENERATE_TEXTURE_COORDS, app);

        objTrans.addChild(textureCube);

        // Create a new Behavior object that will perform the desired
        // operation on the specified transform object and add it into
        // the scene graph.
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
                (float) Math.PI * 2.0f);

        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);
    } catch (RuntimeException e) {
        System.out.println("MultiView.createSceneBranchGroup:" + e.getMessage());
        System.exit(-1);
    }

    return objRoot;
}

From source file:SoundBug.java

void setupSounds() {
    soundSwitch = new Switch(Switch.CHILD_NONE);
    soundSwitch.setWhichChild(Switch.CHILD_NONE);
    soundSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // set up the BoundingSphere for all the sounds
    BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0);

    // Set up the sound media container
    java.net.URL soundURL = null;
    String soundFile = "techno_machine.au";
    try {/*from  w  ww.j  a va2 s.  c  o m*/
        java.net.URL codeBase = null;
        try {
            codeBase = getCodeBase();
        } catch (Exception ex) {
            // got an exception, probably running as an application,
            // keep code base null...
        }
        if (codeBase != null) {
            soundURL = new java.net.URL(codeBase.toString() + soundFile);
        }
    } catch (java.net.MalformedURLException ex) {
        System.out.println(ex.getMessage());
        System.exit(1);
    }
    if (soundURL == null) { // application, try file URL
        try {
            soundURL = new java.net.URL("file:./" + soundFile);
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }
    System.out.println("soundURL = " + soundURL);
    MediaContainer soundMC = new MediaContainer(soundURL);

    // set up the Background Sound
    soundBackground = new BackgroundSound();
    soundBackground.setCapability(Sound.ALLOW_ENABLE_WRITE);
    soundBackground.setSoundData(soundMC);
    soundBackground.setSchedulingBounds(bounds);
    soundBackground.setEnable(true);
    soundBackground.setLoop(Sound.INFINITE_LOOPS);
    soundSwitch.addChild(soundBackground);

    // set up the point sound
    soundPoint = new PointSound();
    soundPoint.setCapability(Sound.ALLOW_ENABLE_WRITE);
    soundPoint.setSoundData(soundMC);
    soundPoint.setSchedulingBounds(bounds);
    soundPoint.setEnable(true);
    soundPoint.setLoop(Sound.INFINITE_LOOPS);
    soundPoint.setPosition(-5.0f, -5.0f, 0.0f);
    Point2f[] distGain = new Point2f[2];
    // set the attenuation to linearly decrease volume from max at
    // source to 0 at a distance of 5m
    distGain[0] = new Point2f(0.0f, 1.0f);
    distGain[1] = new Point2f(5.0f, 0.0f);
    soundPoint.setDistanceGain(distGain);
    soundSwitch.addChild(soundPoint);

}

From source file:ConeYoyoApp.java

public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    objRoot.addChild(objSpin);/*www.  j  a  v a 2  s .  c  o m*/
    objSpin.addChild(new ConeYoyo().getBG());

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, 4000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:ExDepthCue.java

public Group buildScene() {
    // Get the current color
    Color3f color = (Color3f) colors[currentColor].value;

    // Turn off the example headlight
    setHeadlightEnable(false);/*from w ww  .j  a  v  a  2  s.  com*/

    // Create the scene group
    Group scene = new Group();

    // Create a switch group to hold the fog node. This enables
    // us to turn the fog node on and off via the GUI.
    fogSwitch = new Switch();
    fogSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Create influencing bounds
    Bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Set the fog color, density, and its influencing bounds
    fog = new LinearFog();
    fog.setColor(color);
    // front and back distances set below
    fog.setCapability(Fog.ALLOW_COLOR_WRITE);
    fog.setCapability(Fog.ALLOW_INFLUENCING_BOUNDS_WRITE);
    fog.setInfluencingBounds(worldBounds);
    fogSwitch.addChild(fog);
    scene.addChild(fogSwitch);
    if (depthCueOnOff)
        fogSwitch.setWhichChild(0); // on
    else
        fogSwitch.setWhichChild(Switch.CHILD_NONE); // off

    // Set the background color and its application bounds
    //   Usually, the background color should match the fog color
    //   or the results look odd.
    background = new Background();
    background.setColor(color);
    background.setApplicationBounds(worldBounds);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    scene.addChild(background);

    // Build foreground geometry
    Group content = buildIsoline();
    scene.addChild(content);

    // Automatically compute good front and back distances for
    // fog to get good depth-cueing. To do this, first get the
    // dimensions of the bounds around the content. Then,
    // set the front distance to be at the center of the content
    // (or closer by a tad) and the back distance at the front
    // distance PLUS half the depth of the content's bounding box
    BoundingSphere sampleSphere = new BoundingSphere();
    BoundingBox sampleBox = new BoundingBox();
    Bounds bounds = content.getBounds();
    double deltaDistance = 0.0;
    double centerZ = 0.0;

    if (bounds == null) {
        // No bounds available. Estimate the values knowing
        // that the above content is what it is.
        centerZ = 0.5; // 0.5 closer than true center
        deltaDistance = 2.0;
    } else if (bounds.getClass() == sampleSphere.getClass()) {
        BoundingSphere sphereBounds = (BoundingSphere) bounds;
        deltaDistance = Math.abs(sphereBounds.getRadius());
        Point3d center = new Point3d();
        sphereBounds.getCenter(center);
        centerZ = center.z + 0.5; // 0.5 closer than true center
    } else if (bounds.getClass() == sampleBox.getClass()) {
        BoundingBox boxBounds = (BoundingBox) bounds;
        Point3d p1 = new Point3d();
        Point3d p2 = new Point3d();
        boxBounds.getLower(p1);
        boxBounds.getUpper(p2);
        deltaDistance = p2.z - p1.z;
        if (deltaDistance < 0.0)
            deltaDistance *= -1.0;
        if (p1.z > p2.z)
            centerZ = p1.z - deltaDistance / 2.0;
        else
            centerZ = p2.z - deltaDistance / 2.0;
        centerZ += 0.5; // 0.5 closer than true center
    } else {
        System.err.println("Unknown bounds type");
    }

    // Set front distance to the distance from the default
    // viewing position (0,0,10) to the center of the bounds.
    fog.setFrontDistance(10.0f - (float) centerZ);

    // Set back distance to the distance from the default
    // viewing position (0,0,10) to the back of the bounds.
    fog.setBackDistance(10.0f - (float) centerZ + (float) deltaDistance);

    return scene;
}

From source file:AlternateAppearanceScopeTest.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Create influencing bounds
    worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.1f, 0.0f));
    // Shrink the object
    t.setScale(0.8);/*from  w w w. ja  va 2 s . c  om*/

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    otherApp = new Appearance();
    altMat = new Material();
    altMat.setCapability(Material.ALLOW_COMPONENT_WRITE);
    altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
    otherApp.setMaterial(altMat);

    altApp = new AlternateAppearance();
    altApp.setAppearance(otherApp);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ);
    altApp.setInfluencingBounds(worldBounds);
    objRoot.addChild(altApp);

    // Build foreground geometry into two groups. We'll
    // create three directional lights below, one each with
    // scope to cover the first geometry group only, the
    // second geometry group only, or both geometry groups.
    Appearance app1 = new Appearance();
    mat1 = new Material();
    mat1.setCapability(Material.ALLOW_COMPONENT_WRITE);
    mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
    app1.setMaterial(mat1);
    content1 = new SphereGroup(0.05f, // radius of spheres
            0.4f, // x spacing
            0.2f, // y spacing
            3, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content1);
    shapes1 = ((SphereGroup) content1).getShapes();

    content2 = new SphereGroup(0.05f, // radius of spheres
            .4f, // x spacing
            0.2f, // y spacing
            2, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content2);
    shapes2 = ((SphereGroup) content2).getShapes();

    // Add lights
    DirectionalLight light1 = null;
    light1 = new DirectionalLight();
    light1.setEnable(true);
    light1.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight();
    light2.setEnable(true);
    light2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f));
    light2.setInfluencingBounds(worldBounds);
    objRoot.addChild(light2);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional lights are being scoped... otherwise it looks
    // like we're just removing shapes from the scene
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);
    ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    ambient.setInfluencingBounds(worldBounds);
    objRoot.addChild(ambient);

    objRoot.addChild(trans);

    return objRoot;
}

From source file:SimpleGeometry.java

PlatformGeometry createAimer() {

    PlatformGeometry pg = new PlatformGeometry();

    // This TransformGroup will be used by the MouseTranslate
    // utiltiy to move the cylinder around the canvas. when the
    // the user holds down mouse button 3.
    TransformGroup moveTG = new TransformGroup();
    moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    MouseTranslate mouseT = new MouseTranslate(moveTG);
    moveTG.addChild(mouseT);/*from  w  w  w  . ja v a2  s.co m*/
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    mouseT.setSchedulingBounds(bounds);
    pg.addChild(moveTG);

    // This TransformGroup is used to place the cylinder in the scene.
    // The cylinder will be rotated 90 degrees so it will appear as
    // a circle on the screen (could be made into a nice gun site...).
    // The cylinder is also displaced a little in Z so it is in front
    // of the viewer.
    Transform3D xForm = new Transform3D();
    xForm.rotX(Math.PI / 2.0);
    xForm.setTranslation(new Vector3d(0.0, 0.0, -0.7));
    TransformGroup placementTG = new TransformGroup(xForm);
    moveTG.addChild(placementTG);

    // Create the cylinder - make it thin and transparent.
    Appearance cylinderAppearance = new Appearance();
    TransparencyAttributes transAttrs = new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.5f);
    //        cylinderAppearance.setTransparencyAttributes(transAttrs);
    Cylinder aimer = new Cylinder(0.06f, 0.005f, 0, cylinderAppearance);
    placementTG.addChild(aimer);

    return pg;
}