Example usage for javax.media.j3d Background setColor

List of usage examples for javax.media.j3d Background setColor

Introduction

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

Prototype

public void setColor(Color3f color) 

Source Link

Document

Sets the background color to the specified color.

Usage

From source file:LocalEyeApp.java

public LocalEyeApp() {
    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(null);
    add("Center", c);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);

    BranchGroup scene = new BranchGroup();

    TransformGroup trans11 = createTG(-0.7f, 0.7f, -0.5f);
    scene.addChild(trans11);/*from w  w w . j a va2s  .c  om*/
    trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans12 = createTG(0.0f, 0.7f, -0.5f);
    scene.addChild(trans12);
    trans12.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans13 = createTG(0.7f, 0.7f, -0.5f);
    scene.addChild(trans13);
    trans13.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans21 = createTG(-0.7f, 0.0f, -0.5f);
    scene.addChild(trans21);
    trans21.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans22 = createTG(0.0f, 0.0f, -0.5f);
    scene.addChild(trans22);
    trans22.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans23 = createTG(0.7f, 0.0f, -0.5f);
    scene.addChild(trans23);
    trans23.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans31 = createTG(-0.7f, -0.7f, -0.5f);
    scene.addChild(trans31);
    trans31.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans32 = createTG(0.0f, -0.7f, -0.5f);
    scene.addChild(trans32);
    trans32.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans33 = createTG(0.7f, -0.7f, -0.5f);
    scene.addChild(trans33);
    trans33.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f);
    direction.normalize();
    lightD1.setDirection(direction);
    lightD1.setColor(red);
    scene.addChild(lightD1);

    PointLight lightP1 = new PointLight();
    lightP1.setInfluencingBounds(new BoundingSphere());
    Point3f position = new Point3f(0.0f, 0.0f, 1.0f);
    lightP1.setPosition(position);
    scene.addChild(lightP1);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere());
    background.setColor(white);
    scene.addChild(background);

    SimpleUniverse u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    //Enable Local Eye Lighting
    u.getViewer().getView().setLocalEyeLightingEnable(true);

    u.addBranchGraph(scene);
}

From source file:ExAppearance.java

public Group buildScene() {
    // Turn off the example headlight
    setHeadlightEnable(false);// w ww . ja  v a  2s  .  c  om

    // Build the scene group
    Group objRoot = new Group();

    // 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);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

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

    // Add a background
    Background background = new Background();
    background.setColor(new Color3f(0.0f, 0.5f, 1.0f));
    background.setApplicationBounds(bounds);
    objRoot.addChild(background);

    // 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.9;
        for (int j = 0; j < 3; j++) {
            double xpos = (double) (j - 1) * 2.1;
            objRoot.addChild(createObject(app[i][j], 1.0, xpos, ypos));
        }
    }

    return objRoot;
}