簡體   English   中英

如何在 Glium + Glutin 中獲得鼠標 X 和 Y?

[英]How can I get the mouse X and Y in Glium + Glutin?

我使用 Glium 編寫了一個游戲,當檢測到點擊時,我必須在特定位置渲染圖像。 為此,我需要獲取 X 和 Y 位置。 那么我該如何獲得它們呢?

我當前的代碼如下所示:

/* ... */
event.run(move |event, _, control_flow| {
    match event {
            glutin::event::Event::WindowEvent { event, .. } => match event {
                glutin::event::WindowEvent::CloseRequested => {
                   println!("Received termination signal.");
                  *control_flow = glutin::event_loop::ControlFlow::Exit;
                    return;
                },
                _ => return,
            },
            glutin::event::Event::NewEvents(cause) => match cause {
                glutin::event::StartCause::ResumeTimeReached { .. } => (),
                glutin::event::StartCause::Init => (),
                _ => return,
            },
            _ => return,
        }

如果可能的話,我不介意將 OpenGL 坐標設置為 X 和 Y (-1, 1),但我認為將它傳遞給頂點緩沖區會很麻煩。

這是我一直在尋找的答案,它是一個 WindowEvent:

match event {
            glutin::event::Event::WindowEvent { event, .. } => match event {
                glutin::event::WindowEvent::CloseRequested => {
                    println!("Received termination signal.");
                    *control_flow = glutin::event_loop::ControlFlow::Exit;
                    return;
                },
                /* The code to get the mouse position (And print it to the console) */
                glutin::event::WindowEvent::CursorMoved { position, .. } => {
                    println!("Mouse position: {:?}x{:?}", position.x as u16, position.y as u16);
                }
                _ => return,
            },
            /* Handle the rest of events */

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM