-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_glfw.cr
56 lines (44 loc) · 1.24 KB
/
test_glfw.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require "./glfw_app"
require "./scene"
class TestApp < GlfwApp
def initialize
super
@speed = 3_f32
@mouse_speed = 0.05_f32
@scene = Scene.new
@scene.setup
GLFW.get_cursor_pos @window, out @last_xpos, out @last_ypos
end
def process_inputs(delta_time)
# process cursor position
GLFW.get_cursor_pos @window, out xpos, out ypos
@scene.horizontal_angle += @mouse_speed * delta_time * (@last_xpos - xpos)
@scene.vertical_angle += @mouse_speed * delta_time * (@last_ypos - ypos)
@last_xpos = xpos
@last_ypos = ypos
# process keys
if GLFW.get_key(@window, GLFW::KEY_W) == GLFW::PRESS
@scene.position += @scene.direction * delta_time * @speed
end
if GLFW.get_key(@window, GLFW::KEY_S) == GLFW::PRESS
@scene.position -= @scene.direction * delta_time * @speed
end
if GLFW.get_key(@window, GLFW::KEY_A) == GLFW::PRESS
@scene.position -= @scene.right * delta_time * @speed
end
if GLFW.get_key(@window, GLFW::KEY_D) == GLFW::PRESS
@scene.position += @scene.right * delta_time * @speed
end
end
def render_frame(delta_time)
@scene.render
end
def cleanup
@scene.cleanup
end
end
begin
TestApp.new.run
rescue ex
puts "FATAL ERROR: #{ex}"
end