ruby_rpg 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/engine/components/orthographic_camera.rb +2 -2
- data/lib/engine/engine.rb +2 -10
- data/lib/engine/game_object.rb +23 -7
- data/lib/engine/input.rb +43 -0
- data/lib/engine/quaternion.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73ebf7bd3a497f3da5bb8bf0c953da36446ef912edede3605ae811a7d7778c21
|
4
|
+
data.tar.gz: 2c6d68447ef0502ca2d19020659bf09b1821fec4ff741ee5901a142358513701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc07ac48782722967f54d33c0aa633891f1f585557b6cb9427cf0d4ae711b5869c318631f17fd90ef5e82fbdfcf6946542e8cf0874b438aa2165818f601bb20d
|
7
|
+
data.tar.gz: da7fb040ce08572ff69666fe850a3d2bc6d0dd326b040e1c8772f2c4891cef54550baf18d2c558e29b1e9b5ed983a0b016eea6d5345137faaf878bcbbe28d350
|
@@ -33,8 +33,8 @@ module Engine::Components
|
|
33
33
|
@right = nil if game_object.rotation != @rotation
|
34
34
|
@up = nil if game_object.rotation != @rotation
|
35
35
|
@front = nil if game_object.rotation != @rotation
|
36
|
-
@matrix = nil if game_object.rotation.
|
37
|
-
@rotation = game_object.rotation.
|
36
|
+
@matrix = nil if game_object.rotation.dup != @rotation
|
37
|
+
@rotation = game_object.rotation.dup
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
data/lib/engine/engine.rb
CHANGED
@@ -19,11 +19,11 @@ module Engine
|
|
19
19
|
def self.open_window
|
20
20
|
@old_time = Time.now
|
21
21
|
@time = Time.now
|
22
|
-
@key_callback = create_key_callbacks # This must be an instance variable to prevent garbage collection
|
23
22
|
|
24
23
|
Window.create_window
|
25
24
|
GLFW.MakeContextCurrent(Window.window)
|
26
|
-
|
25
|
+
|
26
|
+
Input.init
|
27
27
|
GL.load_lib
|
28
28
|
|
29
29
|
set_opengl_blend_mode
|
@@ -34,8 +34,6 @@ module Engine
|
|
34
34
|
GL.CullFace(GL::BACK)
|
35
35
|
|
36
36
|
GLFW.SwapInterval(0)
|
37
|
-
|
38
|
-
Cursor.hide
|
39
37
|
end
|
40
38
|
|
41
39
|
def self.main_game_loop(&first_frame_block)
|
@@ -130,10 +128,4 @@ module Engine
|
|
130
128
|
GL.Enable(GL::BLEND)
|
131
129
|
GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA)
|
132
130
|
end
|
133
|
-
|
134
|
-
def self.create_key_callbacks
|
135
|
-
GLFW::create_callback(:GLFWkeyfun) do |window, key, scancode, action, mods|
|
136
|
-
Input.key_callback(key, action)
|
137
|
-
end
|
138
|
-
end
|
139
131
|
end
|
data/lib/engine/game_object.rb
CHANGED
@@ -8,15 +8,17 @@ module Engine
|
|
8
8
|
@methods.add(name)
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_accessor :name, :pos, :
|
11
|
+
attr_accessor :name, :pos, :scale, :components, :renderers, :ui_renderers, :created_at, :parent
|
12
12
|
|
13
13
|
def initialize(name = "Game Object", pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], parent: nil)
|
14
14
|
GameObject.object_spawned(self)
|
15
15
|
@pos = Vector[pos[0], pos[1], pos[2] || 0]
|
16
16
|
if rotation.is_a?(Numeric)
|
17
|
-
|
17
|
+
self.rotation = Quaternion.from_euler(Vector[0, 0, rotation])
|
18
|
+
elsif rotation.is_a?(Quaternion)
|
19
|
+
self.rotation = rotation
|
18
20
|
else
|
19
|
-
|
21
|
+
self.rotation = Quaternion.from_euler(rotation)
|
20
22
|
end
|
21
23
|
@scale = scale
|
22
24
|
@name = name
|
@@ -50,6 +52,20 @@ module Engine
|
|
50
52
|
parent.children << self if parent
|
51
53
|
end
|
52
54
|
|
55
|
+
def rotation
|
56
|
+
@rotation_quaternion
|
57
|
+
end
|
58
|
+
|
59
|
+
def rotation=(value)
|
60
|
+
raise "Rotation must be a Quaternion" unless value.is_a?(Quaternion)
|
61
|
+
|
62
|
+
@rotation_quaternion = value
|
63
|
+
end
|
64
|
+
|
65
|
+
def euler_angles
|
66
|
+
rotation.to_euler
|
67
|
+
end
|
68
|
+
|
53
69
|
def x
|
54
70
|
@pos[0]
|
55
71
|
end
|
@@ -93,16 +109,16 @@ module Engine
|
|
93
109
|
def rotate_around(axis, angle)
|
94
110
|
rotation_quaternion = Quaternion.from_angle_axis(angle, axis)
|
95
111
|
|
96
|
-
|
112
|
+
self.rotation = rotation_quaternion * rotation
|
97
113
|
end
|
98
114
|
|
99
115
|
def model_matrix
|
100
|
-
cache_key = [@pos.dup,
|
116
|
+
cache_key = [@pos.dup, rotation.dup, @scale.dup, @parent&.model_matrix&.to_a]
|
101
117
|
@model_matrix = nil if @model_matrix_cache_key != cache_key
|
102
118
|
@model_matrix_cache_key = cache_key
|
103
119
|
@model_matrix ||=
|
104
120
|
begin
|
105
|
-
rot =
|
121
|
+
rot = euler_angles * Math::PI / 180
|
106
122
|
|
107
123
|
cos_x = Math.cos(rot[0])
|
108
124
|
cos_y = Math.cos(rot[1])
|
@@ -186,7 +202,7 @@ module Engine
|
|
186
202
|
GameObject.objects.each do |object|
|
187
203
|
object.components.each { |component| component.update(delta_time) }
|
188
204
|
end
|
189
|
-
|
205
|
+
|
190
206
|
Component.erase_destroyed_components
|
191
207
|
GameObject.erase_destroyed_objects
|
192
208
|
end
|
data/lib/engine/input.rb
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
|
3
3
|
module Engine
|
4
4
|
class Input
|
5
|
+
def self.init
|
6
|
+
@key_callback = GLFW::create_callback(:GLFWkeyfun) do |window, key, scancode, action, mods|
|
7
|
+
Input.key_callback(key, action)
|
8
|
+
end
|
9
|
+
GLFW.SetKeyCallback(Window.window, @key_callback)
|
10
|
+
|
11
|
+
@cursor_pos_callback = GLFW::create_callback(:GLFWcursorposfun) do |window, x, y|
|
12
|
+
Input.mouse_callback(x, y)
|
13
|
+
end
|
14
|
+
GLFW.SetCursorPosCallback(Window.window, @cursor_pos_callback)
|
15
|
+
|
16
|
+
@mouse_button_callback = GLFW::create_callback(:GLFWmousebuttonfun) do |window, button, action, mods|
|
17
|
+
Input.mouse_button_callback(button, action)
|
18
|
+
end
|
19
|
+
GLFW.SetMouseButtonCallback(Window.window, @mouse_button_callback)
|
20
|
+
end
|
21
|
+
|
5
22
|
def self.key?(key)
|
6
23
|
keys[key] == :down || keys[key] == :held
|
7
24
|
end
|
@@ -14,6 +31,17 @@ module Engine
|
|
14
31
|
keys[key] == :up
|
15
32
|
end
|
16
33
|
|
34
|
+
def self.mouse_pos
|
35
|
+
@mouse_pos
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.mouse_delta
|
39
|
+
return Vector[0, 0] if @old_mouse_pos.nil?
|
40
|
+
return Vector[0, 0] unless @mouse_pos_updated
|
41
|
+
|
42
|
+
@mouse_pos - @old_mouse_pos
|
43
|
+
end
|
44
|
+
|
17
45
|
def self._on_key_down(key)
|
18
46
|
keys[key] = :down
|
19
47
|
if key == GLFW::KEY_ESCAPE
|
@@ -42,7 +70,22 @@ module Engine
|
|
42
70
|
end
|
43
71
|
end
|
44
72
|
|
73
|
+
def self.mouse_callback(x, y)
|
74
|
+
@mouse_pos_updated = true
|
75
|
+
@old_mouse_pos = @mouse_pos
|
76
|
+
@mouse_pos = Vector[x, y]
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.mouse_button_callback(button, action)
|
80
|
+
if action == GLFW::PRESS
|
81
|
+
keys[button] = :down
|
82
|
+
elsif action == GLFW::RELEASE
|
83
|
+
keys[button] = :up
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
45
87
|
def self.update_key_states
|
88
|
+
@mouse_pos_updated = false
|
46
89
|
keys.each do |key, state|
|
47
90
|
if state == :down
|
48
91
|
keys[key] = :held
|
data/lib/engine/quaternion.rb
CHANGED
@@ -16,6 +16,12 @@ module Engine
|
|
16
16
|
"Quaternion(w: #{@w}, x: #{@x}, y: #{@y}, z: #{@z})"
|
17
17
|
end
|
18
18
|
|
19
|
+
def ==(other)
|
20
|
+
return false unless other.is_a?(Quaternion)
|
21
|
+
|
22
|
+
@w == other.w && @x == other.x && @y == other.y && @z == other.z
|
23
|
+
end
|
24
|
+
|
19
25
|
def *(other)
|
20
26
|
Quaternion.new(
|
21
27
|
@w * other.w - @x * other.x - @y * other.y - @z * other.z,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_rpg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Hatfull
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: native_audio
|