From 53ebfcc5ad5554b67d2287f8b02c22ec8405af0f Mon Sep 17 00:00:00 2001 From: kcr Date: Wed, 9 Jun 2004 03:28:13 +0000 Subject: Initial creation of j3d-examples sources in CVS repository --- src/PickTest/IntersectInfoBehavior.java | 254 ++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 src/PickTest/IntersectInfoBehavior.java (limited to 'src/PickTest/IntersectInfoBehavior.java') diff --git a/src/PickTest/IntersectInfoBehavior.java b/src/PickTest/IntersectInfoBehavior.java new file mode 100644 index 0000000..226c6a4 --- /dev/null +++ b/src/PickTest/IntersectInfoBehavior.java @@ -0,0 +1,254 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 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$ + */ + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.media.j3d.*; +import javax.vecmath.*; +import com.sun.j3d.utils.picking.*; +import com.sun.j3d.utils.geometry.*; + +/** + * Class: IntersectInfoBehavior + * + * Description: Used to respond to mouse pick and drag events + * in the 3D window. Displays information about the pick. + * + * Version: 1.0 + * + */ +public class IntersectInfoBehavior extends Behavior { + + float size; + PickCanvas pickCanvas; + PickResult[] pickResult; + Appearance oldlook, redlookwf, redlook, greenlook, bluelook; + Node oldNode = null; + GeometryArray oldGeom = null; + Color3f redColor = new Color3f (1.0f, 0.0f, 0.0f); + TransformGroup[] sphTrans = new TransformGroup [6]; + Sphere[] sph = new Sphere [6]; + Transform3D spht3 = new Transform3D(); + + public IntersectInfoBehavior(Canvas3D canvas3D, BranchGroup branchGroup, + float size) { + pickCanvas = new PickCanvas(canvas3D, branchGroup); + pickCanvas.setTolerance(5.0f); + pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO); + this.size = size; + // Create an Appearance. + redlook = new Appearance(); + Color3f objColor = new Color3f(0.5f, 0.0f, 0.0f); + Color3f black = new Color3f(0.0f, 0.0f, 0.0f); + Color3f white = new Color3f(1.0f, 1.0f, 1.0f); + redlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f)); + redlook.setCapability (Appearance.ALLOW_MATERIAL_WRITE); + + redlookwf = new Appearance (); + redlookwf.setMaterial(new Material(objColor, black, objColor, white, 50.0f)); + PolygonAttributes pa = new PolygonAttributes(); + pa.setPolygonMode(pa.POLYGON_LINE); + pa.setCullFace(pa.CULL_NONE); + redlookwf.setPolygonAttributes(pa); + + oldlook = new Appearance(); + objColor = new Color3f(1.0f, 1.0f, 1.0f); + oldlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f)); + + greenlook = new Appearance(); + objColor = new Color3f(0.0f, 0.8f, 0.0f); + greenlook.setMaterial(new Material(objColor, black, objColor, white, 50.0f)); + bluelook = new Appearance(); + objColor = new Color3f(0.0f, 0.0f, 0.8f); + bluelook.setMaterial(new Material(objColor, black, objColor, white, 50.0f)); + for (int i=0;i<6;i++) { + switch (i) { + case 0: + sph[i] = new Sphere(size*1.15f, redlook); + break; + case 1: + sph[i] = new Sphere(size*1.1f, greenlook); + break; + default: + sph[i] = new Sphere(size, bluelook); + break; + } + sph[i].setPickable (false); + sphTrans[i] = new TransformGroup (); + sphTrans[i].setCapability (TransformGroup.ALLOW_TRANSFORM_READ); + sphTrans[i].setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE); + + // Add sphere, transform + branchGroup.addChild (sphTrans[i]); + sphTrans[i].addChild (sph[i]); + } + } + + public void initialize() { + wakeupOn (new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED)); + } + + public void processStimulus (Enumeration criteria) { + WakeupCriterion wakeup; + AWTEvent[] event; + int eventId; + + while (criteria.hasMoreElements()) { + wakeup = (WakeupCriterion) criteria.nextElement(); + if (wakeup instanceof WakeupOnAWTEvent) { + event = ((WakeupOnAWTEvent)wakeup).getAWTEvent(); + for (int i=0; i