myball.java

来自「这个就是目前我收集,以及自己写的一些java3d的原码,大部分都可以运行,适合和」· Java 代码 · 共 76 行

JAVA
76
字号
package com.java3d.examples;

import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;


public class myBall {

public myBall() {

// 创建宇宙

SimpleUniverse universe = new SimpleUniverse();


// 创建容纳物体的结构

BranchGroup group = new BranchGroup();


// 创建一个球体并加入到物体组

Sphere sphere = new Sphere(0.5f,1,100);

group.addChild(sphere);


// 创建一个从原点延伸100米的红色光源

Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);

BoundingSphere bounds = 

new BoundingSphere(new Point3d(0.0,0.0,0.0), 100);


BoundingSphere bounds2 = 

	new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000);

Vector3f light1Direction = new Vector3f(5.0f, 5.0f, -12.0f);

//定义一组平行光,颜色和方向
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);

light1.setInfluencingBounds(bounds);


//加入一环境光
AmbientLight ambientLight = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f));
ambientLight.setInfluencingBounds(bounds2);


//group.addChild(ambientLight);

group.addChild(light1);


// 注视球体

universe.getViewingPlatform().setNominalViewingTransform();


// 添加物体组到宇宙中

universe.addBranchGraph(group);

}

public static void main(String[] args) { new myBall(); }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?