summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin Rushforth <[email protected]>2005-10-17 23:08:36 +0000
committerKevin Rushforth <[email protected]>2005-10-17 23:08:36 +0000
commitf844e28477dc3338d1e607e0afeff1461842b298 (patch)
tree228d5904b3fd4e8d2df1a7a80a77d8e777bf2602 /src
parent73cf83c25f0b48f5dcd6aae86ba8ad1c49395d83 (diff)
Merged changes from dev-1_4 branch into the main trunk.
NOTE: all 1.4 development will now proceed on the main trunk. The dev-1_4 branch is closed. git-svn-id: https://svn.java.net/svn/j3d-core-utils~svn/trunk@81 9497e636-51bd-65ba-982d-a4982e1767a5
Diffstat (limited to 'src')
-rw-r--r--src/classes/ToolsVersion2
-rw-r--r--src/classes/share/com/sun/j3d/utils/behaviors/vp/OrbitBehavior.java203
-rw-r--r--src/classes/share/com/sun/j3d/utils/behaviors/vp/ViewPlatformAWTBehavior.java29
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/PickCanvas.java249
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/PickIntersection.java417
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/PickTool.java514
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickMouseBehavior.java179
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickRotateBehavior.java174
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickTranslateBehavior.java163
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickZoomBehavior.java162
-rw-r--r--src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickingCallback.java76
-rw-r--r--src/classes/share/com/sun/j3d/utils/picking/PickResult.java52
-rw-r--r--src/classes/share/com/sun/j3d/utils/picking/PickTool.java26
-rw-r--r--src/classes/share/com/sun/j3d/utils/scenegraph/transparency/SimpleDistanceComparator.java89
-rw-r--r--src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java98
-rw-r--r--src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortGeom.java90
-rw-r--r--src/classes/share/com/sun/j3d/utils/shader/StringIO.java158
-rw-r--r--src/classes/share/com/sun/j3d/utils/universe/SimpleUniverse.java16
18 files changed, 2577 insertions, 120 deletions
diff --git a/src/classes/ToolsVersion b/src/classes/ToolsVersion
index 7e59062..d6e665f 100644
--- a/src/classes/ToolsVersion
+++ b/src/classes/ToolsVersion
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Specification-Title:
-Specification-Version: 1.3
+Specification-Version: 1.4
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: Java 3D Utilities Runtime Environment
Implementation-Version: @VERSION_BASE@
diff --git a/src/classes/share/com/sun/j3d/utils/behaviors/vp/OrbitBehavior.java b/src/classes/share/com/sun/j3d/utils/behaviors/vp/OrbitBehavior.java
index 70a79e2..09c34db 100644
--- a/src/classes/share/com/sun/j3d/utils/behaviors/vp/OrbitBehavior.java
+++ b/src/classes/share/com/sun/j3d/utils/behaviors/vp/OrbitBehavior.java
@@ -70,7 +70,7 @@ import com.sun.j3d.internal.J3dUtilsI18N;
/**
* Moves the View around a point of interest when the mouse is dragged with
* a mouse button pressed. Includes rotation, zoom, and translation
- * actions.
+ * actions. Zooming can also be obtained by using mouse wheel.
* <p>
* This behavior must be added to the ViewingPlatform
* using the <code>ViewingPlatform.setViewPlatformBehavior</code> method.
@@ -178,6 +178,11 @@ public class OrbitBehavior extends ViewPlatformAWTBehavior {
private int leftButton = ROTATE;
private int rightButton = TRANSLATE;
private int middleButton = ZOOM;
+
+ // the factor to be applied to wheel zooming so that it does not
+ // look much different with mouse movement zooming.
+ // This is a totally subjective factor.
+ private float wheelZoomFactor = 50.0f;
/**
* Constructor flag to reverse the rotate behavior
@@ -265,7 +270,7 @@ public class OrbitBehavior extends ViewPlatformAWTBehavior {
* @since Java 3D 1.3
*/
public OrbitBehavior() {
- super(MOUSE_LISTENER | MOUSE_MOTION_LISTENER);
+ super(MOUSE_LISTENER | MOUSE_MOTION_LISTENER | MOUSE_WHEEL_LISTENER);
}
/**
@@ -284,7 +289,7 @@ public class OrbitBehavior extends ViewPlatformAWTBehavior {
* @param flags The option flags
*/
public OrbitBehavior(Canvas3D c, int flags) {
- super(c, MOUSE_LISTENER | MOUSE_MOTION_LISTENER | flags );
+ super(c, MOUSE_LISTENER | MOUSE_MOTION_LISTENER | MOUSE_WHEEL_LISTENER | flags );
if ((flags & DISABLE_ROTATE) != 0) rotateEnabled = false;
if ((flags & DISABLE_ZOOM) != 0) zoomEnabled = false;
@@ -339,67 +344,96 @@ public class OrbitBehavior extends ViewPlatformAWTBehavior {
}
// zoom
else if (zoom(evt)) {
- if (proportionalZoom) {
- if (reverseZoom) {
- if ((distanceFromCenter -
- (zoomMul*ychange*distanceFromCenter/100.0)) >
- minRadius) {
- distanceFromCenter -= (zoomMul*ychange*
- distanceFromCenter/100.0);
- }
- else {
- distanceFromCenter = minRadius;
- }
+ doZoomOperations( ychange );
+ }
+ mouseX = evt.getX();
+ mouseY = evt.getY();
+ motion = true;
+ } else if (evt.getID()==MouseEvent.MOUSE_RELEASED ) {
+ } else if (evt.getID()==MouseEvent.MOUSE_WHEEL ) {
+ if (zoom(evt)) {
+ // if zooming is done through mouse wheel,
+ // the amount of increments the wheel changed,
+ // multiplied with wheelZoomFactor is used,
+ // so that zooming speed looks natural compared to mouse movement zoom.
+ if ( evt instanceof java.awt.event.MouseWheelEvent){
+ // I/O differenciation is made between
+ // java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL or
+ // java.awt.event.MouseWheelEvent.WHEEL_BLOCK_SCROLL so
+ // that behavior remains stable and not dependent on OS settings.
+ // If getWheelRotation() was used for calculating the zoom,
+ // the zooming speed could act differently on different platforms,
+ // if, for example, the user sets his mouse wheel to jump 10 lines
+ // or a block.
+ int zoom =
+ ((int)(((java.awt.event.MouseWheelEvent)evt).getWheelRotation()
+ * wheelZoomFactor));
+ doZoomOperations( zoom );
+ motion = true;
+ }
+ }
+ }
+ }
+
+ /*extraction of the zoom algorithms so that there is no code duplication or source 'uglyfication'.
+ */
+ private void doZoomOperations( int ychange ) {
+ if (proportionalZoom) {
+ if (reverseZoom) {
+ if ((distanceFromCenter -
+ (zoomMul*ychange*distanceFromCenter/100.0)) >
+ minRadius) {
+ distanceFromCenter -= (zoomMul*ychange*
+ distanceFromCenter/100.0);
+ }
+ else {
+ distanceFromCenter = minRadius;
+ }
+ }
+ else {
+ if ((distanceFromCenter +
+ (zoomMul*ychange*distanceFromCenter/100.0))
+ > minRadius) {
+ distanceFromCenter += (zoomMul*ychange*
+ distanceFromCenter/100.0);
+ }
+ else {
+ distanceFromCenter = minRadius;
+ }
+ }
+ }
+ else {
+ if (stopZoom) {
+ if (reverseZoom) {
+ if ((distanceFromCenter - ychange*zoomMul) > minRadius) {
+ distanceFromCenter -= ychange*zoomMul;
}
else {
- if ((distanceFromCenter +
- (zoomMul*ychange*distanceFromCenter/100.0))
- > minRadius) {
- distanceFromCenter += (zoomMul*ychange*
- distanceFromCenter/100.0);
- }
- else {
- distanceFromCenter = minRadius;
- }
+ distanceFromCenter = minRadius;
}
}
else {
- if (stopZoom) {
- if (reverseZoom) {
- if ((distanceFromCenter - ychange*zoomMul) > minRadius) {
- distanceFromCenter -= ychange*zoomMul;
- }
- else {
- distanceFromCenter = minRadius;
- }
- }
- else {
- if ((distanceFromCenter + ychange*zoomMul) > minRadius) {
- distanceFromCenter += ychange * zoomMul;
- }
- else {
- distanceFromCenter = minRadius;
- }
- }
+ if ((distanceFromCenter + ychange*zoomMul) > minRadius) {
+ distanceFromCenter += ychange * zoomMul;
}
else {
- if (reverseZoom) {
- distanceFromCenter -= ychange*zoomMul;
- }
- else {
- distanceFromCenter += ychange*zoomMul;
- }
+ distanceFromCenter = minRadius;
}
}
}
- mouseX = evt.getX();
- mouseY = evt.getY();
- motion = true;
- } else if (evt.getID()==MouseEvent.MOUSE_RELEASED ) {
- }
-
+ else {
+ if (reverseZoom) {
+ distanceFromCenter -= ychange*zoomMul;
+ }
+ else {
+ distanceFromCenter += ychange*zoomMul;
+ }
+ }
+ }
}
-
+
+
+
/**
* Sets the ViewingPlatform for this behavior. This method is
* called by the ViewingPlatform.
@@ -447,46 +481,46 @@ public class OrbitBehavior extends ViewPlatformAWTBehavior {
}
protected synchronized void integrateTransforms() {
- // Check if the transform has been changed by another
- // behavior
- targetTG.getTransform(currentXfm) ;
- if (! targetTransform.equals(currentXfm))
- resetView() ;
+ // Check if the transform has been changed by another
+ // behavior
+ targetTG.getTransform(currentXfm) ;
+ if (! targetTransform.equals(currentXfm))
+ resetView() ;
- longditudeTransform.rotY( longditude );
- latitudeTransform.rotX( latitude );
- rotateTransform.mul(rotateTransform, latitudeTransform);
- rotateTransform.mul(rotateTransform, longditudeTransform);
+ longditudeTransform.rotY( longditude );
+ latitudeTransform.rotX( latitude );
+ rotateTransform.mul(rotateTransform, latitudeTransform);
+ rotateTransform.mul(rotateTransform, longditudeTransform);
- distanceVector.z = distanceFromCenter - startDistanceFromCenter;
+ distanceVector.z = distanceFromCenter - startDistanceFromCenter;
- temp1.set(distanceVector);
- temp1.mul(rotateTransform, temp1);
+ temp1.set(distanceVector);
+ temp1.mul(rotateTransform, temp1);
- // want to look at rotationCenter
- transVector.x = rotationCenter.x + xtrans;
- transVector.y = rotationCenter.y + ytrans;
- transVector.z = rotationCenter.z + ztrans;
+ // want to look at rotationCenter
+ transVector.x = rotationCenter.x + xtrans;
+ transVector.y = rotationCenter.y + ytrans;
+ transVector.z = rotationCenter.z + ztrans;
- translation.set(transVector);
- targetTransform.mul(temp1, translation);
+ translation.set(transVector);
+ targetTransform.mul(temp1, translation);
- // handle rotationCenter
- temp1.set(centerVector);
- temp1.mul(targetTransform);
+ // handle rotationCenter
+ temp1.set(centerVector);
+ temp1.mul(targetTransform);
- invertCenterVector.x = -centerVector.x;
- invertCenterVector.y = -centerVector.y;
- invertCenterVector.z = -centerVector.z;
+ invertCenterVector.x = -centerVector.x;
+ invertCenterVector.y = -centerVector.y;
+ invertCenterVector.z = -centerVector.z;
- temp2.set(invertCenterVector);
- targetTransform.mul(temp1, temp2);
+ temp2.set(invertCenterVector);
+ targetTransform.mul(temp1, temp2);
- targetTG.setTransform(targetTransform);
+ targetTG.setTransform(targetTransform);
- // reset yaw and pitch angles
- longditude = 0.0;
- latitude = 0.0;
+ // reset yaw and pitch angles
+ longditude = 0.0;
+ latitude = 0.0;
}
/**
@@ -877,6 +911,9 @@ public class OrbitBehavior extends ViewPlatformAWTBehavior {
boolean zoom(MouseEvent evt) {
if (zoomEnabled) {
+ if (evt instanceof java.awt.event.MouseWheelEvent) {
+ return true;
+ }
if ((leftButton == ZOOM) &&
(!evt.isAltDown() && !evt.isMetaDown())) {
return true;
diff --git a/src/classes/share/com/sun/j3d/utils/behaviors/vp/ViewPlatformAWTBehavior.java b/src/classes/share/com/sun/j3d/utils/behaviors/vp/ViewPlatformAWTBehavior.java
index 535f52b..4c4d776 100644
--- a/src/classes/share/com/sun/j3d/utils/behaviors/vp/ViewPlatformAWTBehavior.java
+++ b/src/classes/share/com/sun/j3d/utils/behaviors/vp/ViewPlatformAWTBehavior.java
@@ -47,6 +47,7 @@ package com.sun.j3d.utils.behaviors.vp;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
+import java.awt.event.MouseWheelListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
@@ -82,7 +83,7 @@ import com.sun.j3d.utils.universe.*;
* @since Java 3D 1.2.1
*/
public abstract class ViewPlatformAWTBehavior extends ViewPlatformBehavior
-implements MouseListener, MouseMotionListener, KeyListener {
+implements MouseListener, MouseMotionListener, KeyListener, MouseWheelListener {
private final static boolean DEBUG = false;
@@ -125,7 +126,12 @@ implements MouseListener, MouseMotionListener, KeyListener {
* Flag indicating Behavior should listen for Key Events
*/
public final static int KEY_LISTENER = 0x04;
-
+
+ /**
+ * Flag indicating Behavior should listen for MouseWheel Events
+ */
+ public final static int MOUSE_WHEEL_LISTENER = 0x08;
+
/**
* The Canvas3Ds from which this Behavior gets AWT events
*/
@@ -151,7 +157,7 @@ implements MouseListener, MouseMotionListener, KeyListener {
* ConfiguredUniverse.
*
* @param listenerFlags Indicates which listener should be registered,
- * one or more of MOUSE_LISTENER, MOUSE_MOTION_LISTENER, KEY_LISTENER
+ * one or more of MOUSE_LISTENER, MOUSE_MOTION_LISTENER, KEY_LISTENER, MOUSE_WHEEL_LISTENER
* @since Java 3D 1.3
*/
protected ViewPlatformAWTBehavior(int listenerFlags) {
@@ -165,7 +171,7 @@ implements MouseListener, MouseMotionListener, KeyListener {
* @param c The Canvas3D on which to listen for events. If this is null a
* NullPointerException will be thrown.
* @param listenerFlags Indicates which listener should be registered,
- * one or more of MOUSE_LISTENER, MOUSE_MOTION_LISTENER, KEY_LISTENER
+ * one or more of MOUSE_LISTENER, MOUSE_MOTION_LISTENER, KEY_LISTENER, MOUSE_WHEEL_LISTENER
*/
public ViewPlatformAWTBehavior(Canvas3D c, int listenerFlags ) {
super();
@@ -181,7 +187,7 @@ implements MouseListener, MouseMotionListener, KeyListener {
* Sets listener flags for this behavior.
*
* @param listenerFlags Indicates which listener should be registered,
- * one or more of MOUSE_LISTENER, MOUSE_MOTION_LISTENER, KEY_LISTENER
+ * one or more of MOUSE_LISTENER, MOUSE_MOTION_LISTENER, KEY_LISTENER, MOUSE_WHEEL_LISTENER
* @since Java 3D 1.3
*/
protected void setListenerFlags(int listenerFlags) {
@@ -263,6 +269,10 @@ implements MouseListener, MouseMotionListener, KeyListener {
for(int i=0; i<canvases.length; i++)
canvases[i].addMouseMotionListener(this);
+ if ( (listenerFlags & MOUSE_WHEEL_LISTENER)!=0)
+ for(int i=0; i<canvases.length; i++)
+ canvases[i].addMouseWheelListener(this);
+
if ( (listenerFlags & KEY_LISTENER)!=0)
for(int i=0; i<canvases.length; i++)
canvases[i].addKeyListener(this);
@@ -275,6 +285,10 @@ implements MouseListener, MouseMotionListener, KeyListener {
for(int i=0; i<canvases.length; i++)
canvases[i].removeMouseMotionListener(this);
+ if ( (listenerFlags & MOUSE_WHEEL_LISTENER)!=0)
+ for(int i=0; i<canvases.length; i++)
+ canvases[i].removeMouseWheelListener(this);
+
if ( (listenerFlags & KEY_LISTENER)!=0)
for(int i=0; i<canvases.length; i++)
canvases[i].removeKeyListener(this);
@@ -395,6 +409,9 @@ implements MouseListener, MouseMotionListener, KeyListener {
public void keyTyped(final java.awt.event.KeyEvent e) {
queueAWTEvent( e );
}
-
+
+ public void mouseWheelMoved( final java.awt.event.MouseWheelEvent e) {
+ queueAWTEvent( e );
+ }
}
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/PickCanvas.java b/src/classes/share/com/sun/j3d/utils/pickfast/PickCanvas.java
new file mode 100644
index 0000000..c388353
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/PickCanvas.java
@@ -0,0 +1,249 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast;
+
+import java.awt.event.*;
+import javax.vecmath.*;
+import javax.media.j3d.*;
+import com.sun.j3d.utils.geometry.*; // Cone, Cylinder
+
+/**
+ * A subclass of PickTool, simplifies picking using mouse events from a canvas.
+ * This class allows picking using canvas x,y locations by generating the
+ * appropriate pick shape.
+ * <p>
+ * The pick tolerance specifies the distance from the
+ * pick center to include in the pick shape. A tolerance of 0.0 may speedup
+ * picking slightly, but also make it very difficult to pick points and lines.
+ * <p>
+ * The pick canvas can be used to make a series of picks. For example, to
+ * initialize the pick canvas:
+ * <blockquote><pre>
+ * PickCanvas pickCanvas = new PickCanvas(canvas, scene);
+ * pickCanvas.setMode(PickTool.PICK_GEOMETRY);
+ * pickCanvas.setFlags(PickInfo.NODE | PickInfo.CLOSEST_INTERSECTION_POINT);
+ * pickCanvas.setTolerance(4.0f);
+ * </pre></blockquote>
+ * <p>
+ * Then for each mouse event:
+ * <blockquote><pre>
+ * pickCanvas.setShapeLocation(mouseEvent);
+ * PickInfo[] pickInfos = pickCanvas.pickAll();
+ * </pre></blockquote>
+ * <p>
+ * NOTE: For the pickAllSorted or pickClosest methods, the picks will be sorted
+ * by the distance from the ViewPlatform to the intersection point.
+ * @see PickTool
+ */
+public class PickCanvas extends PickTool {
+
+ /* OPEN ISSUES:
+ -- Should restrict the pick shape to the front/back clip plane
+ */
+
+
+ /** The canvas we are picking into */
+ Canvas3D canvas;
+
+ /* the pick tolerance, default to 2.0 */
+ float tolerance = 2.0f;
+ int save_xpos;
+ int save_ypos;
+
+ /** Constructor with Canvas3D for mouse events and BranchGroup to be picked.
+ */
+ public PickCanvas (Canvas3D c, BranchGroup b) {
+ super (b);
+ canvas = c;
+ }
+
+ /** Constructor with Canvas3D for mouse events and Locale to be picked.
+ */
+ public PickCanvas (Canvas3D c, Locale l) {
+ super (l);
+ canvas = c;
+ }
+
+ /** Inquire the canvas to be used for picking operations.
+ @return the canvas.
+ */
+ public Canvas3D getCanvas() {
+ return canvas;
+ }
+
+ /** Set the picking tolerance. Objects within this distance
+ * (in pixels)
+ * to the mouse x,y location will be picked. The default tolerance is 2.0.
+ * @param t The tolerance
+ * @exception IllegalArgumentException if the tolerance is less than 0.
+ */
+ public void setTolerance(float t) {
+ if (t < 0.0f) {
+ throw new IllegalArgumentException();
+ }
+ tolerance = t;
+
+ if ((pickShape != null) && (!userDefineShape)) {
+ // reset pickShape
+ pickShape = null;
+ setShapeLocation(save_xpos, save_ypos);
+ }
+ }
+
+ /** Get the pick tolerance.
+ */
+ public float getTolerance() {
+ return tolerance;
+ }
+
+ /** Set the pick location. Defines the location on the canvas where the
+ pick is to be performed.
+ @param mevent The MouseEvent for the picking point
+ */
+ public void setShapeLocation(MouseEvent mevent) {
+ setShapeLocation(mevent.getX(), mevent.getY());
+ }
+ /** Set the pick location. Defines the location on the canvas where the
+ pick is to be performed (upper left corner of canvas is 0,0).
+ @param xpos the X position of the picking point
+ @param ypos the Y position of the picking point
+ */
+ public void setShapeLocation (int xpos, int ypos) {
+ Transform3D motion = new Transform3D();
+ Point3d eyePosn = new Point3d();
+ Point3d mousePosn = new Point3d();
+ Vector3d mouseVec = new Vector3d();
+ boolean isParallel = false;
+ double radius = 0.0;
+ double spreadAngle = 0.0;
+
+ this.save_xpos = xpos;
+ this.save_ypos = ypos;
+ canvas.getCenterEyeInImagePlate(eyePosn);
+ canvas.getPixelLocationInImagePlate(xpos,ypos,mousePosn);
+
+ if ((canvas.getView() != null) &&
+ (canvas.getView().getProjectionPolicy() ==
+ View.PARALLEL_PROJECTION)) {
+ // Correct for the parallel projection: keep the eye's z
+ // coordinate, but make x,y be the same as the mouse, this
+ // simulates the eye being at "infinity"
+ eyePosn.x = mousePosn.x;
+ eyePosn.y = mousePosn.y;
+ isParallel = true;
+ }
+
+ // Calculate radius for PickCylinderRay and spread angle for PickConeRay
+ Vector3d eyeToCanvas = new Vector3d();
+ eyeToCanvas.sub (mousePosn, eyePosn);
+ double distanceEyeToCanvas = eyeToCanvas.length();
+
+ Point3d deltaImgPlate = new Point3d();
+ canvas.getPixelLocationInImagePlate (xpos+1, ypos, deltaImgPlate);
+
+ Vector3d ptToDelta = new Vector3d();
+ ptToDelta.sub (mousePosn, deltaImgPlate);
+ double distancePtToDelta = ptToDelta.length();
+ distancePtToDelta *= tolerance;
+
+ canvas.getImagePlateToVworld(motion);
+
+ /*
+ System.out.println("mouse position " + xpos + " " + ypos);
+ System.out.println("before, mouse " + mousePosn + " eye " + eyePosn);
+ */
+
+ motion.transform(eyePosn);
+ start = new Point3d (eyePosn); // store the eye position
+ motion.transform(mousePosn);
+ mouseVec.sub(mousePosn, eyePosn);
+ mouseVec.normalize();
+
+ /*
+ System.out.println(motion + "\n");
+ System.out.println("after, mouse " + mousePosn + " eye " + eyePosn +
+ " mouseVec " + mouseVec);
+ */
+
+ if (tolerance == 0.0) {
+ if ((pickShape != null) && (pickShape instanceof PickRay)) {
+ ((PickRay)pickShape).set (eyePosn, mouseVec);
+ } else {
+ pickShape = (PickShape) new PickRay (eyePosn, mouseVec);
+ }
+ // pickShape = (PickShape) new PickConeRay (eyePosn,
+ // mouseVec,1.0*Math.PI/180.0);
+ } else {
+ if (isParallel) {
+ // Parallel projection, use a PickCylinderRay
+ distancePtToDelta *= motion.getScale();
+ if ((pickShape != null) &&
+ (pickShape instanceof PickCylinderRay)) {
+ ((PickCylinderRay)pickShape).set (eyePosn, mouseVec,
+ distancePtToDelta);
+ } else {
+ pickShape = (PickShape) new PickCylinderRay (eyePosn,
+ mouseVec, distancePtToDelta);
+ }
+ } else {
+ // Perspective projection, use a PickConeRay
+
+ // Calculate spread angle
+ spreadAngle = Math.atan (distancePtToDelta/distanceEyeToCanvas);
+
+ if ((pickShape != null) &&
+ (pickShape instanceof PickConeRay)) {
+ ((PickConeRay)pickShape).set (eyePosn, mouseVec,
+ spreadAngle);
+ } else {
+ pickShape = (PickShape) new PickConeRay (eyePosn, mouseVec,
+ spreadAngle);
+ }
+ }
+ }
+ }
+} // PickCanvas
+
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/PickIntersection.java b/src/classes/share/com/sun/j3d/utils/pickfast/PickIntersection.java
new file mode 100644
index 0000000..6403f89
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/PickIntersection.java
@@ -0,0 +1,417 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast;
+
+import javax.vecmath.*;
+import javax.media.j3d.*;
+import com.sun.j3d.utils.geometry.Primitive;
+
+/**
+ * Holds information about an intersection of a PickShape with a Node
+ * as part of a PickInfo.IntersectionInfo. Information about
+ * the intersected geometry, intersected primitive, intersection point, and
+ * closest vertex can be inquired.
+ * <p>
+ * The intersected primitive indicates which primitive out of the GeometryArray
+ * was intersected (where the primitive is a point, line, triangle or quad,
+ * not a
+ * <code>com.sun.j3d.utils.geometry.Primitive)</code>.
+ * For example, the intersection would indicate which triangle out of a
+ * triangle strip was intersected.
+ * The methods which return primitive data will have one value if the primitive
+ * is
+ * a point, two values if the primitive is a line, three values if the primitive
+ * is a triangle and four values if the primitive is quad.
+ * <p>
+ * The primitive's VWorld coordinates are saved when then intersection is
+ * calculated. The local coordinates, normal, color and texture coordinates
+ * for the primitive can also be inquired if they are present and readable.
+ * <p>
+ * The intersection point is the location on the primitive which intersects the
+ * pick shape closest to the center of the pick shape. The intersection point's
+ * location in VWorld coordinates is saved when the intersection is calculated.
+ * The local coordinates, normal, color and texture coordiantes of at the
+ * intersection can be interpolated if they are present and readable.
+ * <p>
+ * The closest vertex is the vertex of the primitive closest to the intersection
+ * point. The vertex index, VWorld coordinates and local coordinates of the
+ * closest vertex can be inquired. The normal, color and texture coordinate
+ * of the closest vertex can be inquired from the geometry array:
+ * <p><blockquote><pre>
+ * Vector3f getNormal(PickIntersection pi, int vertexIndex) {
+ * int index;
+ * Vector3d normal = new Vector3f();
+ * GeometryArray ga = pickIntersection.getGeometryArray();
+ * if (pickIntersection.geometryIsIndexed()) {
+ * index = ga.getNormalIndex(vertexIndex);
+ * } else {
+ * index = vertexIndex;
+ * }
+ * ga.getNormal(index, normal);
+ * return normal;
+ * }
+ * </pre></blockquote>
+ * <p>
+ * The color, normal
+ * and texture coordinate information for the intersected primitive and the
+ * intersection point
+ * can be inquired
+ * the geometry includes them and the corresponding READ capibility bits are
+ * set.
+ */
+
+public class PickIntersection {
+
+
+ /* =================== METHODS ======================= */
+
+ /** Constructor
+ @param intersectionInfo The IntersectionInfo this intersection is part of.
+ */
+ //PickIntersection (PickResult pr, GeometryArray geomArr) {
+ public PickIntersection (PickInfo.IntersectionInfo intersectionInfo) {
+
+ }
+
+ /** Returns true if the geometry is indexed
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public boolean geometryIsIndexed() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** Get coordinates of closest vertex (local)
+ @return the coordinates of the vertex closest to the intersection point
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Point3d getClosestVertexCoordinates () {
+ throw new UnsupportedOperationException();
+ }
+
+ /** Get coordinates of closest vertex (world)
+ @return the coordinates of the vertex closest to the intersection point
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Point3d getClosestVertexCoordinatesVW () {
+ throw new UnsupportedOperationException();
+ }
+
+ /** Get index of closest vertex
+ @return the index of the closest vertex
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public int getClosestVertexIndex () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the distance from the PickShape start point to the intersection point
+ @return the distance to the intersection point, if available.
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public double getDistance () {
+ throw new UnsupportedOperationException();
+ }
+
+
+ /**
+ Returns the color of the intersection point. Returns null if the geometry
+ does not contain colors. If the geometry was defined with
+ GeometryArray.COLOR_3, the 'w' component of the color will initialized to
+ 1.0
+ @return color at the intersection point.
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Color4f getPointColor() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ /**
+ Returns the coordinates of the intersection point (local coordinates),
+ if available.
+ @return coordinates of the intersection point
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Point3d getPointCoordinates() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Returns the coordinates of the intersection point (world coordinates),
+ if available.
+ @return coordinates of the point
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Point3d getPointCoordinatesVW() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Returns the normal of the intersection point. Returns null if the geometry
+ does not contain normals.
+ @return normal at the intersection point.
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Vector3f getPointNormal() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Returns the texture coordinate of the intersection point at the specifed
+ index in the specified texture coordinate set.
+ Returns null if the geometry
+ does not contain texture coordinates. If the geometry was defined with
+ GeometryArray.TEXTURE_COORDINATE_3, the 'z' component of the texture
+ coordinate will initialized to 0.0
+ @return texture coordinate at the intersection point.
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public TexCoord3f getPointTextureCoordinate(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the color indices for the intersected primitive. For a non-indexed
+ primitive, this will be the same as the primitive vertex indices
+ If the geometry array does not contain colors this will return null.
+ @return an array indices
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public int[] getPrimitiveColorIndices () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the colors of the intersected primitive. This will return null if
+ the primitive does not contain colors. If the geometry was defined
+ using GeometryArray.COLOR_3, the 'w' value of the color will be set to 1.0.
+ @return an array of Point3d's for the primitive that was intersected
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Color4f[] getPrimitiveColors () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the coordinates indices for the intersected primitive. For a non-indexed
+ primitive, this will be the same as the primitive vertex indices
+ @return an array indices
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public int[] getPrimitiveCoordinateIndices () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the local coordinates intersected primitive
+ @return an array of Point3d's for the primitive that was intersected
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Point3d[] getPrimitiveCoordinates () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get VWorld coordinates of the intersected primitive
+ @return an array of Point3d's for the primitive that was picked
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Point3d[] getPrimitiveCoordinatesVW () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the normal indices for the intersected primitive. For a non-indexed
+ primitive, this will be the same as the primitive vertex indices
+ If the geometry array does not contain normals this will return null
+ @return an array indices
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public int[] getPrimitiveNormalIndices () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the normals of the intersected primitive. This will return null if
+ the primitive does not contain normals.
+ @return an array of Point3d's for the primitive that was intersected
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public Vector3f[] getPrimitiveNormals () {
+ throw new UnsupportedOperationException();
+ }
+
+
+ /**
+ Get the texture coordinate indices for the intersected primitive at the specifed
+ index in the specified texture coordinate set. For a non-indexed
+ primitive, this will be the same as the primitive vertex indices
+ If the geometry array does not contain texture coordinates, this will
+ return null.
+ @return an array indices
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public int[] getPrimitiveTexCoordIndices (int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get the texture coordinates of the intersected primitive at the specifed
+ index in the specified texture coordinate set.
+ null if the primitive does not contain texture coordinates.
+ If the geometry was defined
+ using GeometryArray.TEXTURE_COORDINATE_2, the 'z' value of the texture
+ coordinate will be set to 0.0.
+ @return an array of TexCoord3f's for the primitive that was intersected
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public TexCoord3f[] getPrimitiveTexCoords (int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ Get vertex indices of the intersected primitive
+ @return an array which contains the list of indices
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public int [] getPrimitiveVertexIndices () {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ String representation of this object
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public String toString () {
+ throw new UnsupportedOperationException();
+ }
+
+
+ /**
+ Gets the IntersectionInfo this intersection is part of.
+
+ * This method is currently not supported.
+ * @exception UnsupportedOperationException this method is not supported
+
+ */
+ public PickInfo.IntersectionInfo getIntersectionInfo() {
+ throw new UnsupportedOperationException();
+ }
+
+
+} // PickIntersection
+
+
+
+
+
+
+
+
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/PickTool.java b/src/classes/share/com/sun/j3d/utils/pickfast/PickTool.java
new file mode 100644
index 0000000..18116c9
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/PickTool.java
@@ -0,0 +1,514 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast;
+
+import com.sun.j3d.utils.geometry.Primitive;
+import javax.vecmath.*;
+import javax.media.j3d.*;
+import com.sun.j3d.internal.*;
+
+/**
+ * The base class for optimized picking operations.
+ * The picking methods will return a PickInfo object for each object picked,
+ * which can then be queried to
+ * obtain more detailed information about the specific objects that were
+ * picked.
+ * <p>
+ * The pick mode specifies the detail level of picking before the PickInfo
+ * is returned:
+ * <p>
+ * <UL>
+ * <LI> PickInfo.PICK_BOUNDS - Pick using the only bounds of the pickable nodes.
+ * </LI>
+ * <LI> PickInfo.PICK_GEOMETRY will pick using the geometry of the pickable nodes.
+ * Geometry nodes in the scene must have the ALLOW_INTERSECT capability set for
+ * this mode.</LI>
+ * <p>
+ * The pick flags specifies the content of the PickInfo(s) returned by the
+ * pick methods. This is specified as one or more individual bits that are
+ * bitwise "OR"ed together to describe the PickInfo data. The flags include :
+ * <ul>
+ * <code>PickInfo.SCENEGRAPHPATH</code> - request for computed SceneGraphPath.<br>
+ * <code>PickInfo.NODE</code> - request for computed intersected Node.<br>
+ * <code>PickInfo.LOCAL_TO_VWORLD</code> - request for computed local to virtual world transform.<br>
+ * <code>PickInfo.CLOSEST_INTERSECTION_POINT</code> - request for closest intersection point.<br>
+ * <code>PickInfo.CLOSEST_DISTANCE</code> - request for the distance of closest intersection.<br>
+ * <code>PickInfo.CLOSEST_GEOM_INFO</code> - request for only the closest intersection geometry information.<br>
+ * <code>PickInfo.ALL_GEOM_INFO</code> - request for all intersection geometry information.<br>
+ * </ul>
+ * </UL>
+ * <p>
+ * When using pickAllSorted or pickClosest methods, the picks
+ * will be sorted by the distance from the start point of the pick shape to
+ * the intersection point.
+ *
+ * @see Locale#pickClosest(int,int,javax.media.j3d.PickShape)
+ */
+public class PickTool {
+
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>Shape3D</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_SHAPE3D = 0x1;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>Morph</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_MORPH = 0x2;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+
+ * to return a
+ * <code>Primitive</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_PRIMITIVE = 0x4;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>Link</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_LINK = 0x8;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>Group</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_GROUP = 0x10;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>TransformGroup</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_TRANSFORM_GROUP = 0x20;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>BranchGroup</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_BRANCH_GROUP = 0x40;
+
+ /**
+ * Flag to pass to
+ * <CODE>getNode(int)</CODE>
+ * to return a
+ * <code>Switch</code> node from
+ * the <code>SceneGraphPath</code>.
+ */
+ public static final int TYPE_SWITCH = 0x80;
+
+
+ private static final int ALL_FLAGS =
+ PickInfo.SCENEGRAPHPATH |
+ PickInfo.NODE |
+ PickInfo.LOCAL_TO_VWORLD |
+ PickInfo.CLOSEST_INTERSECTION_POINT |
+ PickInfo.CLOSEST_DISTANCE |
+ PickInfo.CLOSEST_GEOM_INFO |
+ PickInfo.ALL_GEOM_INFO;
+
+ private final boolean debug = false;
+ protected boolean userDefineShape = false;
+
+ PickShape pickShape;
+
+ /** Used to store the BranchGroup used for picking */
+ BranchGroup pickRootBG = null;
+ /** Used to store the Locale used for picking */
+ Locale pickRootL = null;
+
+ /** Used to store a reference point used in determining how "close" points
+ are.
+ */
+ Point3d start = null;
+
+ int mode = PickInfo.PICK_BOUNDS;
+ int flags = PickInfo.NODE;
+
+ /* ============================ METHODS ============================ */
+
+ /**
+ * Constructor with BranchGroup to be picked.
+ */
+ public PickTool (BranchGroup b) {
+ pickRootBG = b;
+ }
+
+ /**
+ * Constructor with the Locale to be picked.
+ */
+ public PickTool (Locale l) {
+ pickRootL = l;
+ }
+
+ /** Returns the BranchGroup to be picked if the tool was initialized
+ with a BranchGroup, null otherwise.
+ */
+ public BranchGroup getBranchGroup() {
+ return pickRootBG;
+ }
+
+ /**
+ * Returns the Locale to be picked if the tool was initialized with
+ * a Locale, null otherwise.
+ */
+ public Locale getLocale () {
+ return pickRootL;
+ }
+
+ // Methods used to define the pick shape
+
+ /** Sets the pick shape to a user-provided PickShape object
+ * @param ps The pick shape to pick against.
+ * @param startPt The start point to use for distance calculations
+ */
+ public void setShape (PickShape ps, Point3d startPt) {
+ this.pickShape = ps;
+ this.start = startPt;
+ userDefineShape = (ps != null);
+ }
+
+ /** Sets the pick shape to use a user-provided Bounds object
+ * @param bounds The bounds to pick against.
+ * @param startPt The start point to use for distance calculations
+ */
+ public void setShapeBounds (Bounds bounds, Point3d startPt) {
+ this.pickShape = (PickShape) new PickBounds (bounds);
+ this.start = startPt;
+ userDefineShape = true;
+ }
+
+ /** Sets the picking detail mode. The default is PickInfo.PICK_BOUNDS.
+ * @param mode One of PickInfo.PICK_BOUNDS or PickInfo.PICK_GEOMETRY.
+ * @exception IllegalArgumentException if mode is not a legal value
+ */
+ public void setMode (int mode) {
+ if ((mode != PickInfo.PICK_BOUNDS) && (mode != PickInfo.PICK_GEOMETRY)) {
+ throw new java.lang.IllegalArgumentException();
+ }
+ this.mode = mode;
+ }
+
+ /** Gets the picking detail mode.
+ */
+ public int getMode () {
+ return mode;
+ }
+
+ /** Sets the PickInfo content flags. The default is PickInfo.NODE.
+ * @param flags One of the following:
+ * <ul>
+ * <code>PickInfo.SCENEGRAPHPATH</code> - request for computed SceneGraphPath.<br>
+ * <code>PickInfo.NODE</code> - request for computed intersected Node.<br>
+ * <code>PickInfo.LOCAL_TO_VWORLD</code> - request for computed local to virtual world transform.<br>
+ * <code>PickInfo.CLOSEST_INTERSECTION_POINT</code> - request for closest intersection point.<br>
+ * <code>PickInfo.CLOSEST_DISTANCE</code> - request for the distance of closest intersection.<br>
+ * <code>PickInfo.CLOSEST_GEOM_INFO</code> - request for only the closest intersection geometry information.<br>
+ * <code>PickInfo.ALL_GEOM_INFO</code> - request for all intersection geometry information.<br>
+ * </ul>
+ * @exception IllegalArgumentException if any other bits besides the above are set.
+ */
+ public void setFlags (int flags) {
+ if ((flags & ~ALL_FLAGS) != 0) {
+ throw new java.lang.IllegalArgumentException();
+ }
+ this.flags = flags;
+ }
+
+ /** Gets the PickInfo content flags.
+ */
+ public int getFlags () {
+ return flags;
+ }
+
+ /** Sets the pick shape to a PickRay.
+ * @param start The start of the ray
+ * @param dir The direction of the ray
+ */
+ public void setShapeRay (Point3d start, Vector3d dir) {
+ this.pickShape = (PickShape) new PickRay (start, dir);
+ this.start = start;
+ userDefineShape = true;
+ }
+
+ /** Sets the pick shape to a PickSegment.
+ @param start The start of the segment
+ @param end The end of the segment
+ */
+ public void setShapeSegment (Point3d start, Point3d end) {
+ this.pickShape = (PickShape) new PickSegment (start, end);
+ this.start = start;
+ userDefineShape = true;
+ }
+
+ /** Sets the pick shape to a capped PickCylinder
+ * @param start The start of axis of the cylinder
+ * @param end The end of the axis of the cylinder
+ * @param radius The radius of the cylinder
+ */
+ public void setShapeCylinderSegment (Point3d start, Point3d end,
+ double radius) {
+ this.pickShape = (PickShape)
+ new PickCylinderSegment (start, end, radius);
+ this.start = start;
+ userDefineShape = true;
+ }
+
+ /** Sets the pick shape to an infinite PickCylinder.
+ * @param start The start of axis of the cylinder
+ * @param dir The direction of the axis of the cylinder
+ * @param radius The radius of the cylinder
+ */
+ public void setShapeCylinderRay (Point3d start, Vector3d dir,
+ double radius) {
+ this.pickShape = (PickShape) new PickCylinderRay (start, dir, radius);
+ this.start = start;
+ userDefineShape = true;
+ }
+
+ /** Sets the pick shape to a capped PickCone
+ * @param start The start of axis of the cone
+ * @param end The end of the axis of the cone
+ * @param angle The angle of the cone
+ */
+ public void setShapeConeSegment (Point3d start, Point3d end,
+ double angle) {
+ this.pickShape = (PickShape) new PickConeSegment (start, end, angle);
+ this.start = start;
+ userDefineShape = true;
+ }
+
+ /** Sets the pick shape to an infinite PickCone.
+ * @param start The start of axis of the cone
+ * @param dir The direction of the axis of the cone
+ * @param angle The angle of the cone
+ */
+ public void setShapeConeRay (Point3d start, Vector3d dir,
+ double angle) {
+ this.pickShape = (PickShape) new PickConeRay (start, dir, angle);
+ this.start = start;
+ userDefineShape = true;
+ }
+
+ /** Returns the PickShape for this object. */
+ public PickShape getPickShape () {
+ return pickShape;
+ }
+
+ /** Returns the start postion used for distance measurement. */
+ public Point3d getStartPosition () {
+ return start;
+ }
+
+ /** Selects all the nodes that intersect the PickShape.
+ @return An array of <code>PickInfo</code> objects which will contain
+ information about the picked instances. <code>null</code> if nothing was
+ picked.
+ */
+ public PickInfo[] pickAll () {
+ PickInfo[] pickInfos = null;
+ if (pickRootBG != null) {
+ pickInfos = pickRootBG.pickAll(mode, flags, pickShape);
+ } else if (pickRootL != null) {
+ pickInfos = pickRootL.pickAll(mode, flags, pickShape);
+ }
+ return pickInfos;
+ }
+
+ /** Select one of the nodes that intersect the PickShape
+ @return An array of <code>PickInfo</code> objects which will contain
+ information about the picked instances. <code>null</code> if nothing
+ was picked.
+ */
+ public PickInfo pickAny () {
+ PickInfo pickInfo = null;
+ if (pickRootBG != null) {
+ pickInfo = pickRootBG.pickAny(mode, flags, pickShape);
+ } else if (pickRootL != null) {
+ pickInfo = pickRootL.pickAny(mode, flags, pickShape);
+ }
+ return pickInfo;
+ }
+
+ /** Select all the nodes that intersect the
+ PickShape, returned sorted. The "closest" object will be returned first.
+ See note above to see how "closest" is determined.
+ <p>
+ @return An array of <code>PickInfo</code> objects which will contain
+ information
+ about the picked instances. <code>null</code> if nothing was picked.
+ */
+ public PickInfo[] pickAllSorted () {
+ PickInfo[] pickInfos = null;
+ if (pickRootBG != null) {
+ pickInfos = pickRootBG.pickAllSorted(mode, flags, pickShape);
+ } else if (pickRootL != null) {
+ pickInfos = pickRootL.pickAllSorted(mode, flags, pickShape);
+ }
+ return pickInfos;
+ }
+
+ /** Select the closest node that
+ intersects the PickShape. See note above to see how "closest" is
+ determined.
+ <p>
+ @return An array of <code>PickInfo</code> objects which will contain
+ information about the picked instances. <code>null</code> if nothing
+ was picked.
+ */
+ public PickInfo pickClosest () {
+ // System.out.println("PickTool : pickClosest ...");
+ PickInfo pickInfo = null;
+ if (pickRootBG != null) {
+ pickInfo = pickRootBG.pickClosest(mode, flags, pickShape);
+ } else if (pickRootL != null) {
+ pickInfo = pickRootL.pickClosest(mode, flags, pickShape);
+ }
+ // System.out.println(" -- pickInfo is " + pickInfo);
+
+ return pickInfo;
+ }
+
+ /** Get the first node of a certain type up the SceneGraphPath
+ *@param type the type of node we are interested in
+ *@return a Node object
+ *
+ * @exception NullPointerException if pickInfo does not contain a
+ * Scenegraphpath or a picked node
+ */
+
+ public Node getNode (PickInfo pickInfo, int type) {
+
+ // System.out.println("pickInfo is " + pickInfo);
+
+ if (pickInfo == null) {
+ return null;
+ }
+
+ SceneGraphPath sgp = pickInfo.getSceneGraphPath();
+ Node pickedNode = pickInfo.getNode();
+ // System.out.println("sgp = " + sgp + " pickedNode = " + pickedNode);
+
+
+ /*
+ * Do not check for null for pickNode and sgp.
+ * Will throw NPE if pickedNode or sgp isn't set in pickInfo
+ */
+
+ if ((pickedNode instanceof Shape3D) && ((type & TYPE_SHAPE3D) != 0)){
+ if (debug) System.out.println("Shape3D found");
+ return pickedNode;
+ }
+ else if ((pickedNode instanceof Morph) && ((type & TYPE_MORPH) != 0)){
+ if (debug) System.out.println("Morph found");
+ return pickedNode;
+ }
+ else {
+ for (int j=sgp.nodeCount()-1; j>=0; j--){
+ Node pNode = sgp.getNode(j);
+ if (debug) System.out.println("looking at node " + pNode);
+
+ if ((pNode instanceof Primitive) &&
+ ((type & TYPE_PRIMITIVE) != 0)){
+ if (debug) System.out.println("Primitive found");
+ return pNode;
+ }
+ else if ((pNode instanceof Link) && ((type & TYPE_LINK) != 0)){
+ if (debug) System.out.println("Link found");
+ return pNode;
+ }
+ else if ((pNode instanceof Switch) && ((type & TYPE_SWITCH) != 0)){
+ if (debug) System.out.println("Switch found");
+ return pNode;
+ }
+ else if ((pNode instanceof TransformGroup) &&
+ ((type & TYPE_TRANSFORM_GROUP) != 0)){
+ if (debug) System.out.println("xform group found");
+ return pNode;
+ }
+ else if ((pNode instanceof BranchGroup) &&
+ ((type & TYPE_BRANCH_GROUP) != 0)){
+ if (debug) System.out.println("Branch group found");
+ return pNode;
+ }
+ else if ((pNode instanceof Group) && ((type & TYPE_GROUP) != 0)){
+ if (debug) System.out.println("Group found");
+ return pNode;
+ }
+ }
+ }
+ return null; // should not be reached
+ }
+
+
+} // PickTool
+
+
+
+
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickMouseBehavior.java b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickMouseBehavior.java
new file mode 100644
index 0000000..35465e2
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickMouseBehavior.java
@@ -0,0 +1,179 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast.behaviors;
+
+import com.sun.j3d.utils.pickfast.*;
+import com.sun.j3d.internal.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+
+/**
+ * Base class that allows users to adding picking and mouse manipulation to
+ * the scene graph (see PickDragBehavior for an example of how to extend
+ * this base class). This class is useful for interactive apps.
+ */
+
+public abstract class PickMouseBehavior extends Behavior {
+
+ protected PickCanvas pickCanvas;
+
+ protected WakeupCriterion[] conditions;
+ protected WakeupOr wakeupCondition;
+ protected boolean buttonPress = false;
+
+ protected TransformGroup currGrp;
+ protected static final boolean debug = false;
+ protected MouseEvent mevent;
+
+ /**
+ * Creates a PickMouseBehavior given current canvas, root of the tree to
+ * operate on, and the bounds.
+ */
+ public PickMouseBehavior(Canvas3D canvas, BranchGroup root, Bounds bounds){
+ super();
+ currGrp = new TransformGroup();
+ currGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ currGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
+ root.addChild(currGrp);
+ pickCanvas = new PickCanvas(canvas, root);
+ }
+
+ /**
+ * Sets the pick mode
+ * @see PickTool#setMode
+ **/
+ public void setMode(int pickMode) {
+ pickCanvas.setMode(pickMode);
+ }
+
+ /**
+ * Returns the pickMode
+ * @see PickTool#getMode
+ */
+
+ public int getMode() {
+ return pickCanvas.getMode();
+ }
+
+ /**
+ * Sets the pick tolerance
+ * @see PickCanvas#setTolerance
+ */
+ public void setTolerance(float tolerance) {
+ pickCanvas.setTolerance(tolerance);
+ }
+
+ /**
+ * Returns the pick tolerance
+ * @see PickCanvas#getTolerance
+ */
+ public float getTolerance() {
+ return pickCanvas.getTolerance();
+ }
+
+ public void initialize() {
+
+ conditions = new WakeupCriterion[2];
+ conditions[0] = new WakeupOnAWTEvent(Event.MOUSE_MOVE);
+ conditions[1] = new WakeupOnAWTEvent(Event.MOUSE_DOWN);
+ wakeupCondition = new WakeupOr(conditions);
+
+ wakeupOn(wakeupCondition);
+ }
+
+ private void processMouseEvent(MouseEvent evt) {
+ buttonPress = false;
+
+ if (evt.getID()==MouseEvent.MOUSE_PRESSED |
+ evt.getID()==MouseEvent.MOUSE_CLICKED) {
+ buttonPress = true;
+ return;
+ }
+ else if (evt.getID() == MouseEvent.MOUSE_MOVED) {
+ // Process mouse move event
+ }
+ }
+
+ public void processStimulus (Enumeration criteria) {
+ WakeupCriterion wakeup;
+ AWTEvent[] evt = null;
+ int xpos = 0, ypos = 0;
+
+ while(criteria.hasMoreElements()) {
+ wakeup = (WakeupCriterion)criteria.nextElement();
+ if (wakeup instanceof WakeupOnAWTEvent)
+ evt = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
+ }
+
+ if (evt[0] instanceof MouseEvent){
+ mevent = (MouseEvent) evt[0];
+
+ if (debug)
+ System.out.println("got mouse event");
+ processMouseEvent((MouseEvent)evt[0]);
+ xpos = mevent.getPoint().x;
+ ypos = mevent.getPoint().y;
+ }
+
+ if (debug)
+ System.out.println("mouse position " + xpos + " " + ypos);
+
+ if (buttonPress){
+ updateScene(xpos, ypos);
+ }
+ wakeupOn (wakeupCondition);
+ }
+
+
+ /** Subclasses shall implement this update function
+ */
+ public abstract void updateScene(int xpos, int ypos);
+
+}
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickRotateBehavior.java b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickRotateBehavior.java
new file mode 100644
index 0000000..4980de7
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickRotateBehavior.java
@@ -0,0 +1,174 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast.behaviors;
+
+import com.sun.j3d.utils.pickfast.*;
+import com.sun.j3d.utils.behaviors.mouse.*;
+import com.sun.j3d.internal.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+/**
+ * A mouse behavior that allows user to pick and rotate scene graph objects.
+ * Common usage:
+ * <p>
+ * 1. Create your scene graph.
+ * <p>
+ * 2. Create this behavior with root and canvas.
+ * <p>
+ * <blockquote><pre>
+ * PickRotateBehavior behavior = new PickRotateBehavior(canvas, root, bounds);
+ * root.addChild(behavior);
+ * </pre></blockquote>
+ * <p>
+ * The above behavior will monitor for any picking events on
+ * the scene graph (below root node) and handle mouse rotates on pick hits.
+ * Note the root node can also be a subgraph node of the scene graph (rather
+ * than the topmost).
+ */
+
+public class PickRotateBehavior extends PickMouseBehavior implements MouseBehaviorCallback {
+ MouseRotate rotate;
+ private PickingCallback callback=null;
+ private TransformGroup currentTG;
+
+ /**
+ * Creates a pick/rotate behavior that waits for user mouse events for
+ * the scene graph. This method has its pickMode set to BOUNDS picking.
+ * @param root Root of your scene graph.
+ * @param canvas Java 3D drawing canvas.
+ * @param bounds Bounds of your scene.
+ **/
+
+ public PickRotateBehavior(BranchGroup root, Canvas3D canvas, Bounds bounds){
+ super(canvas, root, bounds);
+ rotate = new MouseRotate(MouseRotate.MANUAL_WAKEUP);
+ rotate.setTransformGroup(currGrp);
+ currGrp.addChild(rotate);
+ rotate.setSchedulingBounds(bounds);
+ this.setSchedulingBounds(bounds);
+ }
+
+ /**
+ * Creates a pick/rotate behavior that waits for user mouse events for
+ * the scene graph.
+ * @param root Root of your scene graph.
+ * @param canvas Java 3D drawing canvas.
+ * @param bounds Bounds of your scene.
+ * @param pickMode specifys PickTool.BOUNDS, PickTool.GEOMETRY or
+ * PickTool.GEOMETRY_INTERSECT_INFO.
+ * @see PickTool#setMode
+ **/
+
+ public PickRotateBehavior(BranchGroup root, Canvas3D canvas, Bounds bounds,
+ int pickMode){
+ super(canvas, root, bounds);
+ rotate = new MouseRotate(MouseRotate.MANUAL_WAKEUP);
+ rotate.setTransformGroup(currGrp);
+ currGrp.addChild(rotate);
+ rotate.setSchedulingBounds(bounds);
+ this.setSchedulingBounds(bounds);
+ this.setMode(pickMode);
+ }
+
+
+ /**
+ * Update the scene to manipulate any nodes. This is not meant to be
+ * called by users. Behavior automatically calls this. You can call
+ * this only if you know what you are doing.
+ *
+ * @param xpos Current mouse X pos.
+ * @param ypos Current mouse Y pos.
+ **/
+ public void updateScene(int xpos, int ypos) {
+ TransformGroup tg = null;
+
+ if (!mevent.isMetaDown() && !mevent.isAltDown()){
+
+ // System.out.println("PickRotateBeh : using pickfast pkg : PickInfo ...");
+ pickCanvas.setFlags(PickInfo.NODE | PickInfo.SCENEGRAPHPATH);
+
+ pickCanvas.setShapeLocation(xpos, ypos);
+ PickInfo pickInfo = pickCanvas.pickClosest();
+ if(pickInfo != null) {
+ // System.out.println("Intersected!");
+ tg = (TransformGroup) pickCanvas.getNode(pickInfo, PickTool.TYPE_TRANSFORM_GROUP);
+ if((tg != null) &&
+ (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) &&
+ (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
+ rotate.setTransformGroup(tg);
+ rotate.wakeup();
+ currentTG = tg;
+ }
+ } else if (callback!=null)
+ callback.transformChanged( PickingCallback.NO_PICK, null );
+ }
+ }
+
+ /**
+ * Callback method from MouseRotate
+ * This is used when the Picking callback is enabled
+ */
+ public void transformChanged( int type, Transform3D transform ) {
+ callback.transformChanged( PickingCallback.ROTATE, currentTG );
+ }
+
+ /**
+ * Register the class @param callback to be called each
+ * time the picked object moves
+ */
+ public void setupCallback( PickingCallback callback ) {
+ this.callback = callback;
+ if (callback==null)
+ rotate.setupCallback( null );
+ else
+ rotate.setupCallback( this );
+ }
+
+}
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickTranslateBehavior.java b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickTranslateBehavior.java
new file mode 100644
index 0000000..16ee7dd
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickTranslateBehavior.java
@@ -0,0 +1,163 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast.behaviors;
+
+import com.sun.j3d.utils.pickfast.*;
+import com.sun.j3d.utils.behaviors.mouse.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+/**
+ * A mouse behavior that allows user to pick and translate scene graph objects.
+ * Common usage: 1. Create your scene graph. 2. Create this behavior with
+ * the root and canvas. See PickRotateBehavior for more details.
+ */
+
+public class PickTranslateBehavior extends PickMouseBehavior implements MouseBehaviorCallback {
+ MouseTranslate translate;
+ private PickingCallback callback = null;
+ private TransformGroup currentTG;
+
+ /**
+ * Creates a pick/translate behavior that waits for user mouse events for
+ * the scene graph.
+ * @param root Root of your scene graph.
+ * @param canvas Java 3D drawing canvas.
+ * @param bounds Bounds of your scene.
+ **/
+
+ public PickTranslateBehavior(BranchGroup root, Canvas3D canvas, Bounds bounds){
+ super(canvas, root, bounds);
+ translate = new MouseTranslate(MouseBehavior.MANUAL_WAKEUP);
+ translate.setTransformGroup(currGrp);
+ currGrp.addChild(translate);
+ translate.setSchedulingBounds(bounds);
+ this.setSchedulingBounds(bounds);
+ }
+
+ /**
+ * Creates a pick/translate behavior that waits for user mouse events for
+ * the scene graph.
+ * @param root Root of your scene graph.
+ * @param canvas Java 3D drawing canvas.
+ * @param bounds Bounds of your scene.
+ * @param pickMode specifys PickTool.BOUNDS, PickTool.GEOMETRY or
+ * PickTool.GEOMETRY_INTERSECT_INFO.
+ * @see PickTool#setMode
+ **/
+ public PickTranslateBehavior(BranchGroup root, Canvas3D canvas,
+ Bounds bounds, int pickMode) {
+ super(canvas, root, bounds);
+ translate = new MouseTranslate(MouseBehavior.MANUAL_WAKEUP);
+ translate.setTransformGroup(currGrp);
+ currGrp.addChild(translate);
+ translate.setSchedulingBounds(bounds);
+ this.setSchedulingBounds(bounds);
+ this.setMode(pickMode);
+ }
+
+
+ /**
+ * Update the scene to manipulate any nodes. This is not meant to be
+ * called by users. Behavior automatically calls this. You can call
+ * this only if you know what you are doing.
+ *
+ * @param xpos Current mouse X pos.
+ * @param ypos Current mouse Y pos.
+ **/
+ public void updateScene(int xpos, int ypos){
+ TransformGroup tg = null;
+
+ if(!mevent.isAltDown() && mevent.isMetaDown()){
+
+ pickCanvas.setShapeLocation(xpos, ypos);
+
+ // System.out.println("PickTranslateBeh : using pickfast pkg : PickInfo ...");
+
+ pickCanvas.setFlags(PickInfo.NODE | PickInfo.SCENEGRAPHPATH);
+ PickInfo pickInfo = pickCanvas.pickClosest();
+
+ if(pickInfo != null) {
+ // System.out.println("Intersected!");
+ tg = (TransformGroup) pickCanvas.getNode(pickInfo, PickTool.TYPE_TRANSFORM_GROUP);
+ if((tg != null) &&
+ (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) &&
+ (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
+ translate.setTransformGroup(tg);
+ translate.wakeup();
+ currentTG = tg;
+ }
+ } else if (callback!=null)
+ callback.transformChanged( PickingCallback.NO_PICK, null );
+
+ }
+
+ }
+
+ /**
+ * Callback method from MouseTranslate
+ * This is used when the Picking callback is enabled
+ */
+ public void transformChanged( int type, Transform3D transform ) {
+ callback.transformChanged( PickingCallback.TRANSLATE, currentTG );
+ }
+
+ /**
+ * Register the class @param callback to be called each
+ * time the picked object moves
+ */
+ public void setupCallback( PickingCallback callback ) {
+ this.callback = callback;
+ if (callback==null)
+ translate.setupCallback( null );
+ else
+ translate.setupCallback( this );
+ }
+
+}
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickZoomBehavior.java b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickZoomBehavior.java
new file mode 100644
index 0000000..ee265ee
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickZoomBehavior.java
@@ -0,0 +1,162 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast.behaviors;
+
+import com.sun.j3d.utils.pickfast.*;
+import com.sun.j3d.utils.behaviors.mouse.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+
+
+/**
+ * A mouse behavior that allows user to pick and zoom scene graph objects.
+ * Common usage: 1. Create your scene graph. 2. Create this behavior with
+ * the root and canvas. See PickRotateBehavior for more details.
+ */
+
+public class PickZoomBehavior extends PickMouseBehavior implements MouseBehaviorCallback {
+ MouseZoom zoom;
+ private PickingCallback callback = null;
+ private TransformGroup currentTG;
+
+ /**
+ * Creates a pick/zoom behavior that waits for user mouse events for
+ * the scene graph.
+ * @param root Root of your scene graph.
+ * @param canvas Java 3D drawing canvas.
+ * @param bounds Bounds of your scene.
+ **/
+
+ public PickZoomBehavior(BranchGroup root, Canvas3D canvas, Bounds bounds){
+ super(canvas, root, bounds);
+ zoom = new MouseZoom(MouseBehavior.MANUAL_WAKEUP);
+ zoom.setTransformGroup(currGrp);
+ currGrp.addChild(zoom);
+ zoom.setSchedulingBounds(bounds);
+ this.setSchedulingBounds(bounds);
+ }
+
+ /**
+ * Creates a pick/zoom behavior that waits for user mouse events for
+ * the scene graph.
+ * @param root Root of your scene graph.
+ * @param canvas Java 3D drawing canvas.
+ * @param bounds Bounds of your scene.
+ * @param pickMode specifys PickTool.BOUNDS, PickTool.GEOMETRY or
+ * PickTool.GEOMETRY_INTERSECT_INFO.
+ * @see PickTool#setMode
+ */
+ public PickZoomBehavior(BranchGroup root, Canvas3D canvas, Bounds bounds,
+ int pickMode) {
+ super(canvas, root, bounds);
+ zoom = new MouseZoom(MouseBehavior.MANUAL_WAKEUP);
+ zoom.setTransformGroup(currGrp);
+ currGrp.addChild(zoom);
+ zoom.setSchedulingBounds(bounds);
+ this.setSchedulingBounds(bounds);
+ this.setMode(pickMode);
+ }
+
+ /**
+ * Update the scene to manipulate any nodes. This is not meant to be
+ * called by users. Behavior automatically calls this. You can call
+ * this only if you know what you are doing.
+ *
+ * @param xpos Current mouse X pos.
+ * @param ypos Current mouse Y pos.
+ **/
+
+ public void updateScene(int xpos, int ypos){
+ TransformGroup tg = null;
+
+ if (mevent.isAltDown() && !mevent.isMetaDown()){
+
+ pickCanvas.setShapeLocation(xpos, ypos);
+ // System.out.println("PickZoomBeh : using pickfast pkg : PickInfo ...");
+
+ pickCanvas.setFlags(PickInfo.NODE | PickInfo.SCENEGRAPHPATH);
+
+ PickInfo pickInfo = pickCanvas.pickClosest();
+ if(pickInfo != null) {
+ // System.out.println("Intersected!");
+ tg = (TransformGroup) pickCanvas.getNode(pickInfo, PickTool.TYPE_TRANSFORM_GROUP);
+ if((tg != null) &&
+ (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) &&
+ (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
+ zoom.setTransformGroup(tg);
+ zoom.wakeup();
+ currentTG = tg;
+ }
+ } else if (callback!=null)
+ callback.transformChanged( PickingCallback.NO_PICK, null );
+
+
+ }
+ }
+
+ /**
+ * Callback method from MouseZoom
+ * This is used when the Picking callback is enabled
+ */
+ public void transformChanged( int type, Transform3D transform ) {
+ callback.transformChanged( PickingCallback.ZOOM, currentTG );
+ }
+
+ /**
+ * Register the class @param callback to be called each
+ * time the picked object moves
+ */
+ public void setupCallback( PickingCallback callback ) {
+ this.callback = callback;
+ if (callback==null)
+ zoom.setupCallback( null );
+ else
+ zoom.setupCallback( this );
+ }
+}
+
diff --git a/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickingCallback.java b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickingCallback.java
new file mode 100644
index 0000000..db6a72c
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/pickfast/behaviors/PickingCallback.java
@@ -0,0 +1,76 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.pickfast.behaviors;
+
+import javax.media.j3d.TransformGroup;
+
+/**
+ * The PickingCallback interface allows a class to be notified when a
+ * picked object is moved. The class that is interested in object
+ * movement implements this interface, and the object created with
+ * that class is registered with the desired subclass of
+ * PickMouseBehavior using the <code>setupCallback</code> method.
+ * When the picked object moves, the registered object's
+ * <code>transformChanged</code> method is invoked.
+ */
+
+public interface PickingCallback {
+
+ public final static int ROTATE=0;
+ public final static int TRANSLATE=1;
+ public final static int ZOOM=2;
+
+ /**
+ * The user made a selection but nothing was
+ * actually picked
+ */
+ public final static int NO_PICK=3;
+
+ /**
+ * Called by the Pick Behavior with which this callback
+ * is registered each time the Picked object is moved
+ */
+ public void transformChanged( int type, TransformGroup tg );
+}
diff --git a/src/classes/share/com/sun/j3d/utils/picking/PickResult.java b/src/classes/share/com/sun/j3d/utils/picking/PickResult.java
index 090b605..2066413 100644
--- a/src/classes/share/com/sun/j3d/utils/picking/PickResult.java
+++ b/src/classes/share/com/sun/j3d/utils/picking/PickResult.java
@@ -185,35 +185,37 @@ public class PickResult {
static boolean debug = false;
/** if true, find only the first intersection */
- boolean firstIntersectOnly = false;
+ private boolean firstIntersectOnly = false;
/** Stored SceneGraphPath */
- SceneGraphPath pickedSceneGraphPath = null;
+ private SceneGraphPath pickedSceneGraphPath = null;
/** Picked node: shape3d, text3d, etc. */
- Node pickedNode = null;
+ private Node pickedNode = null;
/** GeometryArray(s) of the picked node */
- GeometryArray[] geometryArrays = null;
+ private GeometryArray[] geometryArrays = null;
/** Shape3Ds from CompressedGeometry on the picked node */
- Shape3D[] compressGeomShape3Ds = null;
+ private Shape3D[] compressGeomShape3Ds = null;
/** Transform to World Coordinates */
- Transform3D localToVWorld = null;
+ private Transform3D localToVWorld = null;
/** the pick shape to use for intersections */
- PickShape pickShape = null;
+ private PickShape pickShape = null;
/* data derived from the pick shape */
- int pickShapeType = -1;
- Vector3d pickShapeDir = null;
- Point3d pickShapeStart = null;
- Point3d pickShapeEnd = null;
- Bounds pickShapeBounds = null;
+ private int pickShapeType = -1;
+ private Vector3d pickShapeDir = null;
+ private Point3d pickShapeStart = null;
+ private Point3d pickShapeEnd = null;
+ private Bounds pickShapeBounds = null;
static final Point3d zeroPnt = new Point3d();
- /** ArrayList to store intersection results */
+ /** ArrayList to store intersection results
+ * Used in PickTool
+ */
ArrayList intersections = null;
// internal constants used for intersections
@@ -1816,6 +1818,10 @@ public class PickResult {
Point4d tP4d = new Point4d();
Vector4d[] planes = new Vector4d [polytope.getNumPlanes()];
+
+ for(int i=0; i<planes.length; i++)
+ planes[i]=new Vector4d();
+
polytope.getPlanes (planes);
if (coordinates.length == 2) {
@@ -2680,7 +2686,7 @@ public class PickResult {
isIntersect = ((t > -EPS) && (t < 1+EPS));
break;
} else {
- lastSign = 0; //degenerate line=>point
+ //degenerate line=>point
}
}
}
@@ -2712,7 +2718,7 @@ public class PickResult {
isIntersect = ((t > -EPS) && (t < 1+EPS));
break;
} else {
- lastSign = 0; //degenerate line=>point
+ //degenerate line=>point
}
}
}
@@ -2744,7 +2750,7 @@ public class PickResult {
isIntersect = ((t > -EPS) && (t < 1+EPS));
break;
} else {
- lastSign = 0; //degenerate line=>point
+ //degenerate line=>point
}
}
}
@@ -2774,7 +2780,7 @@ public class PickResult {
isIntersect = ((t > -EPS) && (t < 1+EPS));
break;
} else {
- lastSign = 0; //degenerate line=>point
+ //degenerate line=>point
}
}
}
@@ -2985,7 +2991,7 @@ public class PickResult {
pi.setDistance(0);
}
}
- freeVector3d(lDir);
+ //freeVector3d(lDir);
return isIntersect;
}
// Find the inverse.
@@ -3325,19 +3331,21 @@ public class PickResult {
}
static Vector3d getVector3d() {
- return (Vector3d)UtilFreelistManager.vector3dFreelist.getObject();
+ //return (Vector3d)UtilFreelistManager.vector3dFreelist.getObject();
+ return new Vector3d();
}
static void freeVector3d(Vector3d v) {
- UtilFreelistManager.vector3dFreelist.add(v);
+ //UtilFreelistManager.vector3dFreelist.add(v);
}
static Point3d getPoint3d() {
- return (Point3d)UtilFreelistManager.point3dFreelist.getObject();
+ //return (Point3d)UtilFreelistManager.point3dFreelist.getObject();
+ return new Point3d();
}
static void freePoint3d(Point3d p) {
- UtilFreelistManager.point3dFreelist.add(p);
+ //UtilFreelistManager.point3dFreelist.add(p);
}
diff --git a/src/classes/share/com/sun/j3d/utils/picking/PickTool.java b/src/classes/share/com/sun/j3d/utils/picking/PickTool.java
index 0397a8c..9c8461f 100644
--- a/src/classes/share/com/sun/j3d/utils/picking/PickTool.java
+++ b/src/classes/share/com/sun/j3d/utils/picking/PickTool.java
@@ -212,9 +212,20 @@ public class PickTool {
* Returns the Locale to be picked if the tool was initialized with
* a Locale, null otherwise.
*/
- public Locale setBranchGroup (Locale l) {
+ public Locale getLocale () {
return pickRootL;
}
+
+
+ /**
+ * This method is not supported.
+ *
+ * @exception UnsupportedOperationException this method is not supported
+ *
+ */
+ public Locale setBranchGroup (Locale l) {
+ throw new UnsupportedOperationException();
+ }
/**
* Sets the capabilities on the Node and it's components to allow
@@ -1007,16 +1018,17 @@ p @param end The end of the segment
}
PickResult getPickResult(SceneGraphPath spg, PickShape ps) {
- PickResult pr = (PickResult)UtilFreelistManager.pickResultFreelist.getObject();
- if (pr == null) {
- pr = new PickResult();
- }
- pr.reset(spg, ps);
+ //PickResult pr = (PickResult)UtilFreelistManager.pickResultFreelist.getObject();
+ PickResult pr = new PickResult(spg,ps);
+// if (pr == null) {
+// pr = new PickResult();
+// }
+// pr.reset(spg, ps);
return pr;
}
void freePickResult(PickResult pr) {
- UtilFreelistManager.pickResultFreelist.add(pr);
+ //UtilFreelistManager.pickResultFreelist.add(pr);
}
} // PickTool
diff --git a/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/SimpleDistanceComparator.java b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/SimpleDistanceComparator.java
new file mode 100644
index 0000000..410b6b4
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/SimpleDistanceComparator.java
@@ -0,0 +1,89 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.scenegraph.transparency;
+
+import java.util.Comparator;
+import javax.media.j3d.Transform3D;
+
+/**
+ * Sample TransparencySortComparator which has the same functionality as
+ * the fixed default function in Java 3D.
+ *
+ * @since Java 3D 1.4
+ */
+public class SimpleDistanceComparator implements Comparator {
+
+ /** Creates a new instance of SimpleDistanceComparator */
+ public SimpleDistanceComparator() {
+ }
+
+ /**
+ * Compares its two arguments for order. Returns a negative integer, zero,
+ * or a positive integer as the first argument is less than (closer to the viewer),
+ * equal to, or greater than (further from the viewer) the second argument.
+ *
+ * The compare method will be called with 2 objects of type
+ * TransparencySortGeom and it's result should indicate which object is
+ * closer to the viewer. Object1 < Object2 if it is to be considered closer
+ * and rendered after.
+ *
+ * @param o1 TransparencySortGeom object 1
+ * @param o2 TransparencySortGeom object 2
+ *
+ */
+ public int compare(Object o1, Object o2) {
+ TransparencySortGeom t1 = (TransparencySortGeom)o1;
+ TransparencySortGeom t2 = (TransparencySortGeom)o2;
+
+ double f = t1.getDistanceSquared()-t2.getDistanceSquared();
+ if (f<0)
+ return -1;
+ if (f==0)
+ return 0;
+
+ return 1;
+ }
+
+}
diff --git a/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java
new file mode 100644
index 0000000..e8e56a3
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortController.java
@@ -0,0 +1,98 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.scenegraph.transparency;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import javax.media.j3d.View;
+
+/**
+ * This class controls the Transparency Sorting scheme used by Java 3D when
+ * rendering transparent objects. By default (and in all previous versions of
+ * Java 3D) objects are sorted depending on the distance from the viewer of the
+ * centroid of their bounds. By supplying a different Comparator for a view using
+ * the static setComparator method the user can provide their own sorting scheme.
+ *
+ * The Comparator provided will be called with 2 objects of class
+ * TransparencySortGeom.
+ *
+ * @since Java 3D 1.4
+ */
+public class TransparencySortController {
+
+ private static HashMap comparators = new HashMap();
+
+ /**
+ * Set the comparator for the specified view.
+ *
+ * The comparators compare method will be called with 2 objects of type
+ * TransparencySortGeom and it's result should indicate which object is
+ * closer to the viewer. Object1 < Object2 if it is to be considered closer
+ * and rendered after.
+ *
+ * @param view the view to which the comparator applies
+ * @param comparator the comparator to call
+ */
+ public static void setComparator(View view, Comparator comparator) {
+ comparators.put(view, comparator);
+ }
+
+ /**
+ * Returns the comparator for the specified view
+ *
+ * @return the comparator for the specified view, or null if there
+ * is no comparator for the view or the view is unknown.
+ */
+ public static Comparator getComparator(View view) {
+ Object ret = null;
+
+ ret = comparators.get(view);
+
+ if (ret!=null)
+ return (Comparator)ret;
+
+ return null;
+ }
+}
diff --git a/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortGeom.java b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortGeom.java
new file mode 100644
index 0000000..c9a55d5
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/scenegraph/transparency/TransparencySortGeom.java
@@ -0,0 +1,90 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.scenegraph.transparency;
+import javax.media.j3d.Geometry;
+import javax.media.j3d.Shape3D;
+import javax.media.j3d.Transform3D;
+
+/**
+ *
+ * The interface of the objects that should be compared to determine
+ * rendering order of transparent objects.
+ *
+ * The Comparator supplied by the user in TransparencySortController will
+ * be called with 2 objects that implement this interface.
+ *
+ * @since Java 3D 1.4
+ */
+public interface TransparencySortGeom {
+
+ /**
+ * Returns the Geometry for this object.
+ *
+ * @return geometry for this object
+ */
+ public Geometry getGeometry();
+
+ /**
+ * Returns the distance squared of this object to the viewer.
+ *
+ * @return distancesquared to viewer
+ */
+ public double getDistanceSquared();
+
+ /**
+ * Returns the LocalToVWorld transform for this object
+ *
+ * @param localToVW variable in which transform will be returned
+ */
+ public void getLocalToVWorld(Transform3D localToVW);
+
+ /**
+ * Returns the Shape3D being rendered using this geometry.
+ *
+ * @return the Shape3D being rendered using this geometry
+ */
+ public Shape3D getShape3D();
+
+}
diff --git a/src/classes/share/com/sun/j3d/utils/shader/StringIO.java b/src/classes/share/com/sun/j3d/utils/shader/StringIO.java
new file mode 100644
index 0000000..1ef0519
--- /dev/null
+++ b/src/classes/share/com/sun/j3d/utils/shader/StringIO.java
@@ -0,0 +1,158 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any
+ * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
+ * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
+ * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
+ * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
+ * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
+ * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
+ * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
+ * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
+ * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed, licensed or
+ * intended for use in the design, construction, operation or
+ * maintenance of any nuclear facility.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package com.sun.j3d.utils.shader;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+/**
+ * Utility class with static methods to read the entire contents of a
+ * file, URL, InputStream, or Reader into a single String that is
+ * returned to the user.
+ *
+ * @since Java 3D 1.4
+ */
+public class StringIO {
+ /**
+ * Read the entire contents of the specified file and return a
+ * single String object containing the contents of the file.
+ *
+ * @param fileName the name of the file from which to read
+ *
+ * @return a String containing the contents of the input file
+ *
+ * @throws IOException if the specified file cannot be opened, or
+ * if an I/O error occurs while reading the file
+ */
+ public static String readFully(String fileName) throws IOException {
+ return readFully(new File(fileName));
+ }
+
+ /**
+ * Read the entire contents of the specified file and return a
+ * single String object containing the contents of the file.
+ * This method does not return until the end of the input file
+ * is reached.
+ *
+ * @param file a File from which to read
+ *
+ * @return a String containing the contents of the input file
+ *
+ * @throws IOException if the specified file cannot be opened, or
+ * if an I/O error occurs while reading the file
+ */
+ public static String readFully(File file) throws IOException {
+ return readFully(new FileReader(file));
+ }
+
+ /**
+ * Read the entire contents of the specified URL and return a
+ * single String object containing the contents of the URL.
+ * This method does not return until an end of stream is reached
+ * for the URL.
+ *
+ * @param url a URL from which to read
+ *
+ * @return a String containing the contents of the input URL
+ *
+ * @throws IOException if the specified URL cannot be opened, or
+ * if an I/O error occurs while reading the URL
+ */
+ public static String readFully(URL url) throws IOException {
+ return readFully(url.openStream());
+ }
+
+ /**
+ * Read the entire contents of the specified InputStream and return a
+ * single String object containing the contents of the InputStream.
+ * This method does not return until the end of the input
+ * stream is reached.
+ *
+ * @param stream an InputStream from which to read
+ *
+ * @return a String containing the contents of the input stream
+ *
+ * @throws IOException if an I/O error occurs while reading the input stream
+ */
+ public static String readFully(InputStream stream) throws IOException {
+ return readFully(new InputStreamReader(stream));
+ }
+
+ /**
+ * Read the entire contents of the specified Reader and return a
+ * single String object containing the contents of the InputStream.
+ * This method does not return until the end of the input file or
+ * stream is reached.
+ *
+ * @param reader a Reader from which to read
+ *
+ * @return a String containing the contents of the stream
+ *
+ * @throws IOException if an I/O error occurs while reading the input stream
+ */
+ public static String readFully(Reader reader) throws IOException {
+ char[] arr = new char[8*1024]; // 8K at a time
+ StringBuffer buf = new StringBuffer();
+ int numChars;
+
+ while ((numChars = reader.read(arr, 0, arr.length)) > 0) {
+ buf.append(arr, 0, numChars);
+ }
+
+ return buf.toString();
+ }
+
+
+ /**
+ * Do not construct an instance of this class.
+ */
+ private StringIO() {
+ }
+}
diff --git a/src/classes/share/com/sun/j3d/utils/universe/SimpleUniverse.java b/src/classes/share/com/sun/j3d/utils/universe/SimpleUniverse.java
index 1bd0f7b..506ad8e 100644
--- a/src/classes/share/com/sun/j3d/utils/universe/SimpleUniverse.java
+++ b/src/classes/share/com/sun/j3d/utils/universe/SimpleUniverse.java
@@ -403,9 +403,23 @@ public class SimpleUniverse extends VirtualUniverse {
* Typically it should be invoked by the applet's destroy method.
*/
public void cleanup() {
- viewer[0].getView().removeAllCanvas3Ds();
+ // Get view associated with this SimpleUniverse
+ View view = viewer[0].getView();
+
+ // Issue 134: cleanup all off-screen canvases
+ for (int i = view.numCanvas3Ds() - 1; i >= 0; i--) {
+ Canvas3D c = view.getCanvas3D(i);
+ if (c.isOffScreen()) {
+ c.setOffScreenBuffer(null);
+ }
+ }
+
+ // Remove all canvases from view; remove the viewing platform from
+ // this viewer; remove all locales to cleanup the scene graph
+ view.removeAllCanvas3Ds();
viewer[0].setViewingPlatform(null);
removeAllLocales();
+
// viewerMap cleanup here to prevent memory leak problem.
Viewer.clearViewerMap();
Primitive.clearGeometryCache();