コード例 #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
  //
  //  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;
  }