Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with MOUSE_MOVE & MOUSE_WHEEL behaviors with J3D  (Read 1387 times)
0 Members and 1 Guest are viewing this topic.
Offline Thirg

Senior Newbie





« Posted 2006-02-23 20:59:15 »

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...

[size=8pt]public class Test3D extends Applet implements Runnable
{   
........more code, scenegraph setup etc.

<snippet of mouse behavior creation>

        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.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;
                   
                    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 );
    }
}[/size]



Offline Thirg

Senior Newbie





« Reply #1 - Posted 2006-02-24 16:51:15 »

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

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

1  
2  
3  
4  
public class Test extends Applet implements MouseWheelListener, MouseListener, MouseMotionListener
{
.....
}


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

1  
2  
3  
4  
        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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
    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...
Offline otelo

Junior Devvie





« Reply #2 - Posted 2006-02-27 11:34:46 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Thirg

Senior Newbie





« Reply #3 - Posted 2006-02-28 10:43:53 »

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...
Offline otelo

Junior Devvie





« Reply #4 - Posted 2006-02-28 11:28:01 »

How is this a hack?
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.
Offline Breakfast

Senior Devvie




for great justice!


« Reply #5 - Posted 2006-02-28 12:50:10 »

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.
Offline Thirg

Senior Newbie





« Reply #6 - Posted 2006-02-28 17:05:32 »

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...
Offline Breakfast

Senior Devvie




for great justice!


« Reply #7 - Posted 2006-02-28 18:18:41 »

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?
Offline Thirg

Senior Newbie





« Reply #8 - Posted 2006-02-28 19:09:26 »

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

Thirg...

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!