Fullscreen & mouse cursor

Hi,

I’m pretty new to Panda and I’m trying to create something similar to a FPS in fullscreen on Mac. I did some search in the forums and read some topics, but I still don’t fully understand what’s happening.

I’m trying to start directly in fullscreen with the following code:

    WindowFramework * win;
    NodePath environ;
    
    framework.open_framework(argc, argv);
    framework.set_window_title("Panda3D Tests");
    
    GraphicsPipe *gp = framework.get_default_pipe();
    
    WindowProperties wp = WindowProperties::get_config_properties();
    wp.set_fullscreen(true);
    wp.set_cursor_hidden(true);
    wp.set_origin(0, 0);
    wp.set_mouse_mode(WindowProperties::M_relative);
    wp.set_size(gp->get_display_width(), gp->get_display_height());

    win = framework.open_window(wp, GraphicsPipe::BF_require_window);

The application starts in fullscreen, the cursor is not hidden (somehow acceptable) and it’s not locked.

If I change the code to start in a normal window and then set it to full screen the cursor is still not hidden, but it’s locked somewhere on the screen:

    WindowFramework * win;
    NodePath environ;
    
    framework.open_framework(argc, argv);
    framework.set_window_title("Panda3D Tests");
    
    GraphicsPipe *gp = framework.get_default_pipe();
        
    win = framework.open_window();
    const WindowProperties wp = win->get_graphics_window()->get_properties();
    WindowProperties wpx = WindowProperties(wp);

    wpx.set_fullscreen(true);
    wpx.set_size(gp->get_display_width(), gp->get_display_height());
    wpx.set_cursor_hidden(true);
    wpx.set_mouse_mode(WindowProperties::M_relative);
    win->get_graphics_window()->request_properties(wpx);

This happens when I’m not using in my camera task the move_pointer(…) to try to lock the cursor. If I use the move_pointer(…) in the first version the cursor is still not locked and in the second one is locked in the center of the screen. Why the differences? Is there something I’m not doing? I’ve tried comparing the windows’ properties in both cases and they seem to be the same.

The thing is I want it locked (in the center of the screen), but directly starting full screen (first version of code). Is this possible? How?

My camera rotation task looks like below (with or without move_pointer(…)):

AsyncTask::DoneStatus CamRotationTask(GenericAsyncTask * task, void * data) {
    int cursorX, cursorY;
    
    WindowFramework * win = framework.get_window(0);
    NodePath cam = framework.get_window(0)->get_camera_group();
    
    //Get cursor position
    cursorX = win->get_graphics_window()->get_pointer(0).get_x();
    cursorY = win->get_graphics_window()->get_pointer(0).get_y();
    
    if (!init) {
        oldX = cursorX;
        oldY = cursorY;
        init = true;
    }
        
    //Update the rotation angles
    alpha -= (cursorX - oldX) * CAM_SPEED_ROT;
    beta -= (cursorY - oldY) * CAM_SPEED_ROT;

    oldX = cursorX;
    oldY = cursorY;

    //Apply rotation to camera
    cam.set_hpr(alpha, beta, 0.0f);
    
    //Reset the cursor to its default position (middle of the window)
    //win->get_graphics_window()->move_pointer(0, (int)(win->get_graphics_window()->get_x_size() / 2), (int)(win->get_graphics_window()->get_y_size() / 2));
    
    return AsyncTask::DS_cont;
}

Also, how do I replace the mouse pointer with a crosshair/target?

Thanks & best regards,
Dumi.

I’ve managed to start in fullscreen and hide the cursor:

    WindowFramework * win;
    NodePath environ;
    
    framework.open_framework(argc, argv);
    framework.set_window_title("Panda3D Tests");
    
    GraphicsPipe *gp = framework.get_default_pipe();
    
    WindowProperties props;
    framework.get_default_window_props(props);
    props.set_fullscreen(true);
    props.set_origin(0, 0);
    props.set_mouse_mode(WindowProperties::M_relative);
    props.set_size(gp->get_display_width(), gp->get_display_height());

    win = framework.open_window(props, 0);    

    props = WindowProperties(win->get_graphics_window()->get_properties());
    props.set_cursor_hidden(true);
    
    win->get_graphics_window()->request_properties(props);

But the mouse cursor is still not locked in the center of the screen… But do I need this anymore? Or can I just show the crosshair/target using the camera ray or something?

Thanks,
D.

M_relative won’t necessarily constrain the cursor to the centre of the screen, but it should make sure that the mouse position won’t be limited by the bounds of the window, ie it can go infinitely in any direction. You should hide the mouse cursor because it has no real purpose in M_relative mod.