⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myball.java

📁 这个就是目前我收集,以及自己写的一些java3d的原码,大部分都可以运行,适合和我一样,刚刚开始对java3D心动的菜鸟
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -