gamnit :: camera_control_linux $ EulerCamera
Simple camera with perspective oriented with Euler angles (pitch, yaw, roll
)
gamnit :: camera_control_linux $ EulerCamera
Simple camera with perspective oriented with Euler angles (pitch, yaw, roll
)
egl
, sdl
and x11
Serializable::inspect
to show more useful information
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structureaccept_scroll_and_zoom
# Mouse wheel and middle mouse button to control camera
module camera_control_linux
import linux
import camera_control
redef class EulerCamera
# Zoom factor, default at 1.2, higher means more reactive zoom effect
var camera_zoom_mod = 1.2 is writable
# Scroll trigger button mask from SDL2 (1: left, 2: middle, 4: right)
#
# Set to 0 to deactivate the scrolling feature.
var camera_pan_mask = 2 is writable
redef fun accept_scroll_and_zoom(event)
do
# Zoom
if event isa GamnitMouseWheelEvent then
var dy = event.y
var mod = camera_zoom_mod
if dy > 0.0 then
# Zoom in when moving the wheel up
mod = 1.0/mod
else dy = -dy
position.z *= dy * mod
return true
end
# Scroll
var but_mask = camera_pan_mask
if but_mask != 0 and event isa GamnitPointerEvent then
var native = event.native
if native isa SDLMouseMotionEvent and native.state & but_mask == but_mask then
var dx = native.xrel.to_f
var dy = native.yrel.to_f
var world_height = field_of_view_y.sin * position.z
var mod = app.display.as(not null).height.to_f / world_height
position.x -= dx / mod
position.y += dy / mod # Y is inverted between the input and output
return true
end
end
return false
end
end
lib/gamnit/camera_control_linux.nit:15,1--64,3