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

Source Link

Document

Constructs a DirectionalLight node with default parameters.

Usage

From source file:Licht.java

/**
 * Erstellt den Szenegraphen//from  www .ja  va2 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);

    Sphere kugel = new Sphere(0.5f, Sphere.GENERATE_NORMALS, 50, makeAppearance());
    objWurzel.addChild(kugel);
    objWurzel.addChild(objDreh);

    //directes Licht
    DirectionalLight d_Licht = new DirectionalLight();
    d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), Double.MAX_VALUE));
    d_Licht.setColor(new Color3f(1.0f, 0.0f, 0.0f));
    Vector3f dir = new Vector3f(1.0f, 2.0f, -1.0f);
    dir.normalize();
    d_Licht.setDirection(dir);
    objWurzel.addChild(d_Licht);

    // ambient Licht
    AmbientLight a_licht = new AmbientLight();
    a_licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), Double.MAX_VALUE));
    a_licht.setColor(new Color3f(1.0f, 0.0f, 0.0f));
    objWurzel.addChild(a_licht);

    return objWurzel;
}

From source file:LitSphereApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();

    scene.addChild(new Sphere(0.9f, Sphere.GENERATE_NORMALS, createAppearance()));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);/*  w w  w . ja  v  a 2  s  . c  o m*/

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

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    Vector3f direction2 = new Vector3f(1.0f, -1.0f, -0.5f);
    direction2.normalize();
    lightD2.setDirection(direction2);
    lightD2.setColor(new Color3f(1.0f, 0.0f, 0.0f));
    scene.addChild(lightD2);

    Background bg = new Background();
    bg.setColor(1.0f, 1.0f, 1.0f);
    bg.setApplicationBounds(new BoundingSphere());
    scene.addChild(bg);

    return scene;
}

From source file:LitPlaneApp.java

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

    BranchGroup scene = new BranchGroup();

    Shape3D plane = new LitPlane();
    scene.addChild(new LitPlane());
    scene.addChild(new Sphere(0.5f, Sphere.GENERATE_NORMALS, plane.getAppearance()));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);/*from w w w  .j  a v a  2 s  .  c o m*/

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

    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();

    u.addBranchGraph(scene);
}

From source file:Text3DApp.java

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

    Transform3D t3D = new Transform3D();
    t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f));
    TransformGroup objMove = new TransformGroup(t3D);
    objRoot.addChild(objMove);/*from   w ww  . jav  a  2  s .  co  m*/

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objMove.addChild(objSpin);

    Appearance textAppear = new Appearance();
    ColoringAttributes textColor = new ColoringAttributes();
    textColor.setColor(1.0f, 0.0f, 0.0f);
    textAppear.setColoringAttributes(textColor);
    textAppear.setMaterial(new Material());

    // Create a simple shape leaf node, add it to the scene graph.
    Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion());
    Text3D textGeom = new Text3D(font3D, new String("3DText"));
    textGeom.setAlignment(Text3D.ALIGN_CENTER);
    Shape3D textShape = new Shape3D();
    textShape.setGeometry(textGeom);
    textShape.setAppearance(textAppear);
    objSpin.addChild(textShape);

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 100
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    DirectionalLight lightD = new DirectionalLight();
    lightD.setInfluencingBounds(bounds);
    lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f));
    lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f));
    objMove.addChild(lightD);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(bounds);
    objMove.addChild(lightA);

    return objRoot;
}

From source file:ShadowApp.java

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

    BranchGroup scene = new BranchGroup();

    Shape3D plane = new LitQuad(new Point3f(-0.3f, 0.6f, 0.2f), new Point3f(-0.3f, -0.3f, 0.2f),
            new Point3f(0.6f, -0.3f, -0.3f), new Point3f(0.6f, 0.6f, -0.3f));
    scene.addChild(plane);//w ww.j a v a 2s  . co  m

    Shape3D floor = new LitQuad(new Point3f(-1.0f, -0.5f, -1.0f), new Point3f(-1.0f, -0.5f, 1.0f),
            new Point3f(1.0f, -0.5f, 1.0f), new Point3f(1.0f, -0.5f, -1.0f));
    scene.addChild(floor);

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

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

    Shape3D shadow = new SimpleShadow((GeometryArray) plane.getGeometry(), direction,
            new Color3f(0.2f, 0.2f, 0.2f), -0.5f);
    scene.addChild(shadow);

    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();

    u.addBranchGraph(scene);
}

