论文无忧网提供:计算机毕业论文范文|计算机毕业设计|计算机毕业论文
栏目导航 ASP JSP .NET VB6.0 JAVA VC VF DELPHI PB 计算机网络 计算机科学与技术 PHP 安卓APP 其他 C# 代写论文
当前位置: > 计算机 > JAVA >

A4001093D的网络三维技术的设计与实现

运行结果如下:

paper51.com

图10无灯光效果的场景 copyright paper51.com

http://www.paper51.com

图11加入AmbientLight效果的场景 http://www.paper51.com

2.创建PointLight 内容来自www.paper51.com

PointLight orangePoint = new PointLight (); copyright paper51.com

    orangePoint.setEnable(orangePointOnOff);

http://www.paper51.com

    orangePoint.setColor (newColor3f (1.0f, 0.5f, 0.0f)); / / 同样为光的颜色,橙色

http://www.paper51.com

    orangePoint.setPosition (newPoint3f (0.0f, 0.5f, 0.0f)); / / 设置光的位置

copyright paper51.com

    orangePoint.setCapability(AmbientLight.ALLOW_STATE_WRITE);

内容来自www.paper51.com

    orangePoint.setInfluencingBounds(worldBounds);

内容来自www.paper51.com

Scene1.addChild (orangePoint);

内容来自www.paper51.com

运行结果如下: copyright paper51.com

copyright paper51.com

图12加入PointLight效果的场景

内容来自www.paper51.com

3.创建一个DirectionalLight: 内容来自www.paper51.com

DirectionalLight redDirectional = newDirectionalLight ( );

paper51.com

    redDirectional.setEnable(redDirectionalOnOff);

copyright paper51.com

    redDirectional.setColor (newColor3f (1.0f, 0.0f, 0.0f));

内容来自论文无忧网 www.paper51.com

    redDirectional.setDirection(new Vector3f (1.0f, -0.5f, -0.5f)); paper51.com

    redDirectional.setCapability(AmbientLight.ALLOW_STATE_WRITE);

内容来自www.paper51.com

   redDirectional.setInfluencingBounds (worldBounds); copyright paper51.com

Scene1.addChild (redDirectional);

内容来自www.paper51.com

执行结果如下:

内容来自www.paper51.com

http://www.paper51.com

图13加入DirectionalLight效果的场景

内容来自www.paper51.com

4.4.2 创建背景图片

http://www.paper51.com

这里的背景图片实际上就是一张640×480的jpg图片,所以就是么把2D图片读到场景中。为了同时实现交互式更换背景图片,这里也加入了菜单。 内容来自论文无忧网 www.paper51.com

读入2D图片要用到ImageComponent2D和TextureLoader两个类。其中ImageComponent2D用于定义一个二维组件,TextureLoader则是读取ImageComponent2D定义的二维组件。

内容来自论文无忧网 www.paper51.com

// 预载背景图片 内容来自论文无忧网 www.paper51.com

// 使用TextureLoader读图片 内容来自www.paper51.com

// 将要读取的图片装入ImageComponent2D[ ]中 paper51.com

if ( debug ) System.err.println( "  background images..." ); copyright paper51.com

         TextureLoader texLoader = null;

内容来自论文无忧网 www.paper51.com

         String value = null;

paper51.com

         imageComponents = new ImageComponent2D[images.length];

内容来自www.paper51.com

         for ( int i = 0; i < images.length; i++ ) paper51.com

         { 内容来自www.paper51.com

                 value = (String)images[i].value; 内容来自论文无忧网 www.paper51.com

                 if ( value == null ) copyright paper51.com

                 { http://www.paper51.com

                         imageComponents[i] = null; http://www.paper51.com

                         continue;

copyright paper51.com

                  } 内容来自www.paper51.com

                 texLoader = new TextureLoader( value, this ); 内容来自论文无忧网 www.paper51.com

                 imageComponents[i] = texLoader.getImage( ); 内容来自论文无忧网 www.paper51.com

         } 内容来自论文无忧网 www.paper51.com

copyright paper51.com

图14纹理背景--白云

内容来自论文无忧网 www.paper51.com

4.4.3 指数雾 paper51.com

用ExponentialFog可以产生雾的效果

内容来自论文无忧网 www.paper51.com

雾的密度通过指数控制厚度:

内容来自www.paper51.com

effect = e(-density * distance) http://www.paper51.com

color = effect * shapeColor + (1-effect) * fogColor 内容来自www.paper51.com

下面是场景中对雾的初始化 paper51.com

// 设置雾的颜色、密度和范围

内容来自论文无忧网 www.paper51.com

fog = newExponentialFog();

copyright paper51.com

   fog.setColor(color); paper51.com

   fog.setDensity(density);

内容来自www.paper51.com

   fog.setCapability(Fog.ALLOW_COLOR_WRITE);

内容来自www.paper51.com

   fog.setCapability(ExponentialFog.ALLOW_DENSITY_WRITE); copyright paper51.com

   fog.setInfluencingBounds(worldBounds);

copyright paper51.com

    Scene1.addChild (fog); paper51.com

http://www.paper51.com

内容来自www.paper51.com

paper51.com

http://www.paper51.com

图15各种不同的雾效果 copyright paper51.com

4.4.4 背景音乐 内容来自www.paper51.com

在场景中加入背景音乐可以是气氛更加活跃。 内容来自www.paper51.com

首先要把音乐加入到背景中,

内容来自论文无忧网 www.paper51.com

if ( debug ) System.err.println( "sounds..." ); paper51.com

String path = getCurrentDirectory( );

http://www.paper51.com

MediaContainer backgroundMedia  = new MediaContainer(

内容来自www.paper51.com

  path +"canon.wav" ); copyright paper51.com

backgroundMedia.setCacheEnable( true );

http://www.paper51.com

然后对背景音乐初始化, 内容来自www.paper51.com

backgroundSound = new BackgroundSound( ); http://www.paper51.com

backgroundSound.setEnable( true );

copyright paper51.com

backgroundSound.setLoop( Sound.INFINITE_LOOPS ); // 设置音乐循环播放 http://www.paper51.com

backgroundSound.setSoundData( backgroundMedia ); 内容来自www.paper51.com

backgroundSound.setInitialGain( 1.0f ); // 设置音量 http://www.paper51.com

backgroundSound.setSchedulingBounds( worldBounds ); http://www.paper51.com

backgroundSound.setCapability( Sound.ALLOW_ENABLE_WRITE); 内容来自www.paper51.com

backgroundSound.setCapability(Sound.ALLOW_INITIAL_GAIN_WRITE ); paper51.com

backgroundSound.setCapability(Sound.ALLOW_PAUSE_WRITE); copyright paper51.com

backgroundSound.setCapability(Sound.ALLOW_PAUSE_READ);

内容来自论文无忧网 www.paper51.com

Scene1.addChild( backgroundSound ); 内容来自www.paper51.com

§4.5 在网页上显示3D图形 内容来自论文无忧网 www.paper51.com

Java3D一个最大的特性是可以使用Applet作为显示容器, paper51.com

<HTML>

copyright paper51.com

<BODY> http://www.paper51.com

<APPLET code= ExExponentialFog.class width=400height=400>

paper51.com

</APPLET>

http://www.paper51.com

</BODY>

内容来自论文无忧网 www.paper51.com

</HTML> 内容来自论文无忧网 www.paper51.com

------分隔线----------------------------
联系方式