MouseWatcher in C++

Hi, how are you doing?
I’m trying to use the MouseWatcher object but I don’t know why most of the functions throws false or 0.
Letmme show you what I’m doing :slight_smile:

// In class as a property
MouseWatcher          *m_oMouseWatcher;

// In the init method of my class
MouseWatcher::init_type();
m_oMouseWatcher   = DCAST                     (MouseWatcher, m_oWindow->get_mouse().node());

// In different methods I'm calling from the main loop
m_nMouseX = m_oMouseWatcher->get_mouse_x();
m_nMouseY = m_oMouseWatcher->get_mouse_y();
m_bHasMouse = m_oMouseWatcher->has_mouse();

The first two methods (get_mouse_x() and get_mouse_y()) returns always 0 and the last one (has_mouse) gives me always false.

If I use m_oWindow->get_graphics_window()->get_pointer(0).get_x(); to get the x value instead using the mousewatcher it’s ok, it gaves me the x axis of the mouse but it’s very weird… does anyone knows what I’m doing wrong?

It sounds like the MouseWatcher node isn’t connected in the data graph properly. The data graph is a special graph of nodes, similar to the scene graph, but one in which parent-child relationships indicate the flow of data from the user. In general, parent nodes generate data and child nodes receive it.

In order to receive the mouse activity, the MouseWatcher node must be a child of the MouseAndKeyboard node.

Try putting:

notify-level-dgraph spam

in your Config.prc to show all of the datagraph operations. You should be able to run pview, for instance, with this enabled, and you’ll see the mouse data (among lots of other stuff) propagating through the data graph. Then try the same thing in your own application and see if you can tell what’s going on.

David

Hummm, it sais…

:dgraph(spam): MouseAndKeyboard mouse transmits:
pixel_size = 800 600
:dgraph(spam): MouseWatcher watcher (0 regions) receives:
pixel_size = 800 600
:dgraph(spam): MouseWatcher watcher (0 regions) transmits:
pixel_size = 800 600

But I cannot figure what’s going on… I’m too n00b @ Panda3d…

Ok, I’ve added a watcher region doing

MouseWatcherRegion *r = new MouseWatcherRegion("region", 0, 800, 600, 0);
r->set_active(true);
MouseWatcher::init_type();
m_oMouseWatcher   = DCAST                     (MouseWatcher, m_oWindow->get_mouse().node());
m_oMouseWatcher->add_region (r);

And now I get

:dgraph(spam): MouseAndKeyboard mouse transmits:
pixel_size = 800 600
pixel_xy = 799 16
xy = 0.9975 0.946667
:dgraph(spam): MouseWatcher watcher (1 regions) receives:
pixel_size = 800 600
pixel_xy = 799 16
xy = 0.9975 0.946667
:dgraph(spam): MouseWatcher watcher (1 regions) transmits:
pixel_size = 800 600
pixel_xy = 799 16
xy = 0.9975 0.946667

But I can’t get the get_mouse_x(), get_mouse_y() and has_mouse() work yet :frowning:

Are you sure you’re looking at the same MouseWatcher object that’s in the graph? That one certainly seems to be receiving mouse information.

David

Hummm, I’m using only one MouseWatcher pointer so I guess so…