Mercurial > games > semicongine
comparison semiconginev2/input.nim @ 1254:b0f4c8ccd49a
did: stuff to test gltf importer
author | sam <sam@basx.dev> |
---|---|
date | Sat, 27 Jul 2024 20:47:54 +0700 |
parents | 56781cc0fc7c |
children | bfb75c934f4e |
comparison
equal
deleted
inserted
replaced
1253:c4f98eb4bb05 | 1254:b0f4c8ccd49a |
---|---|
9 mousePosition: Vec2f | 9 mousePosition: Vec2f |
10 mouseMove: Vec2f | 10 mouseMove: Vec2f |
11 mouseWheel: float32 | 11 mouseWheel: float32 |
12 windowWasResized: bool = true | 12 windowWasResized: bool = true |
13 windowIsMinimized: bool = false | 13 windowIsMinimized: bool = false |
14 lockMouse: bool = false | |
14 | 15 |
15 # warning, shit is not thread safe | 16 # warning, shit is not thread safe |
16 var input: Input | 17 var input: Input |
17 | 18 |
18 proc UpdateInputs*(): bool = | 19 proc UpdateInputs*(): bool = |
22 input.mouseWasPressed = {} | 23 input.mouseWasPressed = {} |
23 input.mouseWasReleased = {} | 24 input.mouseWasReleased = {} |
24 input.mouseWheel = 0 | 25 input.mouseWheel = 0 |
25 input.mouseMove = NewVec2f() | 26 input.mouseMove = NewVec2f() |
26 input.windowWasResized = false | 27 input.windowWasResized = false |
28 | |
29 if input.lockMouse: | |
30 SetMousePosition(vulkan.window, x=int(vulkan.swapchain.width div 2), y=int(vulkan.swapchain.height div 2)) | |
27 | 31 |
28 var killed = false | 32 var killed = false |
29 for event in vulkan.window.PendingEvents(): | 33 for event in vulkan.window.PendingEvents(): |
30 case event.eventType: | 34 case event.eventType: |
31 of Quit: | 35 of Quit: |
70 proc MouseReleasedButtons*(): set[MouseButton] = input.mouseWasReleased | 74 proc MouseReleasedButtons*(): set[MouseButton] = input.mouseWasReleased |
71 proc MousePosition*(): Vec2f = input.mousePosition | 75 proc MousePosition*(): Vec2f = input.mousePosition |
72 proc MousePositionNormalized*(size: (int, int)): Vec2f = | 76 proc MousePositionNormalized*(size: (int, int)): Vec2f = |
73 result.x = (input.mousePosition.x / float32(size[0])) * 2.0 - 1.0 | 77 result.x = (input.mousePosition.x / float32(size[0])) * 2.0 - 1.0 |
74 result.y = (input.mousePosition.y / float32(size[1])) * 2.0 - 1.0 | 78 result.y = (input.mousePosition.y / float32(size[1])) * 2.0 - 1.0 |
75 proc MouseMove*(): auto = input.mouseMove | 79 proc MouseMove*(): Vec2f = input.mouseMove |
76 proc MouseWheel*(): auto = input.mouseWheel | 80 proc MouseWheel*(): float32 = input.mouseWheel |
77 proc WindowWasResized*(): auto = input.windowWasResized | 81 proc WindowWasResized*(): auto = input.windowWasResized |
78 proc WindowIsMinimized*(): auto = input.windowIsMinimized | 82 proc WindowIsMinimized*(): auto = input.windowIsMinimized |
83 proc LockMouse*(value: bool) = input.lockMouse = value | |
84 | |
79 | 85 |
80 # actions as a slight abstraction over raw input | 86 # actions as a slight abstraction over raw input |
81 | 87 |
82 type | 88 type |
83 ActionMap = object | 89 ActionMap = object |