001: /*
002: * $RCSfile: BoundingLeaf.java,v $
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:20 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import javax.vecmath.*;
035:
036: /**
037: * The BoundingLeaf node defines a bounding region object that can be
038: * referenced by other nodes to define a region of influence
039: * (Fog and Light nodes), an application region (Background, Clip,
040: * and Soundscape nodes), or a scheduling region (Sound and
041: * Behavior nodes). The bounding region is defined in the local
042: * coordinate system of the BoundingLeaf node. A reference to a
043: * BoundingLeaf node can be used in place
044: * of a locally defined bounds object for any of the aforementioned regions.
045: * <P>
046: * This allows an application to specify a bounding region in one coordinate system
047: * (the local coordinate system of the BoundingLeaf node) other than the local
048: * coordinate system of the node that references the bounds. For an example of how
049: * this might be used, consider a closed room with a number of track lights. Each
050: * light can move independent of the other lights and, as such, needs its own local
051: * coordinate system. However, the bounding volume is used by all the lights in the
052: * boundary of the room, which doesn't move when the lights move. In this example,
053: * the BoundingLeaf node allows the bounding region to be defined in the local
054: * coordinate system of the room, rather than in the local coordinate system of a
055: * particular light. All lights can then share this single bounding volume.
056: */
057: public class BoundingLeaf extends Leaf {
058: /**
059: * Specifies that this BoundingLeaf node allows read access to its
060: * bounding region object.
061: */
062: public static final int ALLOW_REGION_READ = CapabilityBits.BOUNDING_LEAF_ALLOW_REGION_READ;
063:
064: /**
065: * Specifies that this BoundingLeaf node allows write access to its
066: * bounding region object.
067: */
068: public static final int ALLOW_REGION_WRITE = CapabilityBits.BOUNDING_LEAF_ALLOW_REGION_WRITE;
069:
070: // Array for setting default read capabilities
071: private static final int[] readCapabilities = { ALLOW_REGION_READ };
072:
073: /**
074: * Constructs a BoundingLeaf node with a null (empty) bounding region.
075: */
076: public BoundingLeaf() {
077: // set default read capabilities
078: setDefaultReadCapabilities(readCapabilities);
079:
080: ((BoundingLeafRetained) this .retained).createBoundingLeaf();
081: }
082:
083: /**
084: * Constructs a BoundingLeaf node with the specified bounding region.
085: * @param region the bounding region of this leaf node
086: */
087: public BoundingLeaf(Bounds region) {
088: // set default read capabilities
089: setDefaultReadCapabilities(readCapabilities);
090:
091: ((BoundingLeafRetained) this .retained).createBoundingLeaf();
092: ((BoundingLeafRetained) this .retained).initRegion(region);
093: }
094:
095: /**
096: * Sets this BoundingLeaf node's bounding region.
097: * @param region the bounding region of this leaf node
098: * @exception CapabilityNotSetException if appropriate capability is
099: * not set and this object is part of live or compiled scene graph
100: */
101: public void setRegion(Bounds region) {
102: if (isLiveOrCompiled())
103: if (!this .getCapability(ALLOW_REGION_WRITE))
104: throw new CapabilityNotSetException(J3dI18N
105: .getString("BoundingLeaf0"));
106:
107: if (isLive())
108: ((BoundingLeafRetained) this .retained).setRegion(region);
109: else
110: ((BoundingLeafRetained) this .retained).initRegion(region);
111: }
112:
113: /**
114: * Retrieves this BoundingLeaf's bounding region.
115: * @return the bounding region of this leaf node
116: * @exception CapabilityNotSetException if appropriate capability is
117: * not set and this object is part of live or compiled scene graph
118: */
119: public Bounds getRegion() {
120: if (isLiveOrCompiled())
121: if (!this .getCapability(ALLOW_REGION_READ))
122: throw new CapabilityNotSetException(J3dI18N
123: .getString("BoundingLeaf1"));
124:
125: return ((BoundingLeafRetained) this .retained).getRegion();
126: }
127:
128: /**
129: * Creates the BoundingLeafRetained object that this
130: * BoundingLeaf object will point to.
131: */
132: void createRetained() {
133: this .retained = new BoundingLeafRetained();
134: this .retained.setSource(this );
135: }
136:
137: /**
138: * Used to create a new instance of the node. This routine is called
139: * by <code>cloneTree</code> to duplicate the current node.
140: * @param forceDuplicate when set to <code>true</code>, causes the
141: * <code>duplicateOnCloneTree</code> flag to be ignored. When
142: * <code>false</code>, the value of each node's
143: * <code>duplicateOnCloneTree</code> variable determines whether
144: * NodeComponent data is duplicated or copied.
145: *
146: * @see Node#cloneTree
147: * @see Node#cloneNode
148: * @see Node#duplicateNode
149: * @see NodeComponent#setDuplicateOnCloneTree
150: */
151: public Node cloneNode(boolean forceDuplicate) {
152: BoundingLeaf bl = new BoundingLeaf();
153: bl.duplicateNode(this , forceDuplicate);
154: return bl;
155: }
156:
157: /**
158: * Copies all BoundingLeaf information from
159: * <code>originalNode</code> into
160: * the current node. This method is called from the
161: * <code>cloneNode</code> method which is, in turn, called by the
162: * <code>cloneTree</code> method.<P>
163: *
164: * @param originalNode the original node to duplicate.
165: * @param forceDuplicate when set to <code>true</code>, causes the
166: * <code>duplicateOnCloneTree</code> flag to be ignored. When
167: * <code>false</code>, the value of each node's
168: * <code>duplicateOnCloneTree</code> variable determines whether
169: * NodeComponent data is duplicated or copied.
170: *
171: * @exception RestrictedAccessException if this object is part of a live
172: * or compiled scenegraph.
173: *
174: * @see Node#duplicateNode
175: * @see Node#cloneTree
176: * @see NodeComponent#setDuplicateOnCloneTree
177: */
178: void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
179: super .duplicateAttributes(originalNode, forceDuplicate);
180:
181: ((BoundingLeafRetained) retained)
182: .initRegion(((BoundingLeafRetained) originalNode.retained)
183: .getRegion());
184: }
185:
186: }
|