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:MixedTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

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

    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);//  ww w  .j  ava2  s  .  com

    objTrans.addChild(new ColorCube());
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:Position.java

public Position() {
    SimpleUniverse universe = new SimpleUniverse();
    BranchGroup group = new BranchGroup();
    // X axis made of spheres
    for (float x = -1.0f; x <= 1.0f; x = x + 0.1f) {
        Sphere sphere = new Sphere(0.05f);
        TransformGroup tg = new TransformGroup();
        Transform3D transform = new Transform3D();
        Vector3f vector = new Vector3f(x, .0f, .0f);
        transform.setTranslation(vector);
        tg.setTransform(transform);//  ww  w  .j  a  v  a  2s  . co m
        tg.addChild(sphere);
        group.addChild(tg);
    }
    // Y axis made of cones
    for (float y = -1.0f; y <= 1.0f; y = y + 0.1f) {
        TransformGroup tg = new TransformGroup();
        Transform3D transform = new Transform3D();
        Cone cone = new Cone(0.05f, 0.1f);
        Vector3f vector = new Vector3f(.0f, y, .0f);
        transform.setTranslation(vector);
        tg.setTransform(transform);
        tg.addChild(cone);
        group.addChild(tg);
    }
    // Z axis made of cylinders
    for (float z = -1.0f; z <= 1.0f; z = z + 0.1f) {
        TransformGroup tg = new TransformGroup();
        Transform3D transform = new Transform3D();
        Cylinder cylinder = new Cylinder(0.05f, 0.1f);
        Vector3f vector = new Vector3f(.0f, .0f, z);
        transform.setTranslation(vector);
        tg.setTransform(transform);
        tg.addChild(cylinder);
        group.addChild(tg);
    }

    Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    group.addChild(light1);
    universe.getViewingPlatform().setNominalViewingTransform();

    // add the group of objects to the Universe
    universe.addBranchGraph(group);
}

From source file:PickText3DGeometry.java

public BranchGroup createSceneGraph(Canvas3D canvas) {
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
    Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    Transform3D t;//from ww w  .ja  va2  s .c om

    // 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);
    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
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion());

    Text3D text3D = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.7f, 0.0f));
    text3D.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D1 = new Shape3D();
    s3D1.setGeometry(text3D);
    s3D1.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg1 = new TransformGroup();
    spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg1.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg1.addChild(s3D1);
    objScale.addChild(spinTg1);

    Text3D pick = new Text3D(f3d, new String("Pick me"), new Point3f(-2.0f, -0.7f, 0.0f));
    pick.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D2 = new Shape3D();
    s3D2.setGeometry(pick);
    s3D2.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg2 = new TransformGroup();
    spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg2.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg2.addChild(s3D2);
    objScale.addChild(spinTg2);

    // Create the transform group node for the each light and initialize
    // it to the identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add them to the root
    // of the subgraph.

    // Create transformations for the positional lights
    t = new Transform3D();
    Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
    t.set(lPos1);
    TransformGroup l1Trans = new TransformGroup(t);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l1Trans);

    t = new Transform3D();
    Vector3d lPos2 = new Vector3d(0.5, 1.2, 2.0);
    t.set(lPos2);
    TransformGroup l2Trans = new TransformGroup(t);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l2Trans);

    // Create Geometry for point lights
    ColoringAttributes caL1 = new ColoringAttributes();
    ColoringAttributes caL2 = new ColoringAttributes();
    caL1.setColor(lColor1);
    caL2.setColor(lColor2);
    Appearance appL1 = new Appearance();
    Appearance appL2 = new Appearance();
    appL1.setColoringAttributes(caL1);
    appL2.setColoringAttributes(caL2);
    l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL1));
    l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL2));

    // Create lights
    AmbientLight aLgt = new AmbientLight(alColor);

    Light lgt1;
    Light lgt2;

    Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
    lgt1 = new PointLight(lColor1, lPoint, atten);
    lgt2 = new PointLight(lColor2, lPoint, atten);

    // Set the influencing bounds
    aLgt.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    objScale.addChild(aLgt);
    l1Trans.addChild(lgt1);
    l2Trans.addChild(lgt2);

    PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds);
    behavior1.setMode(PickTool.GEOMETRY);
    behavior1.setTolerance(0.0f);
    objRoot.addChild(behavior1);

    PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
    behavior2.setMode(PickTool.GEOMETRY);
    behavior2.setTolerance(0.0f);
    objRoot.addChild(behavior2);

    PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
    behavior3.setMode(PickTool.GEOMETRY);
    behavior3.setTolerance(0.0f);
    objRoot.addChild(behavior3);

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

    return objRoot;
}

From source file:TriangulatorTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    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);/*w  w  w.  ja  v a  2  s .c om*/

    // triangulate the polygon
    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);

    gi.setCoordinates(m_VertexArray);

    int[] stripCountArray = { 10, 5 };
    int[] countourCountArray = { stripCountArray.length };

    gi.setContourCounts(countourCountArray);
    gi.setStripCounts(stripCountArray);

    Triangulator triangulator = new Triangulator();
    triangulator.triangulate(gi);

    NormalGenerator normalGenerator = new NormalGenerator();
    normalGenerator.generateNormals(gi);

    // create an appearance
    Appearance ap = new Appearance();

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    ap.setPolygonAttributes(polyAttrbutes);

    // add both a wireframe and a solid version
    // of the triangulated surface
    Shape3D shape1 = new Shape3D(gi.getGeometryArray(), ap);
    Shape3D shape2 = new Shape3D(gi.getGeometryArray());

    objTrans.addChild(shape1);
    objTrans.addChild(shape2);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:TickTockPicking.java

public BranchGroup createSceneGraph(Canvas3D c) {
    // 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);//w  w w . jav a2 s  . c  o m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and behaviors
    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 bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objScale.addChild(aLgt);
    objScale.addChild(lgt1);

    // Create a pair of transform group nodes and initialize them to
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behaviors can modify them at runtime. Add them to the
    // root of the subgraph.
    TransformGroup objTrans1 = new TransformGroup();
    objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objScale.addChild(objTrans1);

    TransformGroup objTrans2 = new TransformGroup();
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans1.addChild(objTrans2);

    // Create the positioning and scaling transform group node.
    Transform3D t = new Transform3D();
    t.set(0.3, new Vector3d(0.0, -1.5, 0.0));
    TransformGroup objTrans3 = new TransformGroup(t);
    objTrans2.addChild(objTrans3);

    // Create a simple shape leaf node, set it's appearance, and
    // add it to the scene graph.
    Shape3D shape = new Cube();
    Appearance a = new Appearance();
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f);
    a.setMaterial(new Material(objColor, black, objColor, white, 80.0f));
    shape.setAppearance(a);
    shape.setCapability(shape.ALLOW_APPEARANCE_READ);
    shape.setCapability(shape.ALLOW_APPEARANCE_WRITE);
    objTrans3.addChild(shape);

    // Create a new Behavior object that will perform the desired
    // rotation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis1 = new Transform3D();
    yAxis1.rotX(Math.PI / 2.0);
    Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500,
            200, 5000, 2500, 200);

    RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1,
            -(float) Math.PI / 2.0f, (float) Math.PI / 2.0f);
    tickTock.setSchedulingBounds(bounds);
    objTrans2.addChild(tickTock);

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

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

    // Now create the simple picking behavior
    PickHighlightBehavior pickBeh = new PickHighlightBehavior(c, objRoot, bounds);

    // Create a bunch of objects with a behavior and add them
    // into the scene graph.

    int row, col;
    Appearance[][] app = new Appearance[3][3];

    for (row = 0; row < 3; row++)
        for (col = 0; col < 3; col++)
            app[row][col] = createAppearance(row * 3 + col);

    for (int i = 0; i < 3; i++) {
        double ypos = (double) (i - 1) * 1.5;
        for (int j = 0; j < 3; j++) {
            double xpos = (double) (j - 1) * 1.5;
            objScale.addChild(createObject(app[i][j], 0.3, xpos, ypos));
        }
    }

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

    return objRoot;
}

From source file:SphereMotion.java

