/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package j3dproject;
/**********************************************************
Copyright (C) 2001 Daniel Selman
First distributed with the book "Java 3D Programming"
by Daniel Selman and published by Manning Publications.
http://manning.com/selman
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The license can be found on the WWW at:
http://www.fsf.org/copyleft/gpl.html
Or by writing to:
Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Authors can be contacted at:
Daniel Selman: daniel@selman.org
If you make changes you think others would like, please
contact one of the authors or someone at the
www.j3d.org web site.
**************************************************************/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.GraphicsConfigTemplate;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.AudioDevice;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Bounds;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.Group;
import javax.media.j3d.ImageComponent2D;
import javax.media.j3d.LineAttributes;
import javax.media.j3d.Locale;
import javax.media.j3d.Material;
import javax.media.j3d.NodeComponent;
import javax.media.j3d.PhysicalBody;
import javax.media.j3d.PhysicalEnvironment;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.QuadArray;
import javax.media.j3d.RenderingAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TexCoordGeneration;
import javax.media.j3d.Texture;
import javax.media.j3d.Texture2D;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.TransparencyAttributes;
import javax.media.j3d.View;
import javax.media.j3d.ViewPlatform;
import javax.media.j3d.VirtualUniverse;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import javax.vecmath.Vector4f;
import com.sun.j3d.audioengines.javasound.JavaSoundMixer;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.image.TextureLoader;
/*******************************************************************************
* Copyright (C) 2001 Daniel Selman
*
* First distributed with the book "Java 3D Programming" by Daniel Selman and
* published by Manning Publications. http://manning.com/selman
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* The license can be found on the WWW at: http://www.fsf.org/copyleft/gpl.html
*
* Or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite
* 330, Boston, MA 02111-1307, USA.
*
* Authors can be contacted at: Daniel Selman: daniel@selman.org
*
* If you make changes you think others would like, please contact one of the
* authors or someone at the www.j3d.org web site.
******************************************************************************/
//*****************************************************************************
/**
* Java3dApplet
*
* Base class for defining a Java 3D applet. Contains some useful methods for
* defining views and scenegraphs etc.
*
* @author Daniel Selman
* @version 1.0
*/
//*****************************************************************************
/**
* Allows the various Java 3D Appearance components to be specified
* interactively and applies the Appearance to an object in a scene.
* <p>
* This example can only be run as an application as it uses a MenuBar which can
* only be associated with a Frame (in AWT)
*/
public class AppearanceTest extends Java3dApplet {
private static int m_kWidth = 400;
private static int m_kHeight = 400;
private Frame m_Frame = null;
private Appearance m_Appearance = null;
private AppearanceComponent[] m_ComponentArray = null;
public AppearanceTest() {
m_Appearance = new Appearance();
TextureComponent.setComponent(this);
m_ComponentArray = new AppearanceComponent[] {
new PolygonComponent(m_Appearance),
new ColoringComponent(m_Appearance),
new LineComponent(m_Appearance),
new MaterialComponent(m_Appearance),
new PointComponent(m_Appearance),
new RenderingComponent(m_Appearance),
new TransparencyComponent(m_Appearance),
new TextureComponent(m_Appearance),
new TextureAttributesComponent(m_Appearance),
new TexGenComponent(m_Appearance) };
}
protected void addCanvas3D(Canvas3D c3d) {
if (m_Frame != null) {
MenuBar menuBar = new MenuBar();
for (int n = 0; n < m_ComponentArray.length; n++)
menuBar.add(m_ComponentArray[n].createMenu());
m_Frame.setMenuBar(menuBar);
}
setLayout(new BorderLayout());
add(c3d, BorderLayout.CENTER);
doLayout();
}
protected double getScale() {
return 0.1;
}
protected BranchGroup createSceneBranchGroup() {
BranchGroup objRoot = super.createSceneBranchGroup();
TransformGroup zoomTg = new TransformGroup();
zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
// attach a navigation behavior to the position of the viewer
KeyNavigatorBehavior key = new KeyNavigatorBehavior(zoomTg);
key.setSchedulingBounds(createApplicationBounds());
key.setEnable(true);
objRoot.addChild(key);
// create a TransformGroup to flip the hand onto its end and enlarge it.
TransformGroup objTrans1 = new TransformGroup();
Transform3D tr = new Transform3D();
objTrans1.getTransform(tr);
tr.setEuler(new Vector3d(0.5 * Math.PI, 0.6, 0));
objTrans1.setTransform(tr);
// Set up the global lights
Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
AmbientLight aLgt = new AmbientLight(alColor);
aLgt.setInfluencingBounds(getApplicationBounds());
DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
lgt1.setInfluencingBounds(getApplicationBounds());
objRoot.addChild(aLgt);
objRoot.addChild(lgt1);
int nScale = 50;
Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS
| Primitiv
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
这是利用java3d编写的入门级别例子。 都是源码. 运行环境: 1.jdk1.2以上 2.请确保你已经配置好java3d的运行环境 3.注意,java3d能够运行相当重要的一步是,在windows下:java3d本身带有3个dll的链接库,别把它们当透明了,将他们放到jdk的jre的bin目录下;linux一样,不过那是两个so文件,放到jre的bin下面。 如果需要交流,请发信给我.
资源推荐
资源详情
资源评论
收起资源包目录
j3dproject.rar (15个子文件)
j3dproject
ProduceFaces.java 516B
BouncingBall.java 4KB
HelloJ3D.java 1KB
FF.jpg 42KB
FinalDogDemo.java 2KB
Point1.java 1KB
AppearanceTest.java 61KB
TransPosition.java 3KB
SetTheLocation.java 1KB
Demo.java 659B
UsingTexture.java 3KB
UsingSwingInJ3D.java 1KB
UsingCartoon.java 437B
UsingLightEffect.java 1KB
UglyCube.java 830B
共 15 条
- 1
资源评论
码农下的天桥
- 粉丝: 871
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功