没有将类添加到Branchgroup

时间:2018-02-12 21:23:06

标签: java

我创建了课程DirectionalLight.javaCore.java。第一个我创建了awt DirectionalLight和DirectionalLight.java类'代码是:

private Light DirectionalLight(){

    DirectionalLight directionalLight = new DirectionalLight(true, new Color3f(1.0f,
            1.0f, 1.0f), new Vector3f(-0.3f, 0.2f, -1.0f));

    directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(), 10000.0));

    return directionalLight;
}

第二个我创建了分支组类和Core.java代码:

BranchGroup branchGroup = new BranchGroup();

    viewTransform = universe.getViewingPlatform().getViewPlatformTransform();

    PlatformGeometry platformGeom = new PlatformGeometry();
    universe.getViewingPlatform().setPlatformGeometry(platformGeom);

    branchGroup.addChild(DirectionalLight());//this line generate problem

当我将DirectionalLight类添加到branchgroup编译器输出时:test无法解析为变量。如何改善这个问题?如何将另一个类添加到branchgroup?

2 个答案:

答案 0 :(得分:0)

受到该教程的启发,我创建了一个类似于你的版本:http://www.java3d.org/lighting.html

import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Light;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Java3D {

public static void main(String[] args) {
    System.setProperty("sun.awt.noerasebackground", "true");
    new Java3D();
}

public Java3D() {
    final SimpleUniverse universe = new SimpleUniverse();
    final BranchGroup group = new BranchGroup();
    final Sphere sphere = new Sphere(0.5f);
    group.addChild(sphere);
    // here you add the created light
    group.addChild(createLight());

    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(group);

}

private Light createLight() {
    final DirectionalLight directionalLight = new DirectionalLight(true, new Color3f(1.0f,
            1.0f, 1.0f), new Vector3f(-0.3f, 0.2f, -1.0f));
    directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(), 100.0));
    return directionalLight;
}
}

答案 1 :(得分:0)

好的,但那只是简单的java。这里是提取专用类的版本。

     d3.json('https://statsapi.web.nhl.com/api/v1/teams', function(data) {
      for (i=0; i < 31; i++) {
          teamID.push(data.teams[i].id);
      }
  });

  console.log(teamID);

  // request roster json data from API and loop through roster to get all player IDS
  // and append them to the playerList array

  d3.json('https://statsapi.web.nhl.com/api/v1/teams/1/?expand=team.roster', function(data) {
      for (i=0; i < data.teams[0].roster.roster.length; i++) {
        playerList.push(data.teams[0].roster.roster[i].person.id);
      }
  });

  console.log(playerList);

  // request player stat json data from API and loop through all players to get all stat
  // and append them to an array

  var playerStats = [];

    for (i = 0; i < playerList.length; i++) {
        d3.json('https://statsapi.web.nhl.com/api/v1/people/' + playerList[i] + '/stats/?stats=statsSingleSeason&season=20172018', function(data) {
          console.log(data.stats[0].splits[0].stat.goals);
        });

  //      console.log(playerStats);
      };