001: /*
002: * $RCSfile: Cylinder.java,v $
003: *
004: * @(#)Cylinder.java 1.23 98/11/05 20:34:22
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: 2006/03/28 14:58:09 $
034: * $State: Exp $
035: */
036: /*
037: *@Author: Rick Goldberg
038: *@Author: Doug Gehringer
039: *@Author: Nikolai V. Chr.
040: *
041: */
042: package org.jdesktop.j3d.loaders.vrml97.impl;
043:
044: import javax.media.j3d.BoundingBox;
045: import javax.vecmath.Point3d;
046:
047: /** Description of the Class */
048: public class Cylinder extends GroupGeom {
049:
050: // field
051: SFFloat radius;
052: SFFloat height;
053: SFBool side;
054: SFBool bottom;
055: SFBool top;
056:
057: BoundingBox bounds;
058:
059: /**
060: *Constructor for the Cylinder object
061: *
062: *@param loader Description of the Parameter
063: */
064: public Cylinder(Loader loader) {
065: super (loader);
066: radius = new SFFloat(1.0f);
067: height = new SFFloat(2.0f);
068: side = new SFBool(true);
069: bottom = new SFBool(true);
070: top = new SFBool(true);
071: initFields();
072: }
073:
074: /**
075: *Constructor for the Cylinder object
076: *
077: *@param loader Description of the Parameter
078: *@param radius Description of the Parameter
079: *@param height Description of the Parameter
080: *@param side Description of the Parameter
081: *@param bottom Description of the Parameter
082: *@param top Description of the Parameter
083: */
084: Cylinder(Loader loader, SFFloat radius, SFFloat height,
085: SFBool side, SFBool bottom, SFBool top) {
086: super (loader);
087: this .radius = radius;
088: this .height = height;
089: this .side = side;
090: this .bottom = bottom;
091: this .top = top;
092: initFields();
093: }
094:
095: /** Description of the Method */
096: void initFields() {
097: radius.init(this , FieldSpec, Field.FIELD, "radius");
098: height.init(this , FieldSpec, Field.FIELD, "height");
099: side.init(this , FieldSpec, Field.FIELD, "side");
100: bottom.init(this , FieldSpec, Field.FIELD, "bottom");
101: top.init(this , FieldSpec, Field.FIELD, "top");
102: }
103:
104: /**
105: * Description of the Method
106: *
107: *@param eventInName Description of the Parameter
108: *@param time Description of the Parameter
109: */
110: public void notifyMethod(String eventInName, double time) {
111: ;
112: }
113:
114: /**
115: * Description of the Method
116: *
117: *@return Description of the Return Value
118: */
119: public Object clone() {
120: return new Cylinder(loader, (SFFloat) radius.clone(),
121: (SFFloat) height.clone(), (SFBool) side.clone(),
122: (SFBool) bottom.clone(), (SFBool) top.clone());
123: }
124:
125: /** Description of the Method */
126: public void initImpl() {
127: ;
128: }
129:
130: /**
131: * Description of the Method
132: *
133: *@param ap Description of the Parameter
134: *@return Description of the Return Value
135: */
136: public javax.media.j3d.Group initGroupImpl(
137: javax.media.j3d.Appearance ap) {
138:
139: // System.out.println("r and h"+radius.value+ " " + height.value);
140: implGroup = new com.sun.j3d.utils.geometry.Cylinder(
141: radius.value,
142: height.value,
143: com.sun.j3d.utils.geometry.Cylinder.GENERATE_NORMALS
144: | com.sun.j3d.utils.geometry.Cylinder.GENERATE_TEXTURE_COORDS,
145: 20, 2, ap);
146: ((javax.media.j3d.Node) implGroup)
147: .clearCapability(javax.media.j3d.Node.ENABLE_PICK_REPORTING);
148:
149: // The util constructs a group with the side, bottom and top as
150: // children. Handle removing the elements from the end of the
151: // group to the beginning
152: if (loader.debug) {
153: System.out.println("Cylinder group before edit: ");
154: loader.treePrinter.print(implGroup);
155: }
156: if (!bottom.value) {
157: if (loader.debug) {
158: System.out.println("no bottom");
159: }
160: ((javax.media.j3d.Group) implGroup)
161: .removeChild(com.sun.j3d.utils.geometry.Cylinder.BOTTOM);
162: }
163: if (!top.value) {
164: if (loader.debug) {
165: System.out.println("no top");
166: }
167: ((javax.media.j3d.Group) implGroup)
168: .removeChild(com.sun.j3d.utils.geometry.Cylinder.TOP);
169: }
170: if (!side.value) {
171: if (loader.debug) {
172: System.out.println("no side");
173: }
174: ((javax.media.j3d.Group) implGroup)
175: .removeChild(com.sun.j3d.utils.geometry.Cylinder.BODY);
176: }
177: if (loader.debug) {
178: System.out.println("Cylinder group after edit: ");
179: loader.treePrinter.print(implGroup);
180: }
181:
182: bounds = new BoundingBox(new Point3d(-radius.value,
183: -height.value / 2.0, -radius.value), new Point3d(
184: radius.value, height.value / 2.0, radius.value));
185:
186: return implGroup;
187: }
188:
189: /**
190: * Gets the boundingBox attribute of the Cylinder object
191: *
192: *@return The boundingBox value
193: */
194: public BoundingBox getBoundingBox() {
195: return bounds;
196: }
197:
198: /**
199: * Gets the implGeom attribute of the Cylinder object
200: *
201: *@return The implGeom value
202: */
203: public javax.media.j3d.Geometry getImplGeom() {
204: // should not be called
205: throw new NullPointerException();
206: }
207:
208: // this should perhaps be renamed haveTextureCoords()
209: /**
210: * Description of the Method
211: *
212: *@return Description of the Return Value
213: */
214: public boolean haveTexture() {
215: return true;
216: }
217:
218: /**
219: * Gets the type attribute of the Cylinder object
220: *
221: *@return The type value
222: */
223: public String getType() {
224: return "Cylinder";
225: }
226:
227: }
|