📄 j-java3d-10-3.html
字号:
</table>
<br>
<br>
</p>
<font size="2" face="Verdana, Arial, Helvetica">
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
/*
*
* Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
*/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;
/**
Simple Texture Mapping example
*/
public class Wallpaper extends Applet {
private SimpleUniverse universe ;
private BranchGroup scene;
private Canvas3D canvas;
private BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0);
private static java.net.URL texImage = null;
public Group createGeometry(int filter, float y, java.net.URL texImage) {
/**
Create some Texture mapped objects
*/
Appearance appearance = new Appearance();
TextureLoader tex = new TextureLoader(texImage, TextureLoader.GENERATE_MIPMAP , this);
Texture texture = tex.getTexture();
texture.setMinFilter(filter) ;
appearance.setTexture(texture);
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
appearance.setTextureAttributes(texAttr);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
// Set up the material properties
appearance.setMaterial(new Material(white, black, white, black, 1.0f));
//use to build tree hierarchy
Group topNode = new Group();
Transform3D translate = new Transform3D();
translate.setTranslation(new Vector3f(.5f,y,-0.5f));
TransformGroup gimmeSpace = new TransformGroup(translate);
Cone cone = new Cone(.4f,0.8f,Primitive.GENERATE_NORMALS|Primitive.GENERATE_TEXTURE_COORDS,appearance);
gimmeSpace.addChild(cone);
topNode.addChild(gimmeSpace); //cone at bottom
translate = new Transform3D();
translate.setTranslation(new Vector3f(-0.5f,y,-0.5f));
gimmeSpace = new TransformGroup(translate);
Sphere sphere = new Sphere(.4f,Primitive.GENERATE_NORMALS|Primitive.GENERATE_TEXTURE_COORDS,appearance);
gimmeSpace.addChild(sphere);
topNode.addChild(gimmeSpace); //cone at bottom
return topNode;
}
public void setupView() {
/** Add some view related things to view branch side
of scene graph */
// add mouse interaction to the ViewingPlatform
OrbitBehavior orbit = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL|OrbitBehavior.STOP_ZOOM);
orbit.setSchedulingBounds(bounds);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
viewingPlatform.setNominalViewingTransform();
viewingPlatform.setViewPlatformBehavior(orbit);
}
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create a simple Shape3D node; add it to the scene graph.
// Set up the texture map
// the path to the image
objRoot.addChild(createGeometry( Texture.BASE_LEVEL_POINT,1.0f,texImage));
objRoot.addChild(createGeometry( Texture.MULTI_LEVEL_POINT,0.0f,texImage));
objRoot.addChild(createGeometry( Texture.MULTI_LEVEL_LINEAR,-1.0f,texImage));
//throw in some light so we aren't stumbling
//around in the dark
Color3f lightColor = new Color3f(.5f,.5f,.5f);
AmbientLight ambientLight= new AmbientLight(lightColor);
ambientLight.setInfluencingBounds(bounds);
objRoot.addChild(ambientLight);
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setColor(lightColor);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
return objRoot;
}
public Wallpaper() {
}
public void init() {
BranchGroup scene = createSceneGraph();
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
add("Center", canvas);
// Create a simple scene and attach it to the virtual universe
universe = new SimpleUniverse(canvas);
setupView();
universe.addBranchGraph(scene);
}
public void destroy() {
universe.removeAllLocales();
}
//
// The following allows Wallpaper to be run as an application
// as well as an applet
//
public static void main(String[] args) {
try{
if (args.length == 0) {
texImage = new java.net.URL("file:./images/speedchase.jpg");
} else {
texImage = new java.net.URL(args[0]);
}
}
catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
new MainFrame(new Wallpaper(), 256, 256);
}
}
</code>
</pre>
<br>
</font></td>
</tr>
</table>
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
<TR>
<TD background="../i/sw-gold.gif"><a border="0" href="index.html" onMouseOver="iOver('topmain'); iOver('bottommain'); self.status=mainblurb; return true;" onMouseOut="iOut('topmain'); iOut('bottommain'); self.status=''; return true;"><img alt="主菜单" border="0" src="../i/main.gif" name="bottommain"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topsection'); iOver('bottomsection'); self.status=sectionblurb; return true;" onMouseOut="iOut('topsection'); iOut('bottomsection'); self.status=''; return true;" href="index10.html"><img alt="章节菜单" border="0" src="../i/section.gif" name="bottomsection"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topfeedback'); iOver('bottomfeedback'); self.status=feedbackblurb; return true;" onMouseOut="iOut('topfeedback'); iOut('bottomfeedback'); self.status=''; return true;" href="j-java3d-9-3.html"><img alt="给出此教程的反馈意见" border="0" src="../i/feedback.gif" name="bottomfeedback"></a></TD><TD width="100%" background="../i/sw-gold.gif"><img src="../i/c.gif"></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topprevious'); iOver('bottomprevious'); self.status=previousblurb; return true;" onMouseOut="iOut('topprevious'); iOut('bottomprevious'); self.status=''; return true;" href="j-java3d-10-2.html"><img alt="上页" border="0" src="../i/previous.gif" name="bottomprevious"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topnext'); iOver('bottomnext'); self.status=nextblurb; return true;" onMouseOut="iOut('topnext'); iOut('bottomnext'); self.status=''; return true;" href="j-java3d-10-4.html"><img alt="下页" border="0" src="../i/next.gif" name="bottomnext"></a></TD>
</TR>
<TR>
<TD width="150" height="1" bgcolor="#000000" colspan="6"><IMG alt="" height="1" width="150" src="../i/c.gif"></TD>
</TR>
</TABLE>
<TABLE width="100%" cellpadding="0" cellspacing="0" border="0">
<TR>
<TD width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img alt="" height="1" width="1" src="../i/c.gif"></td>
</tr>
<tr valign="top">
<td class="bbg" height="21"> <a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/index.shtml">关于 IBM</a><span class="divider"> | </span><a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/privacy/index.shtml">隐私条约</a><span class="divider"> | </span><a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/legal/index.shtml">法律条款</a><span class="divider"> | </span><a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/contact/index.shtml">联系 IBM</a></td>
</tr>
</table>
</TD>
</TR>
</TABLE>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -