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(Color3f color) 

Source Link

Document

Constructs and initializes an ambient light using the specified parameters.

Usage

From source file:SimpleMouse.java

/**
 * Add some lights to the scene graph//from   ww w  .  java2  s. c om
 * 
 * @param b
 *            BranchGroup that the lights are added to
 */
protected void addLights(BranchGroup b) {
    Color3f ambLightColour = new Color3f(0.5f, 0.5f, 0.5f);
    AmbientLight ambLight = new AmbientLight(ambLightColour);
    ambLight.setInfluencingBounds(bounds);
    Color3f dirLightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f dirLightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight dirLight = new DirectionalLight(dirLightColour, dirLightDir);
    dirLight.setInfluencingBounds(bounds);
    b.addChild(ambLight);
    b.addChild(dirLight);
}

From source file:SimpleDirLight.java

/**
 * This creates some lights and adds them to the BranchGroup.
 * //from   www.  j  av  a2 s.c  om
 * @param b
 *            BranchGroup that the lights are added to.
 */
protected void addLights(BranchGroup b) {
    // Create a bounds for the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    //Set up the ambient light
    Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight ambientLight = new AmbientLight(ambientColour);
    ambientLight.setInfluencingBounds(bounds);
    //Set up the directional light
    Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight light = new DirectionalLight(lightColour, lightDir);
    light.setInfluencingBounds(bounds);
    //Add the lights to the BranchGroup
    b.addChild(ambientLight);
    b.addChild(light);
}

From source file:SimpleSpotLights.java

/**
 * This creates some lights and adds them to the BranchGroup.
 * //from  w  w  w  .j a v  a2 s.  c o  m
 * @param b
 *            BranchGroup that the lights are added to.
 */
protected void addLights(BranchGroup b) {
    // Create a bounds for the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    //Set up the ambient light
    Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight ambientLight = new AmbientLight(ambientColour);
    ambientLight.setInfluencingBounds(bounds);
    Color3f blueColour = new Color3f(0.0f, 0.0f, 1.0f);
    Point3f bluePosition = new Point3f(1.8f, 1.8f, 1.8f);
    Point3f blueAtten = new Point3f(1.0f, 0.0f, 0.0f);
    Vector3f blueDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    SpotLight blueLight = new SpotLight(blueColour, bluePosition, blueAtten, blueDir, (float) (Math.PI / 2.0),
            0.0f);
    blueLight.setInfluencingBounds(bounds);
    Color3f greenColour = new Color3f(0.0f, 1.0f, 0.0f);
    Point3f greenPosition = new Point3f(0.0f, 0.0f, 3.0f);
    Point3f greenAtten = new Point3f(1.0f, 0.0f, 0.0f);
    Vector3f greenDir = new Vector3f(0.0f, 0.0f, -1.0f);
    SpotLight greenLight = new SpotLight(greenColour, greenPosition, greenAtten, greenDir,
            (float) (Math.PI / 2.0), 0.0f);
    greenLight.setInfluencingBounds(bounds);
    //Add the lights to the BranchGroup
    b.addChild(ambientLight);
    b.addChild(greenLight);
    b.addChild(blueLight);
}

From source file:SimpleSphere.java

protected void addLights(BranchGroup b) {
    // Create a bounds for the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    // Set up the global lights
    Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f);
    Point3f lightPosition2 = new Point3f(3.0f, 3.0f, 3.0f);
    Point3f lightAtten2 = new Point3f(0.0f, 0.0f, 1.0f);
    Vector3f lightDir2 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight ambientLight1 = new AmbientLight(ambientColour);
    ambientLight1.setInfluencingBounds(bounds);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);
    PointLight light2 = new PointLight(lightColour2, lightPosition2, lightAtten2);
    light2.setInfluencingBounds(bounds);
    b.addChild(ambientLight1);//from   w ww. j av a2  s. c  om
    b.addChild(light1);
    //b.addChild(light2);
}

From source file:SimpleMorph.java

/**
 * Add some lights to the scene graph//  w w  w .ja va  2 s  .c  om
 * 
 * @param b
 *            BranchGroup that the lights are added to
 */
protected void addLights(BranchGroup b) {
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    Color3f ambLightColour = new Color3f(0.5f, 0.5f, 0.5f);
    AmbientLight ambLight = new AmbientLight(ambLightColour);
    ambLight.setInfluencingBounds(bounds);
    Color3f dirLightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f dirLightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight dirLight = new DirectionalLight(dirLightColour, dirLightDir);
    dirLight.setInfluencingBounds(bounds);
    b.addChild(ambLight);
    b.addChild(dirLight);
}

From source file:AppearanceTest.java

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

    // 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
    TextureLoader bgTexture = new TextureLoader(bgImage, this);
    Background bg = new Background(bgTexture.getImage());
    bg.setApplicationBounds(bounds);//from w ww .  j  av  a 2  s  .c  om
    objRoot.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);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

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

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

    return objRoot;
}

From source file:BouncingBall.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);//from w w  w . j  a  va2s .  c  om

    // Create a simple shape leaf node, add it to the scene graph.
    Sphere sphere = new Sphere(0.25f);
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1 = new Transform3D();
    pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
    objTrans.setTransform(pos1);
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

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

    return objRoot;
}

From source file:SimpleKeyNav.java

/**
 * Add some lights to the scene graph/*from   w  w w  .j  a v  a  2s .  co m*/
 * 
 * @param b
 *            BranchGroup that the lights are added to
 */
protected void addLights(BranchGroup b) {
    // Create a bounds for the background and lights
    // Set up the global lights
    Color3f ambLightColour = new Color3f(0.5f, 0.5f, 0.5f);
    AmbientLight ambLight = new AmbientLight(ambLightColour);
    ambLight.setInfluencingBounds(bounds);
    Color3f dirLightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f dirLightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight dirLight = new DirectionalLight(dirLightColour, dirLightDir);
    dirLight.setInfluencingBounds(bounds);
    b.addChild(ambLight);
    b.addChild(dirLight);
}

From source file:SimpleIndexedQuadSmooth.java

/**
 * Add some lights so that we can illuminate the scene. This adds one
 * ambient light to bring up the overall lighting level and one directional
 * shape to show the shape of the objects in the scene.
 * /*from ww  w  .j  a  v a2 s  . c  o m*/
 * @param b
 *            BranchGroup that the lights are to be added to.
 */
protected void addLights(BranchGroup b) {
    //Create a bounding sphere to act as the active bounds
    //of the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    //Create the colours and directions
    Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
    //Create the lights
    AmbientLight ambientLight = new AmbientLight(ambientColour);
    ambientLight.setInfluencingBounds(bounds);
    DirectionalLight directionalLight = new DirectionalLight(lightColour, lightDir);
    directionalLight.setInfluencingBounds(bounds);
    //Add the lights to the branch
    b.addChild(ambientLight);
    b.addChild(directionalLight);
}

From source file:SimpleTextureGen.java

/**
 * Add some lights so that we can illuminate the scene. This adds one
 * ambient light to bring up the overall lighting level and one directional
 * shape to show the shape of the objects in the scene.
 * /*ww w  .j  a  va2  s .  c  o  m*/
 * @param b
 *            BranchGroup that the lights are to be added to.
 */
protected void addLights(BranchGroup b) {
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight ambientLight1 = new AmbientLight(ambientColour);
    ambientLight1.setInfluencingBounds(bounds);
    DirectionalLight directionalLight1 = new DirectionalLight(lightColour1, lightDir1);
    directionalLight1.setInfluencingBounds(bounds);
    b.addChild(ambientLight1);
    b.addChild(directionalLight1);
}