Problem with MOUSE_MOVE & MOUSE_WHEEL behaviors with J3D

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 );
}

}

I solved this in a completely different way than coded above…

I implemented MouseWheelListener, MouseMoveListener and a MouseListener on the Applet.

public class Test extends Applet implements MouseWheelListener, MouseListener, MouseMotionListener
{
.....
}

Then I added the listeners too the canvas3D of the Applet…

        canvas3D.addKeyListener( this );
        canvas3D.addMouseListener( this );
        canvas3D.addMouseWheelListener( this );
        canvas3D.addMouseMotionListener( this );

…from there on it was just a case of implementing the methods for each Listener within the applet class and everything seemed to work fine.

    public void mouseWheelMoved(MouseWheelEvent e) 
    {
// mouse wheel code goes ere etc.... and same for all methods below
    }
    
    public void mousePressed(MouseEvent e)
    {
    }

    public void mouseClicked(MouseEvent e)
    {
    }
    
    public void mouseReleased(MouseEvent e)
    {
    }
 
    public void mouseEntered(MouseEvent e)
    {
    }
    
    public void mouseExited(MouseEvent e)
    {
    }
 
    public void mouseMoved(MouseEvent e)
    {
    }
    
    public void mouseDragged(MouseEvent e)
    {      
    }[

Thirg…

Your solution is a hack, not the correct way of doing this. Have you not forgotten to attached your Behaviour to your scenegraph? Happened to me the first time.

How is this a hack? From my understanding I have setup listeners here, not a behavior linked into the scenegraph.

Granted I have not posted my code that is within the listening methods, getting the mouse buttons, positions, wheel etc.

The implementation works 100%, could you please outline where I have gone wrong?

Thanks,

Thirg…

Naaah, I’m just teasing you.
All the Java3d evangelists would tell you to process events inside of Behaviours but I haven’t seen the implementation of your listener methods anyhow.

My understanding is that you can listen with whatever you want as long as your listener is calling your behaviours to change the scene rather than interfering with it directly.

So I can’t listen for some mouse input, then manipulate a TransformGroup within the scenegraph however I choose based on the input from the Listener? I “must” use a behavior to do this? Call me crazy, but why? My listeners & manipulating a TransformGroup work fine, even in a sandbox environment under Windows, Linux and Mac OS, I am befuddled why I need to do it differently?

I had behaviors working, as per my first example, but I got zero response from the mouse_move or mouse_wheel events… thus I starting using the listeners.

Thirg…

Basically behaviours talk to Java3d on it’s terms. You can mess around with stuff without using them but it’s not the way it’s designed to work - so when J3D is drawing a frame it performs a whole series of actions, one of which is carrying out behaviours- if you are wrangling your scene around without using them then your changes could be taking place at any point in the rendering sequence which can have unforseen circumstances- particularly if the API moves on a version you may find that because it’s not designed for “random at any time” update methods your way of doing things doesn’t work any more.

What you can do is generate an event manually from your MouseListener if your mouse events aren’t being picked up by the MouseBehaviour and then have a behaviour that listens for your manually generated event. It’s not as elegant as a working MouseBehaviour would be but if your tests are correct then you don’t have one of those to start with. Have you looked at the source of the MouseBehaviour to see where the problem could be coming from?

Thanks for your reply Breakfast :), this also describes another slight issue I have noticed but couldn’t put my finger on.

Thirg…