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


001:        /*
002:         * $RCSfile: Box.java,v $
003:         *
004:         *      @(#)Box.java 1.25 98/11/05 20:34:04
005:         *
006:         * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007:         *
008:         * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009:         * modify and redistribute this software in source and binary code form,
010:         * provided that i) this copyright notice and license appear on all copies of
011:         * the software; and ii) Licensee does not utilize the software in a manner
012:         * which is disparaging to Sun.
013:         *
014:         * This software is provided "AS IS," without a warranty of any kind. ALL
015:         * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016:         * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017:         * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018:         * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019:         * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020:         * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021:         * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022:         * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023:         * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024:         * POSSIBILITY OF SUCH DAMAGES.
025:         *
026:         * This software is not designed or intended for use in on-line control of
027:         * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028:         * the design, construction, operation or maintenance of any nuclear
029:         * facility. Licensee represents and warrants that it will not use or
030:         * redistribute the Software for such purposes.
031:         *
032:         * $Revision: 1.3 $
033:         * $Date: 2005/02/03 23:06:52 $
034:         * $State: Exp $
035:         */
036:        /*
037:         *
038:         * @Author: Rick Goldberg
039:         * @Author: Doug Gehringer
040:         */
041:        package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043:        import javax.media.j3d.BoundingBox;
044:
045:        import javax.vecmath.Point3d;
046:
047:        /**  Description of the Class */
048:        public class Box extends Geometry {
049:
050:            // field
051:            SFVec3f size;
052:
053:            javax.media.j3d.QuadArray impl;
054:            BoundingBox bounds;
055:
056:            /**
057:             *Constructor for the Box object
058:             *
059:             *@param  loader Description of the Parameter
060:             */
061:            public Box(Loader loader) {
062:                super (loader);
063:                size = new SFVec3f(2.0f, 2.0f, 2.0f);
064:                initFields();
065:            }
066:
067:            /**
068:             *Constructor for the Box object
069:             *
070:             *@param  loader Description of the Parameter
071:             *@param  size Description of the Parameter
072:             */
073:            Box(Loader loader, SFVec3f size) {
074:                super (loader);
075:                this .size = size;
076:                initFields();
077:            }
078:
079:            /**  Description of the Method */
080:            private void updatePoints() {
081:                float[] coords = new float[72];
082:
083:                float sx = size.value[0] / 2.0f;
084:                float sy = size.value[1] / 2.0f;
085:                float sz = size.value[2] / 2.0f;
086:
087:                Point3d min = new Point3d(-sx, -sy, -sz);
088:                Point3d max = new Point3d(sx, sy, sz);
089:                bounds = new BoundingBox(min, max);
090:
091:                // front face
092:                coords[0] = sx;
093:                coords[1] = -sy;
094:                coords[2] = sz;
095:                coords[3] = sx;
096:                coords[4] = sy;
097:                coords[5] = sz;
098:                coords[6] = -sx;
099:                coords[7] = sy;
100:                coords[8] = sz;
101:                coords[9] = -sx;
102:                coords[10] = -sy;
103:                coords[11] = sz;
104:                // back face
105:                coords[12] = -sx;
106:                coords[13] = -sy;
107:                coords[14] = -sz;
108:                coords[15] = -sx;
109:                coords[16] = sy;
110:                coords[17] = -sz;
111:                coords[18] = sx;
112:                coords[19] = sy;
113:                coords[20] = -sz;
114:                coords[21] = sx;
115:                coords[22] = -sy;
116:                coords[23] = -sz;
117:                // right face
118:                coords[24] = sx;
119:                coords[25] = -sy;
120:                coords[26] = -sz;
121:                coords[27] = sx;
122:                coords[28] = sy;
123:                coords[29] = -sz;
124:                coords[30] = sx;
125:                coords[31] = sy;
126:                coords[32] = sz;
127:                coords[33] = sx;
128:                coords[34] = -sy;
129:                coords[35] = sz;
130:                // left face
131:                coords[36] = -sx;
132:                coords[37] = -sy;
133:                coords[38] = sz;
134:                coords[39] = -sx;
135:                coords[40] = sy;
136:                coords[41] = sz;
137:                coords[42] = -sx;
138:                coords[43] = sy;
139:                coords[44] = -sz;
140:                coords[45] = -sx;
141:                coords[46] = -sy;
142:                coords[47] = -sz;
143:                // top face
144:                coords[48] = sx;
145:                coords[49] = sy;
146:                coords[50] = sz;
147:                coords[51] = sx;
148:                coords[52] = sy;
149:                coords[53] = -sz;
150:                coords[54] = -sx;
151:                coords[55] = sy;
152:                coords[56] = -sz;
153:                coords[57] = -sx;
154:                coords[58] = sy;
155:                coords[59] = sz;
156:                // bottom face
157:                coords[60] = -sx;
158:                coords[61] = -sy;
159:                coords[62] = sz;
160:                coords[63] = -sx;
161:                coords[64] = -sy;
162:                coords[65] = -sz;
163:                coords[66] = sx;
164:                coords[67] = -sy;
165:                coords[68] = -sz;
166:                coords[69] = sx;
167:                coords[70] = -sy;
168:                coords[71] = sz;
169:
170:                impl.setCoordinates(0, coords);
171:            }
172:
173:            /**  Description of the Method */
174:            private void initNormals() {
175:                float[] normals = new float[72];
176:
177:                // front face
178:                normals[0] = 0.0f;
179:                normals[1] = 0.0f;
180:                normals[2] = 1.0f;
181:                normals[3] = 0.0f;
182:                normals[4] = 0.0f;
183:                normals[5] = 1.0f;
184:                normals[6] = 0.0f;
185:                normals[7] = 0.0f;
186:                normals[8] = 1.0f;
187:                normals[9] = 0.0f;
188:                normals[10] = 0.0f;
189:                normals[11] = 1.0f;
190:
191:                // back face
192:                normals[12] = 0.0f;
193:                normals[13] = 0.0f;
194:                normals[14] = -1.0f;
195:                normals[15] = 0.0f;
196:                normals[16] = 0.0f;
197:                normals[17] = -1.0f;
198:                normals[18] = 0.0f;
199:                normals[19] = 0.0f;
200:                normals[20] = -1.0f;
201:                normals[21] = 0.0f;
202:                normals[22] = 0.0f;
203:                normals[23] = -1.0f;
204:
205:                // right face
206:                normals[24] = 1.0f;
207:                normals[25] = 0.0f;
208:                normals[26] = 0.0f;
209:                normals[27] = 1.0f;
210:                normals[28] = 0.0f;
211:                normals[29] = 0.0f;
212:                normals[30] = 1.0f;
213:                normals[31] = 0.0f;
214:                normals[32] = 0.0f;
215:                normals[33] = 1.0f;
216:                normals[34] = 0.0f;
217:                normals[35] = 0.0f;
218:
219:                // left face
220:                normals[36] = -1.0f;
221:                normals[37] = 0.0f;
222:                normals[38] = 0.0f;
223:                normals[39] = -1.0f;
224:                normals[40] = 0.0f;
225:                normals[41] = 0.0f;
226:                normals[42] = -1.0f;
227:                normals[43] = 0.0f;
228:                normals[44] = 0.0f;
229:                normals[45] = -1.0f;
230:                normals[46] = 0.0f;
231:                normals[47] = 0.0f;
232:
233:                // top face
234:                normals[48] = 0.0f;
235:                normals[49] = 1.0f;
236:                normals[50] = 0.0f;
237:                normals[51] = 0.0f;
238:                normals[52] = 1.0f;
239:                normals[53] = 0.0f;
240:                normals[54] = 0.0f;
241:                normals[55] = 1.0f;
242:                normals[56] = 0.0f;
243:                normals[57] = 0.0f;
244:                normals[58] = 1.0f;
245:                normals[59] = 0.0f;
246:
247:                // bottom face
248:                normals[60] = 0.0f;
249:                normals[61] = -1.0f;
250:                normals[62] = 0.0f;
251:                normals[63] = 0.0f;
252:                normals[64] = -1.0f;
253:                normals[65] = 0.0f;
254:                normals[66] = 0.0f;
255:                normals[67] = -1.0f;
256:                normals[68] = 0.0f;
257:                normals[69] = 0.0f;
258:                normals[70] = -1.0f;
259:                normals[71] = 0.0f;
260:
261:                impl.setNormals(0, normals);
262:            }
263:
264:            /**  Description of the Method */
265:            private void initTextureCoordinates() {
266:                float[] coords = new float[48];
267:                // front face
268:                int i = 0;
269:                coords[i++] = 0.0f;
270:                coords[i++] = 0.0f;
271:                coords[i++] = 1.0f;
272:                coords[i++] = 0.0f;
273:                coords[i++] = 1.0f;
274:                coords[i++] = 1.0f;
275:                coords[i++] = 0.0f;
276:                coords[i++] = 1.0f;
277:                // back face
278:                coords[i++] = 0.0f;
279:                coords[i++] = 0.0f;
280:                coords[i++] = 1.0f;
281:                coords[i++] = 0.0f;
282:                coords[i++] = 1.0f;
283:                coords[i++] = 1.0f;
284:                coords[i++] = 0.0f;
285:                coords[i++] = 1.0f;
286:                // right face
287:                coords[i++] = 0.0f;
288:                coords[i++] = 0.0f;
289:                coords[i++] = 1.0f;
290:                coords[i++] = 0.0f;
291:                coords[i++] = 1.0f;
292:                coords[i++] = 1.0f;
293:                coords[i++] = 0.0f;
294:                coords[i++] = 1.0f;
295:                // left face
296:                coords[i++] = 0.0f;
297:                coords[i++] = 0.0f;
298:                coords[i++] = 1.0f;
299:                coords[i++] = 0.0f;
300:                coords[i++] = 1.0f;
301:                coords[i++] = 1.0f;
302:                coords[i++] = 0.0f;
303:                coords[i++] = 1.0f;
304:                // top face
305:                coords[i++] = 0.0f;
306:                coords[i++] = 0.0f;
307:                coords[i++] = 1.0f;
308:                coords[i++] = 0.0f;
309:                coords[i++] = 1.0f;
310:                coords[i++] = 1.0f;
311:                coords[i++] = 0.0f;
312:                coords[i++] = 1.0f;
313:                // bottom face
314:                coords[i++] = 0.0f;
315:                coords[i++] = 0.0f;
316:                coords[i++] = 1.0f;
317:                coords[i++] = 0.0f;
318:                coords[i++] = 1.0f;
319:                coords[i++] = 1.0f;
320:                coords[i++] = 0.0f;
321:                coords[i++] = 1.0f;
322:
323:                impl.setTextureCoordinates(0, 0, coords);
324:            }
325:
326:            /**  Description of the Method */
327:            void initImpl() {
328:                impl = new javax.media.j3d.QuadArray(
329:                        24,
330:                        javax.media.j3d.QuadArray.COORDINATES
331:                                | javax.media.j3d.QuadArray.TEXTURE_COORDINATE_2
332:                                | javax.media.j3d.QuadArray.NORMALS);
333:                updatePoints();
334:                initNormals();
335:                initTextureCoordinates();
336:                implReady = true;
337:            }
338:
339:            /**
340:             *  Description of the Method
341:             *
342:             *@param  eventInName Description of the Parameter
343:             *@param  time Description of the Parameter
344:             */
345:            public void notifyMethod(String eventInName, double time) {
346:                if (eventInName.equals("size")) {
347:                    System.out.println("Updating the points size = "
348:                            + size.value[0] + " " + size.value[1] + " "
349:                            + size.value[2]);
350:                    updatePoints();
351:                } else {
352:                    System.err
353:                            .println("Box.notifyMethod: unexpected eventInName: "
354:                                    + eventInName);
355:                }
356:            }
357:
358:            /**
359:             *  Gets the implGeom attribute of the Box object
360:             *
361:             *@return  The implGeom value
362:             */
363:            public javax.media.j3d.Geometry getImplGeom() {
364:                if (impl == null) {
365:                    throw new NullPointerException();
366:                }
367:                return impl;
368:            }
369:
370:            /**
371:             *  Gets the boundingBox attribute of the Box object
372:             *
373:             *@return  The boundingBox value
374:             */
375:            public BoundingBox getBoundingBox() {
376:                return bounds;
377:            }
378:
379:            /**
380:             *  Description of the Method
381:             *
382:             *@return  Description of the Return Value
383:             */
384:            public boolean haveTexture() {
385:                //return false;
386:                return true;
387:            }
388:
389:            /**
390:             *  Gets the numTris attribute of the Box object
391:             *
392:             *@return  The numTris value
393:             */
394:            public int getNumTris() {
395:                return 12;// 6 faces * 2 tris
396:            }
397:
398:            /**
399:             *  Description of the Method
400:             *
401:             *@return  Description of the Return Value
402:             */
403:            public Object clone() {
404:                return new Box(loader, (SFVec3f) size.clone());
405:            }
406:
407:            /**
408:             *  Gets the type attribute of the Box object
409:             *
410:             *@return  The type value
411:             */
412:            public String getType() {
413:                return "Box";
414:            }
415:
416:            /**  Description of the Method */
417:            void initFields() {
418:                size.init(this , FieldSpec, Field.EXPOSED_FIELD, "size");
419:            }
420:
421:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.