Example usage for javax.media.j3d AmbientLight AmbientLight

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

Introduction

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

Prototype

public AmbientLight(boolean lightOn, Color3f color) 

Source Link

Document

Constructs and initializes an ambient light using the specified parameters.

Usage

From source file:ModelClipTest2.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.4);/*  w ww.j  av  a 2  s  . c  o  m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    //Shine it with two colored lights.
    Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);

    AmbientLight lgt0 = new AmbientLight(true, lColor2);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt0.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt0);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    // Create a Transformgroup for the geometry
    TransformGroup objRot = new TransformGroup();
    Transform3D t3d1 = new Transform3D();
    AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f);
    t3d1.setRotation(rot1);
    objRot.setTransform(t3d1);
    objScale.addChild(objRot);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap);
    objRot.addChild(CylinderObj);

    //Create a box
    Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap);
    objRot.addChild(BoxObj);

    // This Transformgroup is used by the mouse manipulators to
    // move the model clip planes.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRot.addChild(objTrans);

    // Create the rotate behavior node
    MouseRotate behavior = new MouseRotate(objTrans);
    objTrans.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(objTrans);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn);
    mc.setEnable(1, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

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

    return objRoot;
}

From source file:VrmlPickingTest.java

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

    Bounds lightBounds = getApplicationBounds();

    AmbientLight ambLight = new AmbientLight(true, new Color3f(1.0f, 1.0f, 1.0f));
    ambLight.setInfluencingBounds(lightBounds);
    objRoot.addChild(ambLight);/*  w w  w .j  a v a2  s.  c o  m*/

    DirectionalLight headLight = new DirectionalLight();
    headLight.setInfluencingBounds(lightBounds);
    objRoot.addChild(headLight);

    TransformGroup mouseGroup = createMouseBehaviorsGroup();

    String vrmlFile = null;

    try {
        URL codebase = getWorkingDirectory();
        vrmlFile = codebase.toExternalForm() + "BoxConeSphere.wrl";
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (m_szCommandLineArray != null) {
        switch (m_szCommandLineArray.length) {
        case 0:
            break;

        case 1:
            vrmlFile = m_szCommandLineArray[0];
            break;

        default:
            System.err.println("Usage: VrmlPickingTest [pathname|URL]");
            System.exit(-1);
        }
    }

    BranchGroup sceneRoot = loadVrmlFile(vrmlFile);

    if (sceneRoot != null)
        mouseGroup.addChild(sceneRoot);

    objRoot.addChild(mouseGroup);

    return objRoot;
}

From source file:PickCollisionTest.java

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

    Bounds lightBounds = getApplicationBounds();

    AmbientLight ambLight = new AmbientLight(true, new Color3f(1.0f, 1.0f, 1.0f));
    ambLight.setInfluencingBounds(lightBounds);
    objRoot.addChild(ambLight);// w  w w.  j a  va2  s.  co  m

    DirectionalLight headLight = new DirectionalLight();
    headLight.setInfluencingBounds(lightBounds);
    objRoot.addChild(headLight);

    // create ColorCube objects, one for each side of a cube
    addCube(objRoot, 0, boxSize, 0, boxSize, 0.1, boxSize, "Top", false);
    addCube(objRoot, 0, -boxSize, 0, boxSize, 0.1, boxSize, "Bottom", false);
    addCube(objRoot, boxSize, 0, 0, 0.1, boxSize, boxSize, "Right", false);
    addCube(objRoot, -boxSize, 0, 0, 0.1, boxSize, boxSize, "Left", false);
    addCube(objRoot, 0, 0, -boxSize, boxSize, boxSize, 0.1, "Back", false);
    addCube(objRoot, 0, 0, boxSize, boxSize, boxSize, 0.1, "Front", true);

    // create the spheres
    addSphere(objRoot, 0, 3, 4, new Vector3d(0.1, 0.3, 0.1), "Sphere 1");
    addSphere(objRoot, 3, 0, -2, new Vector3d(0.4, 0.1, 0.2), "Sphere 2");
    addSphere(objRoot, 0, -3, 0, new Vector3d(0.2, 0.2, 0.6), "Sphere 3");
    addSphere(objRoot, -3, 0, -4, new Vector3d(0.1, 0.6, 0.3), "Sphere 4");

    return objRoot;
}

From source file:Demo3D.java

/**
 * Create the subgraph #1/*from   ww  w  . j a va 2s. c  o  m*/
 * 
 * @return javax.media.j3d.BranchGroup brGr1 - the root of the subgraph #1
 */
public BranchGroup mySubGraph1() {
    // Create the BranchGroup brGr1 of the subgraph #1.
    brGr1 = new BranchGroup();

    // Create and attach the coordinate system to the brGr1.
    coordSyst = new CoordSyst(1.0f, 1.0f, 0.0f, // Color of the x-axis
            0.0f, 0.0f, 1.0f, // Color of the y-axis
            1.0f, 0.0f, 0.0f, // Color of the z-axis
            0.75f); // Lenght of the 3 axes
    brGr1.addChild(coordSyst);

    // Background setting for the scene.
    newTextureLoader = new NewTextureLoader("Images/Ciel_Out.jpg");
    newTextureLoader.setImageObserver(newTextureLoader.getImageObserver());
    backGr = new Background(newTextureLoader.getImage());
    backGr.setImageScaleMode(Background.SCALE_FIT_ALL);
    boundsBackGr = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0);
    backGr.setApplicationBounds(boundsBackGr);
    brGr1.addChild(backGr);

    // A BoundingSphere instance as general bounding region.
    boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Lighting of the scene.

    // Create and attach an ambient light.
    ambientLight = new AmbientLight(true, new Color3f(0.2f, 0.2f, 0.2f));
    ambientLight.setInfluencingBounds(boundsGen);
    brGr1.addChild(ambientLight);

    // Create and attach a point light.
    pointLight = new PointLight(true, new Color3f(1.0f, 1.0f, 0.3f), new Point3f(-100.0f, 0.0f, 100.0f),
            new Point3f(0.0f, 0.05f, 0.1f));
    pointLight.setInfluencingBounds(boundsGen);
    brGr1.addChild(pointLight);

    // Create and attach a directional light.
    directionalLight = new DirectionalLight(true, new Color3f(0.8f, 1.0f, 1.0f),
            new Vector3f(-0.5f, -0.5f, -0.5f));
    directionalLight.setInfluencingBounds(boundsGen);
    brGr1.addChild(directionalLight);

    // Create the borders of the virtual universe for the inside view of the
    // scene.
    bordersIn = new BordersIn(dimUniverse);
    brGr1.addChild(bordersIn.myInternalUniverse());

    // Create the borders of the virtual universe for the outside view of
    // the scene.
    bordersOut = new BordersOut(dimUniverse);
    brGr1.addChild(bordersOut.myExternalUniverse());

    // Compile the subgraph to optimize the performances.
    brGr1.compile();

    // Return the final version of the BranchGroup node brGr1
    return brGr1;
}