コード例 #1
0
ファイル: ExLinearFog.java プロジェクト: citrit/ECSE4750
  //
  //  Build scene
  //
  public Group buildScene() {
    // Get the current color
    Color3f color = (Color3f) colors[currentColor].value;
    float front = ((Float) fronts[currentFront].value).floatValue();
    float back = ((Float) backs[currentBack].value).floatValue();

    // Turn off the example headlight
    setHeadlightEnable(false);

    // Default to walk navigation
    setNavigationType(Walk);

    // Create 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 fog color, front & back distances, and
    // its influencing bounds
    fog = new LinearFog();
    fog.setColor(color);
    fog.setFrontDistance(front);
    fog.setBackDistance(back);
    fog.setCapability(Fog.ALLOW_COLOR_WRITE);
    fog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE);
    fog.setInfluencingBounds(worldBounds);
    scene.addChild(fog);
    // END EXAMPLE TOPIC

    // Set the background color and its application bounds
    //   Usually, the background color should match the fog color
    //   or the results look odd.
    background = new Background();
    background.setColor(color);
    background.setApplicationBounds(worldBounds);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    scene.addChild(background);

    // Build foreground geometry
    scene.addChild(new ColumnScene(this));

    return scene;
  }
コード例 #2
0
  /** Setup the basic scene which consists of a quad and a viewpoint */
  private void setupSceneGraph() {
    // View group

    Viewpoint vp = new Viewpoint();

    Vector3f trans = new Vector3f(0, 0, 1);

    Matrix4f mat = new Matrix4f();
    mat.setIdentity();
    mat.setTranslation(trans);

    TransformGroup tx = new TransformGroup();
    tx.addChild(vp);
    tx.setTransform(mat);

    Group scene_root = new Group();
    scene_root.addChild(tx);

    // Flat panel that has the viewable object as the demo
    float[] coord = {0, 0, -1, 0.25f, 0, -1, 0, 0.25f, -1};
    float[] normal = {0, 0, 1, 0, 0, 1, 0, 0, 1};

    TriangleArray geom = new TriangleArray();
    geom.setValidVertexCount(3);
    geom.setVertices(TriangleArray.COORDINATE_3, coord);
    geom.setNormals(normal);

    Material material = new Material();
    material.setDiffuseColor(new float[] {0, 0, 1});
    material.setEmissiveColor(new float[] {0, 0, 1});
    material.setSpecularColor(new float[] {1, 1, 1});
    material.setTransparency(0.5f);

    Appearance app = new Appearance();
    app.setMaterial(material);

    Shape3D shape = new Shape3D();
    shape.setGeometry(geom);
    shape.setAppearance(app);

    TransformGroup tg = new TransformGroup();
    Matrix4f transform = new Matrix4f();
    transform.setIdentity();
    transform.setTranslation(new Vector3f(0.15f, 0, -1));
    tg.setTransform(transform);

    Shape3D backShape = new Shape3D();
    Material material2 = new Material();
    material2.setDiffuseColor(new float[] {1, 0, 0});
    material2.setEmissiveColor(new float[] {1, 0, 0});
    material2.setSpecularColor(new float[] {1, 1, 1});

    Appearance app2 = new Appearance();
    app2.setMaterial(material2);
    backShape.setGeometry(geom);
    backShape.setAppearance(app2);
    tg.addChild(backShape);

    scene_root.addChild(tg);
    scene_root.addChild(shape);

    SimpleScene scene = new SimpleScene();
    scene.setRenderedGeometry(scene_root);
    scene.setActiveView(vp);

    // Then the basic layer and viewport at the top:
    SimpleViewport view = new SimpleViewport();
    view.setDimensions(0, 0, 500, 500);
    view.setScene(scene);

    SimpleLayer layer = new SimpleLayer();
    layer.setViewport(view);

    Layer[] layers = {layer};
    displayManager.setLayers(layers, 1);
  }
コード例 #3
0
  //
  //  Build scene
  //
  public Group buildScene() {
    // Turn off the example headlight
    setHeadlightEnable(false);

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

    // Build foreground geometry into two groups.  We'll
    // create three directional lights below, one each with
    // scope to cover the first geometry group only, the
    // second geometry group only, or both geometry groups.
    content1 =
        new SphereGroup(
            0.25f, // radius of spheres
            1.5f, // x spacing
            0.75f, // y spacing
            3, // number of spheres in X
            5, // number of spheres in Y
            null); // appearance
    scene.addChild(content1);

    content2 =
        new SphereGroup(
            0.25f, // radius of spheres
            1.5f, // x spacing
            0.75f, // y spacing
            2, // number of spheres in X
            5, // number of spheres in Y
            null); // appearance
    scene.addChild(content2);

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

    // Add three directional lights whose scopes are set
    // to cover one, the other, or both of the shape groups
    // above.  Also set the lights' color and aim direction.

    // Light #1 with content1 scope
    light1 = new DirectionalLight();
    light1.setEnable(light1OnOff);
    light1.setColor(Red);
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    light1.addScope(content1);
    light1.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(light1);

    // Light #2 with content2 scope
    light2 = new DirectionalLight();
    light2.setEnable(light2OnOff);
    light2.setColor(Blue);
    light2.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light2.setInfluencingBounds(worldBounds);
    light2.addScope(content2);
    light2.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(light2);

    // Light #3 with universal scope (the default)
    light3 = new DirectionalLight();
    light3.setEnable(light3OnOff);
    light3.setColor(White);
    light3.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light3.setInfluencingBounds(worldBounds);
    light3.setCapability(Light.ALLOW_STATE_WRITE);
    scene.addChild(light3);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional lights are being scoped... 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

    return scene;
  }