From source file:MaterialApp.java

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

    Color3f white = new Color3f(1.0f, 1.0f, 1.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);/* w  w  w  .jav  a2s . c o m*/
    trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 0.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, 1.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, 2.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, 5.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, 10.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, 20.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, 50.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, 100.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(-1.0f, -1.0f, -1.0f);
    direction.normalize();
    lightD1.setDirection(direction);
    lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    scene.addChild(lightD1);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere());
    background.setColor(1.0f, 1.0f, 1.0f);
    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();

    // setLocalEyeViewing
    u.getViewer().getView().setLocalEyeLightingEnable(true);

    u.addBranchGraph(scene);
}

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);//from   w w  w  .  ja va2s.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:ExDirectionalLight.java

public Group buildScene() {
    // Get the current color and direction
    Color3f color = (Color3f) colors[currentColor].value;
    Vector3f dir = (Vector3f) directions[currentDirection].value;

    // Turn off the example headlight
    setHeadlightEnable(false);//from   w  w  w .  jav a 2  s . com

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

    // BEGIN EXAMPLE TOPIC
    // Create influencing bounds
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Set the light color and its influencing bounds
    light = new DirectionalLight();
    light.setEnable(lightOnOff);
    light.setColor(color);
    light.setDirection(dir);
    light.setCapability(DirectionalLight.ALLOW_STATE_WRITE);
    light.setCapability(DirectionalLight.ALLOW_COLOR_WRITE);
    light.setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE);
    light.setInfluencingBounds(worldBounds);
    scene.addChild(light);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(new SphereGroup());

    // Add anotation arrows pointing in +-X, +-Y, +-Z to
    // illustrate aim direction
    scene.addChild(buildArrows());

    return scene;
}

From source file:MixedTest.java

public void renderField(int fieldDesc) {
    super.renderField(fieldDesc);

    GraphicsContext3D g = getGraphicsContext3D();

    // first time initialization
    if (m_nRender == 0) {
        // set the start time
        m_StartTime = System.currentTimeMillis();

        // add a light to the graphics context
        DirectionalLight light = new DirectionalLight();
        light.setEnable(true);/* ww  w . j av a2 s  .c o m*/
        g.addLight((Light) light);

        // create the material for the points
        Appearance a = new Appearance();
        Material mat = new Material();
        mat.setLightingEnable(true);
        mat.setAmbientColor(0.5f, 1.0f, 1.0f);
        a.setMaterial(mat);
        a.setColoringAttributes(new ColoringAttributes(1.0f, 0.5f, 0.5f, ColoringAttributes.NICEST));

        // enlarge the points
        a.setPointAttributes(new PointAttributes(4, true));

        // make the appearance current in the graphics context
        g.setAppearance(a);
    }

    // set the current transformation for the graphics context
    g.setModelTransform(m_t3d);

    // finally render the PointArray
    g.draw(m_PointArray);

    // calculate and display the Frames Per Second for the
    // Immediate Mode rendering of the PointArray
    m_nRender++;

    if ((m_nRender % m_kReportInterval) == 0) {
        float fps = (float) 1000.0f / ((System.currentTimeMillis() - m_StartTime) / (float) m_kReportInterval);
        System.out.println("FPS:\t" + fps);

        m_StartTime = System.currentTimeMillis();
    }
}

From source file:ExLightBounds.java

public Group buildScene() {
    // Get the current bounding leaf position
    Point3f pos = (Point3f) positions[currentPosition].value;

    // Turn off the example headlight
    setHeadlightEnable(false);/*from   w  w  w.  j  av  a2  s  .c o m*/

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

    // BEGIN EXAMPLE TOPIC
    // Create a bounding leaf we'll use or not use depending
    // upon menu selections. Put it within a transform group
    // so that we can move the leaf about.
    leafTransformGroup = new TransformGroup();
    leafTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D tr = new Transform3D();
    tr.setTranslation(new Vector3f(pos));
    leafTransformGroup.setTransform(tr);

    leafBounds = new BoundingLeaf(worldBounds);
    leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE);
    leafTransformGroup.addChild(leafBounds);
    scene.addChild(leafTransformGroup);

    // Add a directional light whose bounds we'll modify
    // Set its color and aim direction
    light = new DirectionalLight();
    light.setEnable(true);
    light.setColor(White);
    light.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE);

    // Set the bounds to be either from the leaf or from
    // explicit bounds, depending upon the menu initial state
    if (boundingLeafOnOff)
        // Use bounding leaf
        light.setInfluencingBoundingLeaf(leafBounds);
    else
        // Use bounds on the light
        light.setInfluencingBounds(worldBounds);

    // Set the scope list to include nothing initially.
    // This defaults to "universal scope" which covers
    // everything.

    scene.addChild(light);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional light is being bounded... otherwise it looks
    // like we're just removing shapes from the scene
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);
    ambient.setColor(White);
    ambient.setInfluencingBounds(worldBounds);
    scene.addChild(ambient);
    // END EXAMPLE TOPIC

    // Build foreground geometry
    scene.addChild(new SphereGroup());

    return scene;
}