package elte.java2_utikalauz5.java3d; import java.awt.*; import javax.vecmath.*; import javax.media.j3d.*; /** 3D szöveg megjelenítése egy ablakban.
@link.forrásfájl {@docRoot}/../data/java3d/src Text3DDemo.java @link.letöltés {@docRoot}/../data/java3d Text3DDemo.jar @since Java 2 Útikalauz programozóknak 5.0 */ class Text3DDemo extends Frame { /** Verziószám */ private final static long serialVersionUID = 15L; public static void main(String[] args) { new Text3DDemo(); } public Text3DDemo() { super("Text3DDemo"); enableEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK); GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(new GraphicsConfigTemplate3D()); Canvas3D c = new Canvas3D(config); add(c); UniverseBuilder u = new UniverseBuilder(c); BranchGroup scene = createSceneGraph(); u.addBranchGraph(scene); setSize(300,400); setVisible(true); } /** Ablakesemény feldolgozása, bezáráskor kilépés. @param esemény A fellépett esemény */ @Override protected void processWindowEvent(java.awt.event.WindowEvent esemény) { if (esemény.getID() == esemény.WINDOW_CLOSING) System.exit(0); super.processWindowEvent( esemény ); } public BranchGroup createSceneGraph() { BranchGroup branchGroup = new BranchGroup(); TransformGroup transformGroup = new TransformGroup(); Font3D font3d = new Font3D(new Font("TestFont", Font.PLAIN, 1),new FontExtrusion()); Text3D text3D = new Text3D(font3d, new String("TEXT3D"),new Point3f(0.0f, -1.0f, 0.0f),Text3D.ALIGN_CENTER,Text3D.PATH_DOWN); Shape3D shape3D = new Shape3D(text3D); transformGroup.addChild(shape3D); transformGroup.addChild(new Axes().getShape()); branchGroup.addChild(transformGroup); return branchGroup; } class UniverseBuilder { Locale locale; UniverseBuilder(Canvas3D c) { Transform3D t = new Transform3D(); Transform3D t2 = new Transform3D(); t2.setEuler( new Vector3d(-30.0*(Math.PI/180.0),45.0*(Math.PI/180.0),0.0)); t.set(4,new Vector3d(6.0,5.0,6.0)); t.mul(t,t2); VirtualUniverse universe = new VirtualUniverse(); locale = new Locale(universe); PhysicalBody body = new PhysicalBody(); PhysicalEnvironment environment = new PhysicalEnvironment(); BranchGroup viewPlatformBranchGroup = new BranchGroup(); TransformGroup viewPlatformTransformGroup = new TransformGroup(t); ViewPlatform viewPlatform = new ViewPlatform(); View view = new View(); view.addCanvas3D(c); view.setPhysicalBody(body); view.setPhysicalEnvironment(environment); view.attachViewPlatform(viewPlatform); viewPlatformTransformGroup.addChild(viewPlatform); viewPlatformBranchGroup.addChild(viewPlatformTransformGroup); locale.addBranchGraph(viewPlatformBranchGroup); } void addBranchGraph(BranchGroup bg) { locale.addBranchGraph(bg); } } class Axes { double verts[] = { 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, }; float[] colors = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; private Shape3D shape; public Axes() { LineArray lines = new LineArray(6, LineArray.COORDINATES | LineArray.COLOR_3); lines.setCoordinates(0, verts); lines.setColors(0, colors); shape = new Shape3D(lines, new Appearance()); } public Shape3D getShape() { return shape; } } }