Hi,
I’m having some problems handling mouse_move and mouse_wheel events using J3D behaviors.
The code below shows my mouse class, with a paste of the scenegraph setup for the mouse behavior.
The project needs to run in an Applet, and can only use J3D, can anyone please tell me while I am not recieving the mouse_move and/or the mouse_wheel events when I am getting the mouse_pressed, mouse_dragged and mouse_released events without a problem?
Many thanks
Thirg…
public class Test3D extends Applet implements Runnable
{
…more code, scenegraph setup etc.
TransformGroup mouse_trans = new TransformGroup();
Mouse mouse = new Mouse( this );
mouse.setTransformGroup(m_mouse_trans);
m_mouse.setSchedulingBounds(new BoundingSphere());
scene.addChild(m_mouse);
…more code etc.
}
Mouse Behavior class…
public class Mouse extends MouseBehavior
{
public Mouse( InputMgr input_mgr )
{
super( 0 );
m_input_mgr = input_mgr;
}
public void initialize()
{
super.initialize();
}
public void processStimulus( Enumeration criteria )
{
WakeupCriterion wakeup = null;
AWTEvent[] event = null;
// Process all pending wakeups
while( criteria.hasMoreElements( ) )
{
wakeup = (WakeupCriterion)criteria.nextElement( );
if ( wakeup instanceof WakeupOnAWTEvent )
{
event = ((WakeupOnAWTEvent)wakeup).getAWTEvent( );
// Process all pending events
for ( int i = 0; i < event.length; i++ )
{
int event_id = event[i].getID();
if ( event_id != MouseEvent.MOUSE_PRESSED &&
event_id != MouseEvent.MOUSE_RELEASED &&
event_id != MouseEvent.MOUSE_WHEEL &&
event_id != MouseEvent.MOUSE_MOVED &&
event_id != MouseEvent.MOUSE_DRAGGED )
// Ignore uninteresting mouse events
continue;
MouseEvent e = (MouseEvent)event[i];
switch( event_id )
{
case MouseEvent.MOUSE_WHEEL:
System.out.printf( "MOUSE_WHEEL EVENT\n");
break;
case MouseEvent.MOUSE_PRESSED:
System.out.printf( "MOUSE_PRESSED EVENT\n");
break;
case MouseEvent.MOUSE_RELEASED:
System.out.printf( "MOUSE_RELEASED EVENT\n");
break;
case MouseEvent.MOUSE_DRAGGED:
System.out.printf( "MOUSE_DRAGGED EVENT\n");
break;
}
}
}
}
// Reschedule us for another wakeup
wakeupOn( mouseCriterion );
}
}