我有一个用 Java 编写的小程序,它应该显示 2 个球体。它工作正常,直到球体的平移超出 -1.0 到 1.0 的范围,在这种情况下,物体将会消失。我有一个 SimpleUniverse 设置,我在几个地方尝试了几个 setBounds,但我不明白它是如何消失的。真正奇怪的是,这个位置并不依赖于相机位置,因为我在靠近时的 ViewPlatform 变换上有一个 OrbitBehavior 不会显示该对象。
这是球体的设置: 公共(public)类 CelestialBody 扩展 TransformGroup {
CelestialBody(float posX, float posY, float posZ) {
// This is set for the dynamic behaviour.
setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D t3d = new Transform3D();
t3d.setTranslation(new Vector3f(posX, posY, posZ));
setTransform(t3d);
setBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), 10000.0f));
Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 100, createAppearance());
addChild(sphere);
}
private Appearance createAppearance() {
Appearance appear = new Appearance();
Material mat = new Material();
mat.setShininess(100.0f);
appear.setMaterial(mat);
return appear;
}
}
这是主程序:
public class CelestialApp extends Frame {
public static void main(String[] args) {
// TODO Auto-generated method stub
new CelestialApp();
}
private SimpleUniverse universe = null;
public CelestialApp() {
// ...
BranchGroup scene = constructContentBranch();
scene.compile();
universe = new SimpleUniverse(defaultCanvas);
setupView();
universe.addBranchGraph(scene);
}
private void setupView() {
ViewingPlatform vp = universe.getViewingPlatform();
OrbitBehavior orbit = new OrbitBehavior();
orbit.setSchedulingBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), 10000.0f));
vp.setNominalViewingTransform();
vp.setViewPlatformBehavior(orbit);
}
private BranchGroup constructContentBranch() {
BranchGroup scene = new BranchGroup();
CelestialBody body1 = new CelestialBody(-2.0f, 0.0f, 0.0f);
scene.addChild(body1);
CelestialBody body2 = new CelestialBody(2.0f, 0.0f, -1.1f);
scene.addChild(body2);
PhysicalBehavior physics1 = new PhysicalBehavior(body1);
scene.addChild(physics1);
PhysicalBehavior physics2 = new PhysicalBehavior(body2, new Vector3d(0.0f, 0.0f, 0.0f));
scene.addChild(physics2);
setupLights(scene);
return scene;
}
private void setupLights(BranchGroup scene) {
AmbientLight lightA = new AmbientLight();
lightA.setInfluencingBounds(new BoundingSphere());
lightA.setColor(new Color3f(0.3f, 0.3f, 0.3f));
scene.addChild(lightA);
DirectionalLight lightD1 = new DirectionalLight();
lightD1.setInfluencingBounds(new BoundingSphere());
Vector3f dir = new Vector3f(-0.3f, -1.0f, -0.5f);
dir.normalize();
lightD1.setDirection(dir);
lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f));
scene.addChild(lightD1);
Background bg = new Background(0.0f, 0.0f, 0.0f);
bg.setApplicationBounds(new BoundingSphere());
scene.addChild(bg);
}
}
最佳答案
呸,没关系。光源只有一个半径为 1.0f 的边界球体,并且对象被渲染为黑色。
关于java - Java3D 中仅在 -1.0 到 +1.0 范围内可见的对象的平移位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7796233/