Source Code Cross Referenced for PickText3DBounds.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » picking » 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.picking 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: PickText3DBounds.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:48 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.picking;
046:
047:        import java.applet.Applet;
048:        import java.awt.BorderLayout;
049:        import com.sun.j3d.utils.picking.PickTool;
050:        import com.sun.j3d.utils.picking.behaviors.*;
051:        import com.sun.j3d.utils.geometry.Sphere;
052:        import com.sun.j3d.utils.applet.MainFrame;
053:        import com.sun.j3d.utils.universe.*;
054:        import javax.media.j3d.*;
055:        import javax.vecmath.*;
056:        import java.util.Enumeration;
057:        import java.awt.*;
058:        import java.lang.String;
059:
060:        public class PickText3DBounds extends Applet {
061:
062:            private SimpleUniverse u = null;
063:
064:            public BranchGroup createSceneGraph(Canvas3D canvas) {
065:                Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
066:                Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
067:                Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
068:                Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
069:                Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
070:                Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
071:                Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
072:
073:                Transform3D t;
074:
075:                // Create the root of the branch graph
076:                BranchGroup objRoot = new BranchGroup();
077:
078:                // Create a Transformgroup to scale all objects so they
079:                // appear in the scene.
080:                TransformGroup objScale = new TransformGroup();
081:                Transform3D t3d = new Transform3D();
082:                t3d.setScale(0.4);
083:                objScale.setTransform(t3d);
084:                objRoot.addChild(objScale);
085:
086:                // Create a bounds for the background and lights
087:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
088:                        0.0, 0.0), 100.0);
089:
090:                // Set up the background
091:                Background bg = new Background(bgColor);
092:                bg.setApplicationBounds(bounds);
093:                objScale.addChild(bg);
094:
095:                Material m = new Material(objColor, eColor, objColor, sColor,
096:                        100.0f);
097:                Appearance a = new Appearance();
098:                m.setLightingEnable(true);
099:                a.setMaterial(m);
100:                Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1),
101:                        new FontExtrusion());
102:                Text3D txt = new Text3D(f3d, new String("TEXT3D"), new Point3f(
103:                        -2.0f, 0.0f, 0.0f));
104:                //    txt.setCapability(Geometry.ALLOW_INTERSECT);
105:                Shape3D s3D = new Shape3D();
106:                s3D.setGeometry(txt);
107:                s3D.setAppearance(a);
108:
109:                // Create a transform group node and initialize it to the
110:                // identity.  Enable the TRANSFORM_WRITE capability so that
111:                // our behavior code can modify it at runtime.
112:                TransformGroup spinTg = new TransformGroup();
113:                spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
114:                spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
115:                spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
116:
117:                spinTg.addChild(s3D);
118:                objScale.addChild(spinTg);
119:
120:                // Create the transform group node for the each light and initialize
121:                // it to the identity.  Enable the TRANSFORM_WRITE capability so that
122:                // our behavior code can modify it at runtime.  Add them to the root
123:                // of the subgraph.
124:
125:                // Create transformations for the positional lights
126:                t = new Transform3D();
127:                Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
128:                t.set(lPos1);
129:                TransformGroup l1Trans = new TransformGroup(t);
130:                l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
131:                l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
132:                l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
133:                objScale.addChild(l1Trans);
134:
135:                t = new Transform3D();
136:                Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
137:                t.set(lPos2);
138:                TransformGroup l2Trans = new TransformGroup(t);
139:                l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
140:                l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
141:                l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
142:
143:                objScale.addChild(l2Trans);
144:
145:                // Create Geometry for point lights
146:                ColoringAttributes caL1 = new ColoringAttributes();
147:                ColoringAttributes caL2 = new ColoringAttributes();
148:                caL1.setColor(lColor1);
149:                caL2.setColor(lColor2);
150:                Appearance appL1 = new Appearance();
151:                Appearance appL2 = new Appearance();
152:                appL1.setColoringAttributes(caL1);
153:                appL2.setColoringAttributes(caL2);
154:                l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15,
155:                        appL1));
156:                l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS, 15,
157:                        appL2));
158:
159:                // Create lights
160:                AmbientLight aLgt = new AmbientLight(alColor);
161:
162:                Light lgt1;
163:                Light lgt2;
164:
165:                Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
166:                Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
167:                lgt1 = new PointLight(lColor1, lPoint, atten);
168:                lgt2 = new PointLight(lColor2, lPoint, atten);
169:
170:                // Set the influencing bounds
171:                aLgt.setInfluencingBounds(bounds);
172:                lgt1.setInfluencingBounds(bounds);
173:                lgt2.setInfluencingBounds(bounds);
174:
175:                // Add the lights into the scene graph
176:                objScale.addChild(aLgt);
177:                l1Trans.addChild(lgt1);
178:                l2Trans.addChild(lgt2);
179:
180:                PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot,
181:                        canvas, bounds);
182:                behavior1.setMode(PickTool.BOUNDS);
183:                objRoot.addChild(behavior1);
184:
185:                PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot,
186:                        canvas, bounds);
187:                behavior2.setMode(PickTool.BOUNDS);
188:                objRoot.addChild(behavior2);
189:
190:                PickTranslateBehavior behavior3 = new PickTranslateBehavior(
191:                        objRoot, canvas, bounds);
192:                behavior3.setMode(PickTool.BOUNDS);
193:                objRoot.addChild(behavior3);
194:
195:                // Let Java 3D perform optimizations on this scene graph.
196:                objRoot.compile();
197:
198:                return objRoot;
199:            }
200:
201:            public PickText3DBounds() {
202:            }
203:
204:            public void init() {
205:                setLayout(new BorderLayout());
206:                GraphicsConfiguration config = SimpleUniverse
207:                        .getPreferredConfiguration();
208:
209:                Canvas3D c = new Canvas3D(config);
210:                add("Center", c);
211:
212:                u = new SimpleUniverse(c);
213:                BranchGroup scene = createSceneGraph(c);
214:
215:                // This will move the ViewPlatform back a bit so the
216:                // objects in the scene can be viewed.
217:                u.getViewingPlatform().setNominalViewingTransform();
218:
219:                u.addBranchGraph(scene);
220:            }
221:
222:            public void destroy() {
223:                u.cleanup();
224:            }
225:
226:            //
227:            // The following allows Text3DMotion to be run as an application
228:            // as well as an applet
229:            //
230:            public static void main(String[] args) {
231:                new MainFrame(new PickText3DBounds(), 700, 700);
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.