Source Code Cross Referenced for Primitive.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » utils » environment » 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.j3dfly.utils.environment.geometry 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/environment/geometry/Primitive.java,v 1.1 2005/04/20 21:04:55 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly.utils.environment.geometry;
019:
020:        import java.io.*;
021:        import java.util.*;
022:        import javax.media.j3d.*;
023:        import javax.vecmath.*;
024:        import java.math.*;
025:
026:        /**
027:         * Base class for all Java 3D primitives. 
028:         */
029:
030:        public abstract class Primitive extends Group {
031:            /**
032:             * Specifies that normals are generated along with the positions. 
033:             **/
034:            public static final int GENERATE_NORMALS = 0x01;
035:
036:            /**
037:             * Specifies that texture coordinates are generated along with the
038:             * positions. 
039:             **/
040:            public static final int GENERATE_TEXTURE_COORDS = 0x02;
041:
042:            /**
043:             * Specifies that normals are to be flipped along the surface.
044:             **/
045:            public static final int GENERATE_NORMALS_INWARD = 0x04;
046:
047:            public static final int GENERATE_COLOR_3 = 0x08;
048:
049:            /** 
050:             * Specifies that the geometry being created will not be shared by 
051:             * another scene graph node. By default all primitives created with
052:             * the same parameters share their geometry (you have 50 spheres in
053:             * your scene, but the geometry stored only once). A change to one
054:             * primitive will effect all shared nodes. 
055:             * You specify this flag if you do not wish to share any geometry
056:             * among primitives of the same parameters.
057:             */
058:            public static final int GEOMETRY_NOT_SHARED = 0x10;
059:
060:            /**
061:             * Specifies that the ALLOW_INTERSECT
062:             * capability bit should be set on the generated geometry.
063:             * This allows the object
064:             * to be picked using Geometry based picking.
065:             */
066:            public static final int ENABLE_GEOMETRY_PICKING = 0x20;
067:
068:            /**
069:             * Specifies that the ALLOW_APPEARANCE_READ and 
070:             * ALLOW_APPEARANCE_WRITE bits are to be set on the generated
071:             * geometry's Shape3D nodes.
072:             */
073:            public static final int ENABLE_APPEARANCE_MODIFY = 0x40;
074:
075:            static final int SPHERE = 0x01;
076:            static final int CYLINDER = 0x02;
077:            static final int CONE = 0x04;
078:            static final int BOX = 0x08;
079:
080:            int numTris = 0;
081:            int numVerts = 0;
082:
083:            /**
084:             * Primitive flags.
085:             */
086:            int flags;
087:
088:            /** Constructs a default primitive.
089:             */
090:            public Primitive() {
091:                flags = 0;
092:                setCapability(ENABLE_PICK_REPORTING);
093:                setCapability(ALLOW_CHILDREN_READ);
094:            }
095:
096:            /** Returns total number of triangles in this primitive. 
097:             */
098:            public int getNumTriangles() {
099:                return numTris;
100:            }
101:
102:            /** Sets the total number of triangles in this primitive. 
103:             */
104:            public void setNumTriangles(int num) {
105:                numTris = num;
106:            }
107:
108:            /** Returns total number of vertices in this primitive. 
109:             */
110:            public int getNumVertices() {
111:                return numVerts;
112:            }
113:
114:            /** Sets total number of vertices in this primitive. 
115:             */
116:            public void setNumVertices(int num) {
117:                numVerts = num;
118:            }
119:
120:            /** Returns the flags of primitive (generate normal, textures, caching, etc).
121:             */
122:            public int getPrimitiveFlags() {
123:                return flags;
124:            }
125:
126:            /**
127:             * @deprecated The primitive flags must be set at construction time
128:             * via one of the subclass constructors.
129:             */
130:            public void setPrimitiveFlags(int fl) {
131:                System.err.println("Warning: setPrimitiveFlags has no effect");
132:            }
133:
134:            /** Obtains a shape node of a subpart of the primitive.
135:             * @param partid identifier for a given subpart of the primitive.
136:             */
137:            public abstract Shape3D getShape(int partid);
138:
139:            /** Gets the appearance of the primitive (defaults to first subpart).
140:             */
141:            public Appearance getAppearance() {
142:                return getShape(0).getAppearance();
143:            }
144:
145:            /** Sets the appearance of a subpart given a partid.
146:             */
147:
148:            public void setAppearance(int partid, Appearance ap) {
149:                getShape(partid).setAppearance(ap);
150:            }
151:
152:            /** Sets the main appearance of the primitive (all subparts) to 
153:             *  same appearance.
154:             */
155:            public abstract void setAppearance(Appearance ap);
156:
157:            /** Sets the main appearance of the primitive (all subparts) to 
158:             *  a default white appearance.
159:             */
160:            public void setAppearance() {
161:
162:                Color3f aColor = new Color3f(0.1f, 0.1f, 0.1f);
163:                Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
164:                Color3f dColor = new Color3f(0.6f, 0.6f, 0.6f);
165:                Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
166:
167:                Material m = new Material(aColor, eColor, dColor, sColor,
168:                        100.0f);
169:                Appearance a = new Appearance();
170:                m.setLightingEnable(true);
171:                a.setMaterial(m);
172:                setAppearance(a);
173:            }
174:
175:            static Hashtable geomCache = new Hashtable();
176:
177:            String strfloat(float x) {
178:                return (new Float(x)).toString();
179:            }
180:
181:            protected void cacheGeometry(int kind, float a, float b, float c,
182:                    int d, int e, int flags, GeomBuffer geo) {
183:                String key = new String(kind + strfloat(a) + strfloat(b)
184:                        + strfloat(c) + d + e + flags);
185:                geomCache.put(key, geo);
186:            }
187:
188:            protected GeomBuffer getCachedGeometry(int kind, float a, float b,
189:                    float c, int d, int e, int flags) {
190:                String key = new String(kind + strfloat(a) + strfloat(b)
191:                        + strfloat(c) + d + e + flags);
192:                Object cache = geomCache.get(key);
193:
194:                return ((GeomBuffer) cache);
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.