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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6334c6764856a6865332a3e5763760cd92caf56d7d7860657059f27cc7b16daa
4
- data.tar.gz: c96b3e9f508da06d0ad90bfa271ec9114ad89ce6a62dbfb0047f350e6b82aaed
3
+ metadata.gz: 007b1e3b07b58938d2ef46f760a57bcff8ea430db434db6be96804453e864839
4
+ data.tar.gz: 54ba403b3ba8bfa5b5c0a1a9e537b6acce9dcaa20460354592ab1cb738fa617c
5
5
  SHA512:
6
- metadata.gz: 965c114ae4bcc2cf4444e34317fd2e282b900bda0f37a61e675423e82eada8027bbddbb28e84f38df6b56ae0dbe6ef1e6a5d5b17fc9c1b5e0975ad98cb830871
7
- data.tar.gz: 4ee3ca2aafeacece9beeee37ee2b89ebe71cbe31ee551da4f5e2142169a89b59006bec3c158fe676be22a13e914d96aa2cc94cddde6b9eb8fab484165349b316
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(game_object.pos)],
28
- [up[0], up[1], up[2], -up.dot(game_object.pos)],
29
- [forward[0], forward[1], forward[2], -forward.dot(game_object.pos)],
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.pos
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.rotation != @rotation || game_object.pos != @pos
53
+ if game_object.world_transform_version != @cached_transform_version
53
54
  @matrix = nil
54
55
  @inverse_vp_matrix = nil
55
56
  end
56
- @rotation = game_object.rotation.dup
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(game_object.pos)],
28
- [up[0], up[1], up[2], -up.dot(game_object.pos)],
29
- [forward[0], forward[1], forward[2], -forward.dot(game_object.pos)],
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.pos
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
- pos = game_object.pos
57
+ world_pos = game_object.world_pos
57
58
 
58
59
  Matrix[
59
- [right[0], right[1], right[2], -right.dot(pos)],
60
- [up[0], up[1], up[2], -up.dot(pos)],
61
- [forward[0], forward[1], forward[2], -forward.dot(pos)],
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.rotation != @rotation || game_object.pos != @pos || game_object.scale != @scale
68
+ if game_object.world_transform_version != @cached_transform_version
68
69
  @matrix = nil
69
70
  @inverse_vp_matrix = nil
70
71
  end
71
- @rotation = game_object.rotation.dup
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
@@ -41,7 +41,7 @@ module Engine::Components
41
41
  end
42
42
 
43
43
  def position
44
- game_object.local_to_world_coordinate(Vector[0, 0, 0])
44
+ game_object.world_pos
45
45
  end
46
46
 
47
47
  def shadow_near
@@ -48,7 +48,7 @@ module Engine::Components
48
48
  end
49
49
 
50
50
  def position
51
- game_object.local_to_world_coordinate(Vector[0, 0, 0])
51
+ game_object.world_pos
52
52
  end
53
53
 
54
54
  def light_space_matrix
@@ -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) - local_to_world_coordinate(Vector[0, 0, 0])
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
- return @up if @cached_up_rotation == rotation
245
- @cached_up_rotation = rotation.dup
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
- return @right if @cached_right_rotation == rotation
251
- @cached_right_rotation = rotation.dup
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
- return @forward if @cached_forward_rotation == rotation
257
- @cached_forward_rotation = rotation.dup
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),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_rpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Hatfull