java3d效果_[转载]JAVA3D 灯光效果实例

package unit5;

import java.applet.Applet;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.applet.MainFrame;

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

import com.sun.j3d.utils.universe.*;

import javax.media.j3d.*;

import javax.vecmath.*;

public class SimpleLight extends Applet{

Appearance createAppearance() {

Appearance appear = new

Appearance();

Material material = new

Material();

appear.setMaterial(material);

return

appear;

}

public BranchGroup createSceneGraph() {

BranchGroup sceneRoot = new

BranchGroup();

BoundingSphere bounds =new BoundingSphere(new Point3d(0.0,0.0,0.0),

100.0);

// Set up the background

Color

Color3f bgColor = new Color3f(1.0f, 1.0f,

1.0f);

Background bg = new Background(bgColor);

bg.setApplicationBounds(bounds);

sceneRoot.addChild(bg);

//环境光的使用

//聚光灯的使用

SpotLight lightS=new SpotLight

();

// lightS.setEnable

(true);

lightS.setPosition (new

Point3f(0.5f,0.0f,10.0f));

lightS.setColor (new

Color3f(0.0f,1.0f,1.0f));

lightS.setAttenuation (new

Point3f(1.0f,0.0f,0.0f));

lightS.setDirection (new

Vector3f(0.0f,0.0f,-1.0f));

lightS.setSpreadAngle (15.0f *

(float)Math.PI / 180.0f);

lightS.setConcentration

(100);

lightS.setInfluencingBounds

(bounds);

sceneRoot.addChild

(lightS);

Sphere ball1=new Sphere(0.5f,Sphere.GENERATE_NORMALS,createAppearance()); Sphere ball2=new Sphere(0.5f,Sphere.GENERATE_NORMALS,createAppearance()); Transform3D tr = new

Transform3D();

tr.setScale(0.8);

tr.setTranslation(new

Vector3f(0.5f, 0.0f, 0.0f));

TransformGroup objTransr = new

TransformGroup(tr);

objTransr.addChild(ball1);

Transform3D tl = new

Transform3D();

tl.setScale(0.8);

tl.setTranslation(new

Vector3f(-0.5f, 0.0f, 0.0f));

TransformGroup objTransl = new

TransformGroup(tl);

objTransl.addChild(ball2);

sceneRoot.addChild(objTransr);

sceneRoot.addChild

(objTransl);

System.out.println("hello");

return

sceneRoot;

}

public SimpleLight() {

setLayout(new

BorderLayout());

GraphicsConfiguration

config=SimpleUniverse.getPreferredConfiguration();

Canvas3D c = new

Canvas3D(config);

add("Center", c);

BranchGroup scene =

createSceneGraph();

SimpleUniverse u = new

SimpleUniverse(c);

u.getViewingPlatform().setNominalViewingTransform();

u.addBranchGraph(scene);

}

public static void main(String[] args) {

new MainFrame(new

SimpleLight(), 512, 256);

}

}

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值