001: /*
002: * $RCSfile: Sphere.java,v $
003: *
004: * @(#)Sphere.java 1.24 98/11/05 20:35: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.2 $
033: * $Date: 2005/02/03 23:07:02 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043: import javax.media.j3d.BoundingBox;
044: import javax.vecmath.Point3d;
045:
046: // only a groupgeom because of the util orientation
047: /** Description of the Class */
048: public class Sphere extends GroupGeom {
049:
050: // field
051: SFFloat radius;
052:
053: BoundingBox bounds;
054:
055: /**
056: *Constructor for the Sphere object
057: *
058: *@param loader Description of the Parameter
059: */
060: public Sphere(Loader loader) {
061: super (loader);
062: radius = new SFFloat(1.0f);
063: initFields();
064: }
065:
066: /**
067: *Constructor for the Sphere object
068: *
069: *@param loader Description of the Parameter
070: *@param radius Description of the Parameter
071: */
072: Sphere(Loader loader, SFFloat radius) {
073: super (loader);
074: this .radius = radius;
075: initFields();
076: }
077:
078: /** Description of the Method */
079: public void initImpl() {
080: ;
081: }
082:
083: /**
084: * Description of the Method
085: *
086: *@param ap Description of the Parameter
087: *@return Description of the Return Value
088: */
089: public javax.media.j3d.Group initGroupImpl(
090: javax.media.j3d.Appearance ap) {
091: if (ap == null) {
092: ap = new javax.media.j3d.Appearance();
093: }
094:
095: implGroup = new com.sun.j3d.utils.geometry.Sphere(
096: radius.value,
097: com.sun.j3d.utils.geometry.Sphere.GENERATE_NORMALS
098: | com.sun.j3d.utils.geometry.Sphere.GEOMETRY_NOT_SHARED
099: | com.sun.j3d.utils.geometry.Sphere.GENERATE_TEXTURE_COORDS,
100: 20, ap);
101: ((com.sun.j3d.utils.geometry.Sphere) implGroup).getShape()
102: .clearCapability(
103: javax.media.j3d.Node.ENABLE_PICK_REPORTING);
104: implGroup.setCapability(javax.media.j3d.Node.ALLOW_BOUNDS_READ);
105:
106: //((com.sun.j3d.utils.geometry.Sphere)implGroup).getShape().setPickable(false);
107: bounds = new BoundingBox(new Point3d(-radius.value,
108: -radius.value, -radius.value), new Point3d(
109: radius.value, radius.value, radius.value));
110: return implGroup;
111: }
112:
113: /**
114: * Gets the type attribute of the Sphere object
115: *
116: *@return The type value
117: */
118: public String getType() {
119: return "Sphere";
120: }
121:
122: /**
123: * Description of the Method
124: *
125: *@param eventInName Description of the Parameter
126: *@param time Description of the Parameter
127: */
128: public void notifyMethod(String eventInName, double time) {
129: if (loader.debug) {
130: System.out
131: .println("Sphere.notifyMethod: unexpected eventInName"
132: + eventInName);
133: }
134: }
135:
136: /** Description of the Method */
137: void initFields() {
138: radius.init(this , FieldSpec, Field.FIELD, "radius");
139: }
140:
141: /**
142: * Description of the Method
143: *
144: *@return Description of the Return Value
145: */
146: public Object clone() {
147: return new Sphere(loader, (SFFloat) radius.clone());
148: }
149:
150: /**
151: * Gets the implGeom attribute of the Sphere object
152: *
153: *@return The implGeom value
154: */
155: public javax.media.j3d.Geometry getImplGeom() {
156: // should not be called
157: throw new NullPointerException();
158: }
159:
160: /**
161: * Description of the Method
162: *
163: *@param impl Description of the Parameter
164: */
165: void updateParent(javax.media.j3d.Node impl) {
166: super .updateParent(impl);
167: }
168:
169: /**
170: * Description of the Method
171: *
172: *@return Description of the Return Value
173: */
174: public boolean haveTexture() {
175: return false;
176: }
177:
178: /**
179: * Gets the boundingBox attribute of the Sphere object
180: *
181: *@return The boundingBox value
182: */
183: public BoundingBox getBoundingBox() {
184: return bounds;
185: }
186:
187: }
|