Problem with mouseWatcher in C++

I am using Pandora v1.9.0 , Ubuntu and the C++ API.
I have the same problem explained here: I cannot get the values of the pointer of the mouse using the MouseWatcher.
When I call the function mouseWatcher->has_mouse() I get always 0.

 
NodePath mouseNode = window->get_mouse();

MouseWatcher* mouseWatcher = dynamic_cast<MouseWatcher*>(mouseNode.node()); 

std::cout << "Has_mouse" << mouseWatcher->has_mouse() << std::endl;

here the complete code.

Instead If I use the function:

window->get_graphics_window()->get_pointer(0).get_x()

I get the correct result.

In Python the MouseWatcher is working properly (for example in the example Ball-in-Maze ).

        # Read the mouse position and tilt the maze accordingly
        if base.mouseWatcherNode.hasMouse():
            mpos = base.mouseWatcherNode.getMouse()  # get the mouse position
            self.maze.setP(mpos.getY() * -10)
            self.maze.setR(mpos.getX() * 10)

Any Idea?

Thank you in advance

Hmm, it actually works fine for me. I compiled the code on Linux and I can push around a sphere with a sphere that is being controlled by the mouse.

Note that has_mouse() will only return 1 when the mouse is inside the window.

For what it’s worth, I recommend using Panda’s dcast mechanism for dynamic casting, which uses Panda’s typing system rather than relying on RTTI:

MouseWatcher *mouseWatcher = DCAST(MouseWatcher, mouseNode.node());