001: /*
002: * $RCSfile: BigCube.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:37 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.examples.four_by_four;
046:
047: import java.applet.Applet;
048: import java.awt.event.*;
049: import javax.media.j3d.*;
050: import javax.vecmath.*;
051:
052: /**
053: * Class BigCube
054: *
055: * Description: Creates the "big" cube used to mark the computer's
056: * position.
057: *
058: * Version: 1.0
059: */
060: public class BigCube extends Object {
061:
062: private Shape3D shape3D;
063:
064: private static final float[] verts = {
065: // Front Face
066: 5.0f, -5.0f, 5.0f, 5.0f, 5.0f, 5.0f, -5.0f,
067: 5.0f,
068: 5.0f,
069: -5.0f,
070: -5.0f,
071: 5.0f,
072: // Back Face
073: -5.0f, -5.0f, -5.0f, -5.0f, 5.0f, -5.0f, 5.0f, 5.0f,
074: -5.0f,
075: 5.0f,
076: -5.0f,
077: -5.0f,
078: // Right Face
079: 5.0f, -5.0f, -5.0f, 5.0f, 5.0f, -5.0f, 5.0f, 5.0f, 5.0f,
080: 5.0f,
081: -5.0f,
082: 5.0f,
083: // Left Face
084: -5.0f, -5.0f, 5.0f, -5.0f, 5.0f, 5.0f, -5.0f, 5.0f, -5.0f,
085: -5.0f, -5.0f,
086: -5.0f,
087: // Top Face
088: 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, -5.0f, -5.0f, 5.0f, -5.0f,
089: -5.0f, 5.0f, 5.0f,
090: // Bottom Face
091: -5.0f, -5.0f, 5.0f, -5.0f, -5.0f, -5.0f, 5.0f, -5.0f,
092: -5.0f, 5.0f, -5.0f, 5.0f, };
093:
094: private static final float[] normals = {
095: // Front Face
096: 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
097: 0.0f,
098: 1.0f,
099: 0.0f,
100: 0.0f,
101: 1.0f,
102: // Back Face
103: 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
104: -1.0f,
105: 0.0f,
106: 0.0f,
107: -1.0f,
108: // Right Face
109: 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
110: 1.0f,
111: 0.0f,
112: 0.0f,
113: // Left Face
114: -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
115: -1.0f, 0.0f,
116: 0.0f,
117: // Top Face
118: 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
119: 1.0f, 0.0f,
120: // Bottom Face
121: 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
122: 0.0f, -1.0f, 0.0f, };
123:
124: public BigCube(Appearance appearance) {
125:
126: QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES
127: | QuadArray.NORMALS);
128: quadArray.setCoordinates(0, verts);
129: quadArray.setNormals(0, normals);
130:
131: shape3D = new Shape3D(quadArray, appearance);
132: shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
133: shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
134: shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
135: shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
136: }
137:
138: public BigCube(Appearance appearance, float size) {
139:
140: QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES
141: | QuadArray.NORMALS);
142:
143: for (int i = 0; i < 72; i++)
144: verts[i] *= size;
145:
146: quadArray.setCoordinates(0, verts);
147: quadArray.setNormals(0, normals);
148:
149: shape3D = new Shape3D(quadArray, appearance);
150: shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
151: shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
152: shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
153: shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
154: }
155:
156: public Shape3D getChild() {
157: return shape3D;
158: }
159: }
|