ruby_rpg 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/engine/components/orthographic_camera.rb +7 -7
- data/lib/engine/components/perspective_camera.rb +11 -12
- data/lib/engine/components/point_light.rb +1 -1
- data/lib/engine/components/spot_light.rb +1 -1
- data/lib/engine/game_object.rb +18 -10
- data/lib/engine/standard_objects/cube.rb +2 -1
- data/lib/engine/standard_objects/plane.rb +2 -1
- data/lib/engine/standard_objects/sphere.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 007b1e3b07b58938d2ef46f760a57bcff8ea430db434db6be96804453e864839
|
|
4
|
+
data.tar.gz: 54ba403b3ba8bfa5b5c0a1a9e537b6acce9dcaa20460354592ab1cb738fa617c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce867115127c2b89fde8c2cc9de02c8d4cb76b73358e5104d75889d886cf5780db38c2a7ce925480e364d3ca3c2d08adc2cfc822daf38b7e462e0d32b2795b6e
|
|
7
|
+
data.tar.gz: 46dfa2e1f02498f220f825efcdbaa9ebf97a1133f58e019fd2ee1c92efd38ae4731e454cb35606f5aaf588a707fbc08b997a01e61e8d9dee31201f8a729e7889
|
|
@@ -22,11 +22,12 @@ module Engine::Components
|
|
|
22
22
|
right = game_object.right
|
|
23
23
|
up = game_object.up
|
|
24
24
|
forward = game_object.forward
|
|
25
|
+
world_pos = game_object.world_pos
|
|
25
26
|
|
|
26
27
|
view_matrix = Matrix[
|
|
27
|
-
[right[0], right[1], right[2], -right.dot(
|
|
28
|
-
[up[0], up[1], up[2], -up.dot(
|
|
29
|
-
[forward[0], forward[1], forward[2], -forward.dot(
|
|
28
|
+
[right[0], right[1], right[2], -right.dot(world_pos)],
|
|
29
|
+
[up[0], up[1], up[2], -up.dot(world_pos)],
|
|
30
|
+
[forward[0], forward[1], forward[2], -forward.dot(world_pos)],
|
|
30
31
|
[0, 0, 0, 1]
|
|
31
32
|
]
|
|
32
33
|
|
|
@@ -39,7 +40,7 @@ module Engine::Components
|
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
def position
|
|
42
|
-
game_object.
|
|
43
|
+
game_object.world_pos
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def projection
|
|
@@ -49,12 +50,11 @@ module Engine::Components
|
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
def update(delta_time)
|
|
52
|
-
if game_object.
|
|
53
|
+
if game_object.world_transform_version != @cached_transform_version
|
|
53
54
|
@matrix = nil
|
|
54
55
|
@inverse_vp_matrix = nil
|
|
55
56
|
end
|
|
56
|
-
@
|
|
57
|
-
@pos = game_object.pos.dup
|
|
57
|
+
@cached_transform_version = game_object.world_transform_version
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
end
|
|
@@ -22,11 +22,12 @@ module Engine::Components
|
|
|
22
22
|
right = game_object.right
|
|
23
23
|
up = game_object.up
|
|
24
24
|
forward = game_object.forward
|
|
25
|
+
world_pos = game_object.world_pos
|
|
25
26
|
|
|
26
27
|
transformation_matrix = Matrix[
|
|
27
|
-
[right[0], right[1], right[2], -right.dot(
|
|
28
|
-
[up[0], up[1], up[2], -up.dot(
|
|
29
|
-
[forward[0], forward[1], forward[2], -forward.dot(
|
|
28
|
+
[right[0], right[1], right[2], -right.dot(world_pos)],
|
|
29
|
+
[up[0], up[1], up[2], -up.dot(world_pos)],
|
|
30
|
+
[forward[0], forward[1], forward[2], -forward.dot(world_pos)],
|
|
30
31
|
[0, 0, 0, 1]
|
|
31
32
|
]
|
|
32
33
|
|
|
@@ -41,7 +42,7 @@ module Engine::Components
|
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def position
|
|
44
|
-
game_object.
|
|
45
|
+
game_object.world_pos
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
def projection
|
|
@@ -53,24 +54,22 @@ module Engine::Components
|
|
|
53
54
|
right = game_object.right
|
|
54
55
|
up = game_object.up
|
|
55
56
|
forward = game_object.forward
|
|
56
|
-
|
|
57
|
+
world_pos = game_object.world_pos
|
|
57
58
|
|
|
58
59
|
Matrix[
|
|
59
|
-
[right[0], right[1], right[2], -right.dot(
|
|
60
|
-
[up[0], up[1], up[2], -up.dot(
|
|
61
|
-
[forward[0], forward[1], forward[2], -forward.dot(
|
|
60
|
+
[right[0], right[1], right[2], -right.dot(world_pos)],
|
|
61
|
+
[up[0], up[1], up[2], -up.dot(world_pos)],
|
|
62
|
+
[forward[0], forward[1], forward[2], -forward.dot(world_pos)],
|
|
62
63
|
[0, 0, 0, 1]
|
|
63
64
|
].transpose
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
def update(delta_time)
|
|
67
|
-
if game_object.
|
|
68
|
+
if game_object.world_transform_version != @cached_transform_version
|
|
68
69
|
@matrix = nil
|
|
69
70
|
@inverse_vp_matrix = nil
|
|
70
71
|
end
|
|
71
|
-
@
|
|
72
|
-
@pos = game_object.pos.dup
|
|
73
|
-
@scale = game_object.scale.dup
|
|
72
|
+
@cached_transform_version = game_object.world_transform_version
|
|
74
73
|
end
|
|
75
74
|
end
|
|
76
75
|
end
|
data/lib/engine/game_object.rb
CHANGED
|
@@ -145,6 +145,11 @@ module Engine
|
|
|
145
145
|
@local_version += 1
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
+
def world_pos
|
|
149
|
+
m = model_matrix
|
|
150
|
+
@cached_world_pos ||= Vector[m[3, 0], m[3, 1], m[3, 2]]
|
|
151
|
+
end
|
|
152
|
+
|
|
148
153
|
def local_to_world_coordinate(local)
|
|
149
154
|
local_x4 = Matrix[[local[0], local[1], local[2], 1.0]]
|
|
150
155
|
world = local_x4 * model_matrix
|
|
@@ -158,7 +163,7 @@ module Engine
|
|
|
158
163
|
end
|
|
159
164
|
|
|
160
165
|
def local_to_world_direction(local)
|
|
161
|
-
local_to_world_coordinate(local) -
|
|
166
|
+
local_to_world_coordinate(local) - world_pos
|
|
162
167
|
end
|
|
163
168
|
|
|
164
169
|
def rotate_around(axis, angle)
|
|
@@ -175,6 +180,12 @@ module Engine
|
|
|
175
180
|
current_version = world_transform_version
|
|
176
181
|
return @cached_world_matrix if @cached_world_version == current_version
|
|
177
182
|
|
|
183
|
+
# Invalidate derived caches
|
|
184
|
+
@cached_world_pos = nil
|
|
185
|
+
@cached_right = nil
|
|
186
|
+
@cached_up = nil
|
|
187
|
+
@cached_forward = nil
|
|
188
|
+
|
|
178
189
|
@cached_world_version = current_version
|
|
179
190
|
@cached_world_matrix = compute_world_matrix
|
|
180
191
|
end
|
|
@@ -241,21 +252,18 @@ module Engine
|
|
|
241
252
|
end
|
|
242
253
|
|
|
243
254
|
def up
|
|
244
|
-
|
|
245
|
-
@
|
|
246
|
-
@up = local_to_world_direction(Vector[0, 1, 0])
|
|
255
|
+
model_matrix
|
|
256
|
+
@cached_up ||= local_to_world_direction(Vector[0, 1, 0])
|
|
247
257
|
end
|
|
248
258
|
|
|
249
259
|
def right
|
|
250
|
-
|
|
251
|
-
@
|
|
252
|
-
@right = local_to_world_direction(Vector[1, 0, 0])
|
|
260
|
+
model_matrix
|
|
261
|
+
@cached_right ||= local_to_world_direction(Vector[1, 0, 0])
|
|
253
262
|
end
|
|
254
263
|
|
|
255
264
|
def forward
|
|
256
|
-
|
|
257
|
-
@
|
|
258
|
-
@forward = local_to_world_direction(Vector[0, 0, 1])
|
|
265
|
+
model_matrix
|
|
266
|
+
@cached_forward ||= local_to_world_direction(Vector[0, 0, 1])
|
|
259
267
|
end
|
|
260
268
|
|
|
261
269
|
def self.destroy_all
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module Engine
|
|
4
4
|
module StandardObjects
|
|
5
5
|
module Cube
|
|
6
|
-
def self.create(pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], material: nil)
|
|
6
|
+
def self.create(pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], material: nil, parent: nil)
|
|
7
7
|
Engine::GameObject.create(
|
|
8
8
|
name: "Cube",
|
|
9
9
|
pos: pos,
|
|
10
10
|
rotation: rotation,
|
|
11
11
|
scale: scale,
|
|
12
|
+
parent: parent,
|
|
12
13
|
components: [
|
|
13
14
|
Engine::Components::MeshRenderer.create(
|
|
14
15
|
mesh: Engine::Mesh.for("cube", source: :engine),
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module Engine
|
|
4
4
|
module StandardObjects
|
|
5
5
|
module Plane
|
|
6
|
-
def self.create(pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], material: nil)
|
|
6
|
+
def self.create(pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], material: nil, parent: nil)
|
|
7
7
|
Engine::GameObject.create(
|
|
8
8
|
name: "Plane",
|
|
9
9
|
pos: pos,
|
|
10
10
|
rotation: rotation,
|
|
11
11
|
scale: scale,
|
|
12
|
+
parent: parent,
|
|
12
13
|
components: [
|
|
13
14
|
Engine::Components::MeshRenderer.create(
|
|
14
15
|
mesh: Engine::Mesh.for("plane", source: :engine),
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
module Engine
|
|
4
4
|
module StandardObjects
|
|
5
5
|
module Sphere
|
|
6
|
-
def self.create(pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], material: nil)
|
|
6
|
+
def self.create(pos: Vector[0, 0, 0], rotation: 0, scale: Vector[1, 1, 1], components: [], material: nil, parent: nil)
|
|
7
7
|
Engine::GameObject.create(
|
|
8
8
|
name: "Sphere",
|
|
9
9
|
pos: pos,
|
|
10
10
|
rotation: rotation,
|
|
11
11
|
scale: scale,
|
|
12
|
+
parent: parent,
|
|
12
13
|
components: [
|
|
13
14
|
Engine::Components::MeshRenderer.create(
|
|
14
15
|
mesh: Engine::Mesh.for("sphere", source: :engine),
|