Example usage for javax.media.j3d DirectionalLight DirectionalLight

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

Introduction

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

Prototype

public DirectionalLight(Color3f color, Vector3f direction) 

Source Link

Document

Constructs and initializes a directional light.

Usage

From source file:Ball.java

public Ball() {
    // Create the universe
    SimpleUniverse universe = new SimpleUniverse();

    // Create a structure to contain objects
    BranchGroup group = new BranchGroup();

    // Create a ball and add it to the group of objects
    Sphere sphere = new Sphere(0.5f);
    group.addChild(sphere);/* w  w w . ja  v a  2s . co  m*/

    // Create a red light that shines for 100m from the origin
    Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);
    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);

    // look towards the ball
    universe.getViewingPlatform().setNominalViewingTransform();

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

From source file:ObjectLoader.java

/**
 * Erstellt den Szenegraphen//from ww  w  .  j  a  v  a 2 s .c  o  m
 * 
 * @return BranchGroup
 */
public BranchGroup macheSzene() {
    BranchGroup objWurzel = new BranchGroup();
    // Transformation, 2 Rotationen:
    Transform3D drehung = new Transform3D();
    Transform3D drehung2 = new Transform3D();
    drehung.rotX(Math.PI / 4.0d);
    drehung2.rotY(Math.PI / 5.0d);
    drehung.mul(drehung2);
    TransformGroup objDreh = new TransformGroup(drehung);
    //Loader
    ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
    Scene scene = null;
    try {
        scene = file.load(ClassLoader.getSystemResource("teapot.obj"));

    } catch (Exception e) {
    }
    objDreh.addChild(scene.getSceneGroup());

    DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 0.5f, 0.3f),
            new Vector3f(-1.0f, -1.0f, -1.0f));
    d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d));
    //      d_Licht.setColor(new Color3f(1.0f,0.5f,0.3f));
    objDreh.addChild(d_Licht);

    objWurzel.addChild(objDreh);
    return objWurzel;
}

From source file:Phong.java

/**
 * Erstellt den Szenegraphen/*from ww  w.  j  av a 2s .  c  o m*/
 * 
 * @return BranchGroup
 */
public BranchGroup macheSzene() {
    BranchGroup objWurzel = new BranchGroup();
    // Transformation, 2 Rotationen:
    Transform3D drehung = new Transform3D();
    Transform3D drehung2 = new Transform3D();
    drehung.rotX(Math.PI / 4.0d);
    drehung2.rotY(Math.PI / 5.0d);
    drehung.mul(drehung2);
    TransformGroup objDreh = new TransformGroup(drehung);
    //Loader
    ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
    Scene scene = null;
    try {
        scene = file.load(ClassLoader.getSystemResource("teapot.obj"));

    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }
    objDreh.addChild(scene.getSceneGroup());

    DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f),
            new Vector3f(-1.0f, -1.0f, -1.0f));
    d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d));
    objDreh.addChild(d_Licht);
    objWurzel.addChild(objDreh);
    return objWurzel;
}

From source file:SimpleMouse.java

/**
 * Add some lights to the scene graph/* ww  w .ja v a  2 s. co  m*/
 * 
 * @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: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 va2 s  .  co m*/

    // 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:SimpleDirLight.java

/**
 * This creates some lights and adds them to the BranchGroup.
 * //from   w  w  w .  ja va 2 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: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 w  w . j  av a 2  s.  c om
    b.addChild(light1);
    //b.addChild(light2);
}

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. ja v a 2  s  . c  o m*/
    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:BasicConstruct.java

/**
 * Adds a light source to the universe// ww  w . j  ava 2s  .  com
 * 
 * @param direction
 *            The inverse direction of the light
 * @param color
 *            The color of the light
 */
public void addDirectionalLight(Vector3f direction, Color3f color) {
    // Creates a bounding sphere for the lights
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(1000d);

    // Then create a directional light with the given
    // direction and color
    DirectionalLight lightD = new DirectionalLight(color, direction);
    lightD.setInfluencingBounds(bounds);

    // Then add it to the root BranchGroup
    rootBranchGroup.addChild(lightD);
}

From source file:SimpleMorph.java

/**
 * Add some lights to the scene graph//from  w ww  .ja  v a  2  s.c o m
 * 
 * @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);
}