public BranchGroup createSceneGraph(SimpleUniverse u) {
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
    Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    Transform3D t;// w w w.  jav  a2 s . c om

    // 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);
    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
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    // Create a Sphere object, generate one copy of the sphere,
    // and add it into the scene graph.
    Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 80, a);
    objScale.addChild(sph);

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

    TransformGroup l2RotTrans = new TransformGroup();
    l2RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objScale.addChild(l2RotTrans);

    // Create transformations for the positional lights
    t = new Transform3D();
    Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
    t.set(lPos1);
    TransformGroup l1Trans = new TransformGroup(t);
    l1RotTrans.addChild(l1Trans);

    t = new Transform3D();
    Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
    t.set(lPos2);
    TransformGroup l2Trans = new TransformGroup(t);
    l2RotTrans.addChild(l2Trans);

    // Create Geometry for point lights
    ColoringAttributes caL1 = new ColoringAttributes();
    ColoringAttributes caL2 = new ColoringAttributes();
    caL1.setColor(lColor1);
    caL2.setColor(lColor2);
    Appearance appL1 = new Appearance();
    Appearance appL2 = new Appearance();
    appL1.setColoringAttributes(caL1);
    appL2.setColoringAttributes(caL2);
    l1Trans.addChild(new Sphere(0.05f, appL1));
    l2Trans.addChild(new Sphere(0.05f, appL2));

    // Create lights
    AmbientLight aLgt = new AmbientLight(alColor);

    Light lgt1 = null;
    Light lgt2 = null;

    Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
    Vector3f lDirect1 = new Vector3f(lPos1);
    Vector3f lDirect2 = new Vector3f(lPos2);
    lDirect1.negate();
    lDirect2.negate();

    switch (lightType) {
    case DIRECTIONAL_LIGHT:
        lgt1 = new DirectionalLight(lColor1, lDirect1);
        lgt2 = new DirectionalLight(lColor2, lDirect2);
        break;
    case POINT_LIGHT:
        lgt1 = new PointLight(lColor1, lPoint, atten);
        lgt2 = new PointLight(lColor2, lPoint, atten);
        break;
    case SPOT_LIGHT:
        lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1, 25.0f * (float) Math.PI / 180.0f, 10.0f);
        lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2, 25.0f * (float) Math.PI / 180.0f, 10.0f);
        break;
    }

    // Set the influencing bounds
    aLgt.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    objScale.addChild(aLgt);
    l1Trans.addChild(lgt1);
    l2Trans.addChild(lgt2);

    // 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 rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator1 = new RotationInterpolator(rotor1Alpha, l1RotTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator1.setSchedulingBounds(bounds);
    l1RotTrans.addChild(rotator1);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into the
    // scene graph.
    Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 1000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator2 = new RotationInterpolator(rotor2Alpha, l2RotTrans, yAxis, 0.0f, 0.0f);
    bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator2.setSchedulingBounds(bounds);
    l2RotTrans.addChild(rotator2);

    // Create a position interpolator and attach it to the view
    // platform
    TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform();
    Transform3D axisOfTranslation = new Transform3D();
    Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000,
            0, 0);
    axisOfTranslation.rotY(-Math.PI / 2.0);
    PositionInterpolator translator = new PositionInterpolator(transAlpha, vpTrans, axisOfTranslation, 2.0f,
            3.5f);
    translator.setSchedulingBounds(bounds);
    objScale.addChild(translator);

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

    return objRoot;
}

From source file:OrientedPtTest.java

public BranchGroup createSceneGraph() {

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

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);// ww  w.  ja v a  2s . c o  m
    objScale.setTransform(textMat);

    // 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);
    objRoot.addChild(objTrans);

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

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Point3f textPt = new Point3f(-sl / 2.0f, 3.0f, 0.0f);
    Text3D txt = new Text3D(f3d, textString, textPt);
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);

    textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
    // text is centered around 0, 3, 0. Make it rotate around 0,5,0
    Point3f rotationPt = new Point3f(0.0f, 5.0f, 0.0f);
    textShape.setRotationPoint(rotationPt);
    objScale.addChild(textShape);

    // also add a small Sphere at the rotation point to
    // show that we are rotating around the right point
    Sphere sphere = new Sphere(0.2f);
    TransformGroup sphereGroup = new TransformGroup();
    Transform3D sphereXform = new Transform3D();
    sphereXform.set(new Vector3f(rotationPt));
    sphereGroup.setTransform(sphereXform);
    sphereGroup.addChild(sphere);
    objScale.addChild(sphereGroup);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.REPLACE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());
    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // 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, 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);

    apText.setMaterial(mm);

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

    return objRoot;
}

From source file:HelloUniverse.java

public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);/*www. j  ava  2  s . c om*/
    objTrans.addChild(new ColorCube(0.2));
    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);
    return objRoot;
}

From source file:FPSCounterDemo.java

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

   // Create the TransformGroup node and initialize it to the
   // identity. Enable the TRANSFORM_WRITE capability so that
   // our behavior code can modify it at run time. Add it to
   // the root of the subgraph.
   TransformGroup objTrans = new TransformGroup();
   objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
   objRoot.addChild(objTrans);/*from w  w  w . j  a  va 2  s  .c o  m*/

   // Create a simple Shape3D node; add it to the scene graph.
   objTrans.addChild(new ColorCube(0.4));

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

   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);
   objRoot.addChild(rotator);

   // Create the Framecounter behavior
   fpsCounter.setSchedulingBounds(bounds);
   objRoot.addChild(fpsCounter);

   return objRoot;
}

From source file:CuboidTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

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

    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);//  w  w  w. j  a va2  s. co m

    // create an appearance
    Appearance ap = new Appearance();

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    ap.setPolygonAttributes(polyAttrbutes);

    objTrans.addChild(new Cuboid(50, 30, 20, ap));
    objTrans.addChild(new Box(25, 15, 10, ap));

    objRoot.addChild(objTrans);

    return objRoot;
}