1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Mouse wheel and middle mouse button to control camera
16 module camera_control_linux
21 redef class EulerCamera
23 # Zoom factor, default at 1.2, higher means more reactive zoom effect
24 var camera_zoom_mod
= 1.2 is writable
26 # Scoll trigger button mask from SDL2 (1: left, 2: middle, 4: right)
28 # Set to 0 to deactivate the scrolling feature.
29 var camera_pan_mask
= 2 is writable
31 redef fun accept_scroll_and_zoom
(event
)
34 if event
isa GamnitMouseWheelEvent then
36 var mod
= camera_zoom_mod
38 # Zoom in when moving the wheel up
42 position
.z
*= dy
* mod
47 var but_mask
= camera_pan_mask
48 if but_mask
!= 0 and event
isa GamnitPointerEvent then
49 var native
= event
.native
50 if native
isa SDLMouseMotionEvent and native
.state
& but_mask
== but_mask
then
51 var dx
= native
.xrel
.to_f
52 var dy
= native
.yrel
.to_f
54 var world_height
= field_of_view_y
.sin
* position
.z
55 var mod
= app
.display
.as(not null).height
.to_f
/ world_height
56 position
.x
-= dx
/ mod
57 position
.y
+= dy
/ mod
# Y is inverted between the input and output