Mouse Delta in FB Pixeln, statt Fenster Px
This commit is contained in:
@@ -67,7 +67,8 @@ fn main() {
|
||||
- `set_mouse_capture(bool)` – Cursor einsperren + verstecken (`CursorMode::Disabled`),
|
||||
liefert unbegrenzte Bewegungsdeltas. Impliziert `mouse_visible = false`.
|
||||
- `mouse_delta() -> (f32, f32)` – akkumulierte Mausbewegung seit dem letzten Aufruf
|
||||
in Window-Pixeln, danach genullt. Nützlich für FPS-Kamerasteuerung.
|
||||
in Framebuffer-Pixeln (gleiche Skala wie `MouseMove`), danach genullt. Nützlich
|
||||
für FPS-Kamerasteuerung.
|
||||
|
||||
### Cursor-Modi
|
||||
|
||||
|
||||
+12
-8
@@ -255,8 +255,9 @@ impl Platform {
|
||||
self.window.set_cursor_mode(mode);
|
||||
}
|
||||
|
||||
/// Akkumulierte Mausbewegung seit dem letzten Aufruf, in Window-Pixeln.
|
||||
/// Bei `set_mouse_capture(true)` liefert GLFW unbegrenzte Deltas (FPS-Stil).
|
||||
/// Akkumulierte Mausbewegung seit dem letzten Aufruf, in Framebuffer-Pixeln
|
||||
/// (gleiche Skala wie `Event::MouseMove`). Bei `set_mouse_capture(true)`
|
||||
/// liefert GLFW unbegrenzte Deltas (FPS-Stil).
|
||||
pub fn mouse_delta(&mut self) -> (f32, f32) {
|
||||
std::mem::replace(&mut self.mouse_delta, (0.0, 0.0))
|
||||
}
|
||||
@@ -357,16 +358,19 @@ impl Platform {
|
||||
}
|
||||
W::Char(c) => self.event_queue.push_back(Event::Char(c)),
|
||||
W::CursorPos(x, y) => {
|
||||
let (cx, cy, cw, ch) = self.content_rect;
|
||||
let (fw, fh) = self.framebuffer_size;
|
||||
let sx = fw as f64 / cw as f64;
|
||||
let sy = fh as f64 / ch as f64;
|
||||
|
||||
if let Some((lx, ly)) = self.last_cursor_pos {
|
||||
self.mouse_delta.0 += (x - lx) as f32;
|
||||
self.mouse_delta.1 += (y - ly) as f32;
|
||||
self.mouse_delta.0 += ((x - lx) * sx) as f32;
|
||||
self.mouse_delta.1 += ((y - ly) * sy) as f32;
|
||||
}
|
||||
self.last_cursor_pos = Some((x, y));
|
||||
|
||||
let (cx, cy, cw, ch) = self.content_rect;
|
||||
let (fw, fh) = self.framebuffer_size;
|
||||
let fx = ((x - cx as f64) / cw as f64 * fw as f64) as f32;
|
||||
let fy = ((y - cy as f64) / ch as f64 * fh as f64) as f32;
|
||||
let fx = ((x - cx as f64) * sx) as f32;
|
||||
let fy = ((y - cy as f64) * sy) as f32;
|
||||
self.event_queue.push_back(Event::MouseMove { x: fx, y: fy });
|
||||
}
|
||||
W::MouseButton(btn, action, _) => if let Some(button) = from_glfw_button(btn) {
|
||||
|
||||
Reference in New Issue
Block a user