getting mouse coordinates

Hey there

How do I get mouse coordinated under C++? I can see only python example in manual, and can’t find similar functions in include files.

I’m trying to get coordinates so I can move actor (player) with mouse, but also with some restrictions (only one axis for example). If someone know the way to do it, please tell me too.

I’ve translated the relevant part of that manual chapter to c++.

Basically:

if (mouseWatcher->has_mouse()){
  // It's a good idea to check that the window hasn't just been closed,
  // otherwise you could get an assertion on exit.
  if (window){
    int x = window->get_graphics_window()->get_pointer(0).get_x();
    int y = window->get_graphics_window()->get_pointer(0).get_y();
  }
}

EDIT: Actually, in my code I also check that get_graphics_window() doesn’t return null first, this is what I do:

    if (mouseWatcher->has_mouse()){
        if (window){
            GraphicsWindow *gwin = window->get_graphics_window();
            if (gwin){
                thisMouseX = gwin->get_pointer(0).get_x();
                thisMouseY = gwin->get_pointer(0).get_y();
            }
        }
    }

I did that to avoid an assertion, but I don’t remember if I got the assertion on window == NULL or on graphicWindow == NULL.

Thanks for help :slight_smile: It’s working