Package javax.media.j3d

Examples of javax.media.j3d.BranchGroup





    //*** Generate (the root of) the scenegraph. ***
    BranchGroup theScene = new BranchGroup();


    //Add the cube and the sphere to the scene.
    theScene.addChild(tgBox);
    theScene.addChild(tgSphere);


    //Generate a white background.
    Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);




    theScene.compile();

    //Add everything to the universe.
    su.addBranchGraph(theScene);

  }
View Full Code Here


  //Directional light rotation around the scene.
  public void addLight(SimpleUniverse su)
  {

    BranchGroup bgLight = new BranchGroup();

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), Double.MAX_VALUE);


    //Directional light to be rotated.
    Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lightDir  = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight light = new DirectionalLight(lightColour, lightDir);
    light.setInfluencingBounds(bounds);

    //The transformation group for the directional light including the rotation.
    TransformGroup tfmLight = new TransformGroup();
    tfmLight.addChild(light);

    //The Alpha for the rotation.
    Alpha alphaLight = new Alpha(-1,4000);
    //The rotation.
    RotationInterpolator rot = new RotationInterpolator(alphaLight,tfmLight,
                                                        new Transform3D(),
                                                         0.0f,(float) Math.PI*2);
    rot.setSchedulingBounds(bounds);

    tfmLight.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tfmLight.addChild(rot);

    bgLight.addChild(tfmLight);




    //Ambient light.
    Color3f ambientLightColour = new Color3f(0.5f, 0.5f, 0.5f);
    AmbientLight ambLight = new AmbientLight(ambientLightColour);
    ambLight.setInfluencingBounds(bounds);
    bgLight.addChild(ambLight);


    su.addBranchGraph(bgLight);
  }
View Full Code Here

  //In this method, the objects for the scene are generated and added to
  //the SimpleUniverse.
  public void createSceneGraph(SimpleUniverse su)
  {

    BranchGroup theScene = new BranchGroup();

    //Generate a sphere.
    Color3f ambientColourBSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f emissiveColourBSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourBSphere = new Color3f(0.9f,0.9f,0.9f);
    Color3f specularColourBSphere = new Color3f(0.9f,0.9f,0.9f);
    float shininessBSphere = 128.0f;

    Appearance bSphereApp = new Appearance();

    bSphereApp.setMaterial(new Material(ambientColourBSphere,
                                        emissiveColourBSphere,
                                        diffuseColourBSphere,
                                        specularColourBSphere,
                                        shininessBSphere));

    Sphere bSphere = new Sphere(0.1f,bSphereApp);


    //Assign the sphere to a SharedGroup to use it multiple
    //times in the scene.
    SharedGroup sgSphere = new SharedGroup();
    sgSphere.addChild(bSphere);



    //Generate a two-dimensional array of rows*columns spheres.
    //rowStep and columnStep define the distance between the spheres.
    int rows = 40;
    float rowStep = 0.25f;
    int columns = 20;
    float columnStep = 0.3f;

    TransformGroup[][] tgArray = new TransformGroup[rows][columns];
    Transform3D[][] tfArray = new Transform3D[rows][columns];

    for (int i=0; i<rows; i++)
    {
      for (int j=0; j<columns; j++)
      {
        tfArray[i][j] = new Transform3D();
        tfArray[i][j].setTranslation(new Vector3f(i*columnStep-2.0f,j*0.1f-0.5f,-j*rowStep));
        tgArray[i][j] = new TransformGroup(tfArray[i][j]);
        tgArray[i][j].addChild(new Link(sgSphere));
        theScene.addChild(tgArray[i][j]);
      }
    }




    //Generate a background in the colour of the fog.
    Color3f fogColour = new Color3f(0.5f,0.5f,0.5f);
    Background bg = new Background(fogColour);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);


    //Generate exponential fog.
    ExponentialFog fog = new ExponentialFog(fogColour,6.0f);
    fog.setInfluencingBounds(bounds);

    theScene.addChild(fog);

    theScene.compile();

    //Add the scene to the universe.
    su.addBranchGraph(theScene);

  }
View Full Code Here

  //Some light is added to the scene here.
  public void addLight(SimpleUniverse su)
  {

    BranchGroup bgLight = new BranchGroup();

    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,0.0f,-0.5f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);

    bgLight.addChild(light1);


    su.addBranchGraph(bgLight);

  }
View Full Code Here


    //The objects to be shown on the canvas are created in this method.
    //BranchGroup theScene = new BranchGroup();

    BranchGroup theScene = createSceneGraph();






    theScene.compile();




    //Put everything together in a simple universe:
View Full Code Here

    tfBSphere.setTranslation(new Vector3f(2.0f,0.0f,-10.5f));
    TransformGroup tgBSphere = new TransformGroup(tfBSphere);
    tgBSphere.addChild(tgmBSphere);

    //Create the root of the scene graph and add the box and the sphere group.
    BranchGroup theScene = new BranchGroup();;
    theScene.addChild(tgFBox);
    theScene.addChild(tgBSphere);


    //Define the data for the picking interaction and add the picking to the
    //scene graph.
    Alpha[] alphas = new Alpha[3];
View Full Code Here

  //To make the scene look a little bit more realistic we add some light
  public void addLight(SimpleUniverse su)
  {

    BranchGroup bgLight = new BranchGroup();

    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,0.0f,-0.5f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);

    bgLight.addChild(light1);


    Vector3f lightDir2  = new Vector3f(0.0f,0.0f,-1.0f);
    DirectionalLight light2 = new DirectionalLight(lightColour1, lightDir2);
    light2.setInfluencingBounds(bounds);

    bgLight.addChild(light2);



    su.addBranchGraph(bgLight);
View Full Code Here

    tgTree.addChild(tgTrunk);
    tgTree.addChild(tgLeaves);


//*** The root of the graph containing the scene. ***
    BranchGroup theScene = new BranchGroup();


    //Add the helicopter and the tree to the scene.
    theScene.addChild(tgHeliPlat);
    theScene.addChild(tgTree);


    //The following four lines generate a white background.
    Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);


    theScene.compile();

    //Add the scene to the universe.
    su.addBranchGraph(theScene);

  }
View Full Code Here

  //Some light is added to the scene here.
  public void addLight(SimpleUniverse su)
  {

    BranchGroup bgLight = new BranchGroup();

    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,0.0f,-0.5f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);

    bgLight.addChild(light1);
    su.addBranchGraph(bgLight);
  }
View Full Code Here

    tfBSphere.setTranslation(new Vector3f(2.0f,0.0f,-10.5f));
    TransformGroup tgBSphere = new TransformGroup(tfBSphere);
    tgBSphere.addChild(bSphere);

    //Generate the scenegraph.
    BranchGroup theScene = new BranchGroup();
    theScene.addChild(tgFBox);
    theScene.addChild(tgBSphere);

    //Definition of the parameters for picking. Generate the PickingBehaviour
    //and add it to the scene.
    BoundingSphere bs = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    PickingTest sp = new PickingTest(myCanvas3D,theScene,bs);
    theScene.addChild(sp);

    theScene.compile();

    //Add everything to the universe.
    su.addBranchGraph(theScene);

  }
View Full Code Here

TOP

Related Classes of javax.media.j3d.BranchGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.