Source Code Cross Referenced for SimpleGeometry.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » platform_geometry » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3d.examples.platform_geometry 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: SimpleGeometry.java,v $
003:         *
004:         * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * - Redistribution of source code must retain the above copyright
011:         *   notice, this list of conditions and the following disclaimer.
012:         *
013:         * - Redistribution in binary form must reproduce the above copyright
014:         *   notice, this list of conditions and the following disclaimer in
015:         *   the documentation and/or other materials provided with the
016:         *   distribution.
017:         *
018:         * Neither the name of Sun Microsystems, Inc. or the names of
019:         * contributors may be used to endorse or promote products derived
020:         * from this software without specific prior written permission.
021:         *
022:         * This software is provided "AS IS," without a warranty of any
023:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026:         * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027:         * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028:         * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029:         * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030:         * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031:         * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032:         * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033:         * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034:         * POSSIBILITY OF SUCH DAMAGES.
035:         *
036:         * You acknowledge that this software is not designed, licensed or
037:         * intended for use in the design, construction, operation or
038:         * maintenance of any nuclear facility.
039:         *
040:         * $Revision: 1.2 $
041:         * $Date: 2007/02/09 17:21:50 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.platform_geometry;
046:
047:        import com.sun.j3d.utils.geometry.ColorCube;
048:        import com.sun.j3d.utils.geometry.*;
049:        import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
050:        import com.sun.j3d.utils.universe.*;
051:        import javax.media.j3d.*;
052:        import javax.vecmath.*;
053:        import java.applet.Applet;
054:        import com.sun.j3d.utils.applet.MainFrame;
055:        import java.awt.*;
056:
057:        /**
058:         * This class demonstrates the use of the Universe builder for stand-alone
059:         * applications along with the use of the PlatformGeometry node that is
060:         * present in the Java 3D Universe Builder utility.  The standard
061:         * HelloWorld application is brought up.  A transparent cylinder has been
062:         * added to the PlatfromGeometry node of the ViewingPlatform and the
063:         * MouseTranslate utility has been used to allow this sphere to be dragged
064:         * around the canvas.
065:         */
066:        public class SimpleGeometry extends Applet {
067:
068:            SimpleUniverse u = null;
069:
070:            public BranchGroup createSceneGraph() {
071:                // Create the root of the branch graph
072:                BranchGroup objRoot = new BranchGroup();
073:
074:                // Create a Transformgroup to scale all objects so they
075:                // appear in the scene.
076:                TransformGroup objScale = new TransformGroup();
077:                Transform3D t3d = new Transform3D();
078:                t3d.setScale(0.4);
079:                objScale.setTransform(t3d);
080:                objRoot.addChild(objScale);
081:
082:                // Create the transform group node and initialize it to the
083:                // identity.  Enable the TRANSFORM_WRITE capability so that
084:                // our behavior code can modify it at runtime.  Add it to the
085:                // root of the subgraph.
086:                TransformGroup objTrans = new TransformGroup();
087:                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
088:                objScale.addChild(objTrans);
089:
090:                // Create a simple shape leaf node, add it to the scene graph.
091:                objTrans.addChild(new ColorCube());
092:
093:                // Create a new Behavior object that will perform the desired
094:                // operation on the specified transform object and add it into
095:                // the scene graph.
096:                Transform3D yAxis = new Transform3D();
097:                Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0,
098:                        0, 4000, 0, 0, 0, 0, 0);
099:
100:                RotationInterpolator rotator = new RotationInterpolator(
101:                        rotationAlpha, objTrans, yAxis, 0.0f,
102:                        (float) Math.PI * 2.0f);
103:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
104:                        0.0, 0.0), 100.0);
105:                rotator.setSchedulingBounds(bounds);
106:                objTrans.addChild(rotator);
107:
108:                // Have Java 3D perform optimizations on this scene graph.
109:                objRoot.compile();
110:
111:                return objRoot;
112:            }
113:
114:            /*
115:             * Create the geometry to add to the platform geometry. 
116:             */
117:            PlatformGeometry createAimer() {
118:
119:                PlatformGeometry pg = new PlatformGeometry();
120:
121:                // This TransformGroup will be used by the MouseTranslate
122:                // utiltiy to move the cylinder around the canvas.  when the
123:                // the user holds down mouse button 3.
124:                TransformGroup moveTG = new TransformGroup();
125:                moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
126:                moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
127:                MouseTranslate mouseT = new MouseTranslate(moveTG);
128:                moveTG.addChild(mouseT);
129:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
130:                        0.0, 0.0), 100.0);
131:                mouseT.setSchedulingBounds(bounds);
132:                pg.addChild(moveTG);
133:
134:                // This TransformGroup is used to place the cylinder in the scene.
135:                // The cylinder will be rotated 90 degrees so it will appear as
136:                // a circle on the screen (could be made into a nice gun site...).
137:                // The cylinder is also displaced a little in Z so it is in front
138:                // of the viewer.
139:                Transform3D xForm = new Transform3D();
140:                xForm.rotX(Math.PI / 2.0);
141:                xForm.setTranslation(new Vector3d(0.0, 0.0, -0.7));
142:                TransformGroup placementTG = new TransformGroup(xForm);
143:                moveTG.addChild(placementTG);
144:
145:                // Create the cylinder - make it thin and transparent.
146:                Appearance cylinderAppearance = new Appearance();
147:                TransparencyAttributes transAttrs = new TransparencyAttributes(
148:                        TransparencyAttributes.FASTEST, 0.5f);
149:                //        cylinderAppearance.setTransparencyAttributes(transAttrs);
150:                Cylinder aimer = new Cylinder(0.06f, 0.005f, 0,
151:                        cylinderAppearance);
152:                placementTG.addChild(aimer);
153:
154:                return pg;
155:            }
156:
157:            public void init() {
158:
159:                setLayout(new BorderLayout());
160:                GraphicsConfiguration config = SimpleUniverse
161:                        .getPreferredConfiguration();
162:
163:                Canvas3D c = new Canvas3D(config);
164:                add("Center", c);
165:
166:                // Create a simple scene and attach it to the virtual universe
167:                BranchGroup scene = createSceneGraph();
168:
169:                u = new SimpleUniverse(c);
170:
171:                PlatformGeometry pg = createAimer();
172:
173:                // Now set the just created PlatformGeometry.
174:                ViewingPlatform vp = u.getViewingPlatform();
175:                vp.setPlatformGeometry(pg);
176:
177:                // This will move the ViewPlatform back a bit so the
178:                // objects in the scene can be viewed.
179:                u.getViewingPlatform().setNominalViewingTransform();
180:
181:                // Add everthing to the scene graph - it will now be displayed.
182:                u.addBranchGraph(scene);
183:            }
184:
185:            public SimpleGeometry(String[] args) {
186:            }
187:
188:            public SimpleGeometry() {
189:            }
190:
191:            public void destroy() {
192:                u.cleanup();
193:            }
194:
195:            public static void main(String[] args) {
196:                new MainFrame(new SimpleGeometry(args), 256, 256);
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.