001: /*
002: * $RCSfile: PickBounds.java,v $
003: *
004: * Copyright 1998-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.5 $
028: * $Date: 2008/02/28 20:17:27 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import javax.vecmath.*;
035:
036: /**
037: * PickBounds is a finite pick shape defined with a Bounds object. It can
038: * be used as an argument to the picking methods in BranchGroup and Locale.
039: *
040: * @see BranchGroup#pickAll
041: * @see Locale#pickAll
042: */
043: public final class PickBounds extends PickShape {
044:
045: Bounds bounds;
046:
047: /**
048: * Constructs an empty PickBounds. The bounds object is set to null.
049: */
050: public PickBounds() {
051: bounds = null;
052: }
053:
054: /**
055: * Constructs a PickBounds from the specified bounds object.
056: * @param boundsObject the bounds of this PickBounds.
057: */
058: public PickBounds(Bounds boundsObject) {
059: bounds = boundsObject;
060: }
061:
062: /**
063: * Sets the bounds object of this PickBounds to the specified object.
064: * @param boundsObject the new bounds of this PickBounds.
065: */
066: public void set(Bounds boundsObject) {
067: bounds = boundsObject;
068: }
069:
070: /**
071: * Gets the bounds object from this PickBounds.
072: * @return the bounds.
073: */
074: public Bounds get() {
075: return bounds;
076: }
077:
078: /**
079: * Return true if shape intersect with bounds.
080: * The point of intersection is stored in pickPos.
081: */
082: final boolean intersect(Bounds bounds, Point4d pickPos) {
083: return bounds.intersect(this .bounds, pickPos);
084: }
085:
086: // Only use within J3D.
087: // Return a new PickBounds that is the transformed (t3d) of this pickBounds.
088: PickShape transform(Transform3D t3d) {
089: // If the bounds is a BoundingBox, then the transformed bounds will
090: // get bigger. So this is a potential bug, and we'll have to deal with
091: // if there is a complain.
092: Bounds newBds = (Bounds) bounds.clone();
093: newBds.transform(t3d);
094: PickBounds newPB = new PickBounds(newBds);
095:
096: return newPB;
097: }
098:
099: Point3d getStartPoint() {
100: return bounds.getCenter();
101: }
102:
103: int getPickType() {
104: return (bounds != null ? bounds.getPickType()
105: : PickShape.PICKUNKNOWN);
106: }
107: }
|