Kha icon indicating copy to clipboard operation
Kha copied to clipboard

Pointer Lock?

Open sixFingers opened this issue 8 years ago • 6 comments

I'm writing something that resembles a first person camera controller, and I have a hard time figuring out how the pointer lock API works. I'm targeting CPP (but I'm having issues with Javascript too). I tried both kha.input.Mouse.get().lock(); and kha.SystemImpl.lockMouse();, any pointer would be greatly appreciated!

sixFingers avatar Jan 10 '18 17:01 sixFingers

There was some issue recently which also talked about why there is lock and lockMouse - I still have to investigate myself, didn't originally write the mouse lock code. Meanwhile, please tell us about your target system.

RobDangerous avatar Jan 10 '18 17:01 RobDangerous

Thanks for your super-fast reply! I can't get it to work on both HTML 5 (when running in default debug mode from Kode) and CPP (Mac OS Sierra). On CPP I noticed that mouse position gets refreshed when the cursor is outside the window and direction of movement isn't beyond my screen bounds. On HTML 5 I see no difference at all (system cursor is visible, movement is ignored if cursor is outside the window). I'm very new to Kha, so I might be misunderstanding something. Apart from that, it's a pleasure to work with ;)

sixFingers avatar Jan 10 '18 17:01 sixFingers

In HTML5, you can call Pointer Lock only after user events (mouse/keyboard/etc). Please check if this html5 demo worked for you. If not, please tell your browser too.

RblSb avatar Jan 11 '18 02:01 RblSb

I also couldn't get pointer lock working properly in HTML5 semi-recently (during a game jam, so didn't have time to sort it out on Kha's end). You can see what I ended up doing which worked a treat here: https://github.com/BlazingMammothGames/xkcdgamejam/blob/master/Sources/Game.hx#L135-L152

hamaluik avatar Mar 01 '18 05:03 hamaluik

I was the original author of mouse lock stuff (with a working implementation on html5 and a barely working one on windows) It was using SystemImpl.hx only : https://github.com/Kode/Kha/pull/757/files

@RblSb seems to have added the function on the Mouse class here : https://github.com/Kode/Kha/pull/705/files

Then there is the latest change by @luboslenco : https://github.com/Kode/Kha/pull/757

I guess SystemImpl was required to get access to the canvas.

wighawag avatar Mar 01 '18 07:03 wighawag

Pointer lock on macos requires kinc_mouse_set_position implementation, which requires internal window handle like on windows (to get x/y window offset). https://github.com/Kode/Kinc/blob/naster/Backends/System/macOS/Sources/Kore/Input/Mouse.mm#L28 https://github.com/Kode/Kinc/blob/master/Backends/System/Windows/Sources/Kore/Window.c#L38

RblSb avatar Aug 18 '19 19:08 RblSb