Hi Allistair, I'm not a Java3D engineer, but this is how I would do this, * The behaviour should wake up on the following AWT events: MouseEvent.MOUSE_PRESSED, KeyEvent.KEY_PRESSED, KeyEvent.KEY_RELEASED * In the processStimulus method: ~ On receiving a KEY_PRESSED record the key code of the KeyEvent in some variable (say keyCode). ~ On receiving a KEY_RELEASED make the keyCode = -1, to signify that nothing is pressed. ~ On receiving a MOUSE_PRESSED do something depending on keyCode. I've attached some source code. Regards, Renoir "Crossley, Allistair" wrote: > Will you all join me in asking a Java3D engineer(s) to demonstrate with code > how to write a picking behaviour that only wakes up on left click whist a > character key "A-Z" is depressed. > > All the examples with Java3D are with Alt or Control but these are useless > for big applications except for zoom and translate. Besides, there are > special functions in the events classes that can detect these being down at > the time of the click too which makes these easier. > > Anyone in favour of a concrete example from the makers of J3D say "Aye". > > Cheers, > > Allistair Crossley > Web/New Media Consultant > Logica UK Ltd > Tel: 02074 463267 > Mob: 07884 056274 > > -----Original Message----- > From: Karsten Fries [mailto:[EMAIL PROTECTED]] > Sent: 22 May 2001 09:24 > To: [EMAIL PROTECTED] > Subject: [JAVA3D] Mouse events > > Hi there, > > another mouse question. > I have the problem that I use left mouse click for selecting objects and > left mouse double-click for zooming > in. In big complex scenes the picking stuff is very computation > intensive and therefore takes a while (in the range of a second is > the max we can tolerate), but anyway the double click is not produced if > it takes too long. > > Rephrased: if i double-click on a complex object (say build of 30000 > triangles) I get two mouse click events with > clickCount() == 1 instead of one with cC==1 and a secong with cC == 2. > > Pitty!! > > Is there any way of getting around this. I already rearranged the mouse > controls, but I'm always running in some > problems concering this issue. > > Any help is appreciated!! > > Thanks and cheers, > Karsten > > =========================================================================== > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff JAVA3D-INTEREST". For general help, send email to > [EMAIL PROTECTED] and include in the body of the message "help". > > =========================================================================== > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff JAVA3D-INTEREST". For general help, send email to > [EMAIL PROTECTED] and include in the body of the message "help". -- Renoir Sewjee Software Engineer ISS International (Welkom) Tel: +27 (0)57 912 2702 Fax: +27 (0)57 912 2652 --
/** * Picks a point in the virtual world. * */ import java.awt.AWTEvent; import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; import java.util.Enumeration; import java.util.ArrayList; import com.sun.j3d.utils.picking.PickCanvas; import com.sun.j3d.utils.picking.PickResult; import com.sun.j3d.utils.picking.PickIntersection; import javax.media.j3d.Behavior; import javax.media.j3d.BranchGroup; import javax.media.j3d.WakeupOnAWTEvent; import javax.media.j3d.WakeupCriterion; import javax.media.j3d.WakeupCondition; import javax.media.j3d.WakeupOr; import javax.media.j3d.Canvas3D; import javax.vecmath.Point3d; import javax.vecmath.Point3f; import java.util.ArrayList; import java.util.Iterator; import com.sun.j3d.utils.picking.PickTool; public class Picker extends Behavior { private PickCanvas pickCanvas; private WakeupCondition wakeupCondition; private int currentKeyPressed = -1; public Picker(Canvas3D canvas, BranchGroup scene) { pickCanvas = new PickCanvas(canvas, scene); pickCanvas.setTolerance(3.0f); pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO); } public void initialize() { WakeupCriterion[] wakeups = new WakeupCriterion[3]; wakeups[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED); wakeups[1] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED); wakeups[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED); wakeupCondition = new WakeupOr(wakeups); wakeupOn(wakeupCondition); } public void processStimulus(Enumeration criteria) { while (criteria.hasMoreElements()) { WakeupCriterion wakeup = (WakeupCriterion)criteria.nextElement(); if (wakeup instanceof WakeupOnAWTEvent) { AWTEvent[] events = ((WakeupOnAWTEvent)wakeup).getAWTEvent(); if (events.length > 0) { if (events[events.length-1] instanceof KeyEvent) { KeyEvent event = (KeyEvent)events[events.length-1]; int id = event.getID(); if (id == KeyEvent.KEY_PRESSED) { currentKeyPressed = event.getKeyCode(); } else { currentKeyPressed = -1; } } else if (events[events.length-1] instanceof MouseEvent && currentKeyPressed != -1) { MouseEvent event = (MouseEvent)events[events.length-1]; int id = event.getID(); int mod = event.getModifiers(); if (mod == MouseEvent.BUTTON1_MASK) { if (id == MouseEvent.MOUSE_PRESSED) { pickCanvas.setShapeLocation(event.getX(), event.getY()); Point3d eyePos = pickCanvas.getStartPosition(); PickResult pickResult = pickCanvas.pickClosest(); if (pickResult != null) { PickIntersection pickIntersection = pickResult.getClosestIntersection(eyePos); Point3d pickedPoint = pickIntersection.getPointCoordinatesVW(); if (currentKeyPressed == KeyEvent.VK_A) System.err.println("Pressed A"); else if (currentKeyPressed == KeyEvent.VK_B) System.err.println("Pressed B"); else System.err.println("Pressed Something Else"); System.err.println(pickedPoint); System.err.println(); } else { System.err.println("No point picked"); System.err.println(); } } } } } } } wakeupOn(wakeupCondition); } }