送交者: 吴聊 于 2005-4-15, 18:03:13:
回答: buddy, 不是我搞笑. Graphics and images are different 由 boxer 于 2005-4-15, 17:49:06:
让你跟我倔,到底谁笑了
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Ball {
public Ball() {
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
Sphere sphere = new Sphere(0.3f);
for (float x = -1.0f; x <= 1.0f; x += 0.5f){
for (float y = -1.0f; y <= 1.0f; y += 0.5f){
for (float z = -1.0f; z <= 1.0f; z += 0.8f){
Cylinder sphere1 = new Cylinder(0.1f, 0.3f);
TransformGroup tg = new TransformGroup();
Transform3D transform = new Transform3D();
Vector3f vector = new Vector3f( x, y, z);
transform.setTranslation(vector);
tg.setTransform(transform);
tg.addChild(sphere1);
group.addChild(tg);
}}
}
Color3f light1Color = new Color3f(1.3f, 0.8f, 0.1f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Vector3f light1Direction = new Vector3f(4.0f, 1.0f, -12.0f);
DirectionalLight light1
= new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}
public static void main(String[] args) { new Ball(); }
}