001: /*
002: * $RCSfile: PickSegment.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.5 $
028: * $Date: 2008/02/28 20:17:28 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import javax.vecmath.*;
035:
036: /**
037: * PickSegment is a line segment pick shape. 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 PickSegment extends PickShape {
044:
045: Point3d start;
046: Point3d end;
047:
048: /**
049: * Constructs an empty PickSegment.
050: * The start and end points of the line segment are
051: * initialized to (0,0,0).
052: */
053: public PickSegment() {
054: this .start = new Point3d();
055: this .end = new Point3d();
056: }
057:
058: /**
059: * Constructs a line segment pick shape from the specified
060: * parameters.
061: * @param start the start point of the line segment.
062: * @param end the end point of the line segment.
063: */
064: public PickSegment(Point3d start, Point3d end) {
065: this .start = new Point3d(start);
066: this .end = new Point3d(end);
067: }
068:
069: /**
070: * Sets the parameters of this PickSegment to the specified values.
071: * @param start the start point of the line segment.
072: * @param end the end point of the line segment.
073: */
074: public void set(Point3d start, Point3d end) {
075: this .start.x = start.x;
076: this .start.y = start.y;
077: this .start.z = start.z;
078: this .end.x = end.x;
079: this .end.y = end.y;
080: this .end.z = end.z;
081: }
082:
083: /**
084: * Gets the parameters from this PickSegment.
085: * @param start the Point3d object into which the start
086: * point will be copied.
087: * @param end the Point3d object into which the end point
088: * will be copied.
089: */
090: public void get(Point3d start, Point3d end) {
091: start.x = this .start.x;
092: start.y = this .start.y;
093: start.z = this .start.z;
094: end.x = this .end.x;
095: end.y = this .end.y;
096: end.z = this .end.z;
097: }
098:
099: /**
100: * Return true if shape intersect with bounds.
101: * The point of intersection is stored in pickPos.
102: */
103: final boolean intersect(Bounds bounds, Point4d pickPos) {
104: return bounds.intersect(start, end, pickPos);
105: }
106:
107: // Only use within J3D.
108: // Return a new PickSegment that is the transformed (t3d) of this pickSegment.
109: PickShape transform(Transform3D t3d) {
110: PickSegment newPS = new PickSegment(start, end);
111: t3d.transform(newPS.start);
112: t3d.transform(newPS.end);
113: return newPS;
114: }
115:
116: Point3d getStartPoint() {
117: return start;
118: }
119:
120: int getPickType() {
121: return PICKSEGMENT;
122: }
123: }
|