📄 textc.java
字号:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.geometry.Cylinder;
import javax.media.j3d.*;
import javax.vecmath.*;
public class TextC extends Applet {
private java.net.URL texImage = null;
private SimpleUniverse u = null;
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = 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);
objRoot.addChild(bg);
Transform3D t3D = new Transform3D();
t3D.setTranslation(new Vector3f(0.0f, -0.2f, -3.0f));
TransformGroup objMove = new TransformGroup(t3D);
objRoot.addChild(objMove);
// Create the transform group node and initialize it to the
// identity. Add it to the root of the subgraph.
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objMove.addChild(objSpin);
Appearance textAppear = new Appearance();
PolygonAttributes polyAttrib = new PolygonAttributes();
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
textAppear.setPolygonAttributes(polyAttrib);
TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
TexCoordGeneration.TEXTURE_COORDINATE_2);
textAppear.setTexCoordGeneration(tcg);
String filename = "brick.jpg";
TextureLoader myTL = new TextureLoader(texImage, this);
Texture myTex = myTL.getTexture();
textAppear.setTexture(myTex);
// Create a simple shape leaf node, add it to the scene graph.
// Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1),
// new FontExtrusion());
Font3D font3D = new Font3D(new Font("宋体", Font.PLAIN, 1),
new FontExtrusion());
Text3D textGeom = new Text3D(font3D, new String("Java 3D"));
textGeom.setAlignment(Text3D.ALIGN_CENTER);
Shape3D textShape = new Shape3D();
textShape.setGeometry(textGeom);
textShape.setAppearance(textAppear);
objSpin.addChild(textShape);
return objRoot;
} // end of CreateSceneGraph method
public TextC() {
}
public TextC(java.net.URL url) {
texImage = url;
}
public void init() {
if (texImage == null) {
// the path to the image for an applet
try {
texImage = new java.net.URL(getCodeBase().toString() +
"../misc/brick.jpg");
}
catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
}
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
u = new SimpleUniverse(c);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public void destroy() {
u.removeAllLocales();
}
//
// The following allows TextureImage to be run as an application
// as well as an applet
//
public static void main(String[] args) {
java.net.URL url = null;
if (args.length > 0) {
try {
url = new java.net.URL("file:" + args[0]);
}
catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
}
else {
// the path to the image for an application
try {
url = new java.net.URL("file:../misc/brick.jpg");
}
catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
}
new MainFrame(new TextC(url), 512, 200);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -