cyberarm_engine 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/assets/textures/default.png +0 -0
- data/cyberarm_engine.gemspec +10 -8
- data/lib/cyberarm_engine.rb +13 -2
- data/lib/cyberarm_engine/animator.rb +6 -4
- data/lib/cyberarm_engine/background.rb +19 -15
- data/lib/cyberarm_engine/background_nine_slice.rb +125 -0
- data/lib/cyberarm_engine/bounding_box.rb +18 -18
- data/lib/cyberarm_engine/cache.rb +4 -0
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -0
- data/lib/cyberarm_engine/common.rb +13 -13
- data/lib/cyberarm_engine/config_file.rb +2 -2
- data/lib/cyberarm_engine/game_object.rb +63 -72
- data/lib/cyberarm_engine/game_state.rb +6 -3
- data/lib/cyberarm_engine/model.rb +207 -0
- data/lib/cyberarm_engine/model/material.rb +21 -0
- data/lib/cyberarm_engine/model/model_object.rb +131 -0
- data/lib/cyberarm_engine/model/parser.rb +74 -0
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -0
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -0
- data/lib/cyberarm_engine/model_cache.rb +31 -0
- data/lib/cyberarm_engine/opengl.rb +28 -0
- data/lib/cyberarm_engine/opengl/light.rb +50 -0
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -0
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -0
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -0
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -0
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +289 -0
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -0
- data/lib/cyberarm_engine/{shader.rb → opengl/shader.rb} +51 -43
- data/lib/cyberarm_engine/opengl/texture.rb +69 -0
- data/lib/cyberarm_engine/ray.rb +5 -5
- data/lib/cyberarm_engine/stats.rb +2 -2
- data/lib/cyberarm_engine/text.rb +41 -27
- data/lib/cyberarm_engine/timer.rb +1 -1
- data/lib/cyberarm_engine/transform.rb +43 -20
- data/lib/cyberarm_engine/ui/border_canvas.rb +4 -3
- data/lib/cyberarm_engine/ui/dsl.rb +25 -11
- data/lib/cyberarm_engine/ui/element.rb +30 -20
- data/lib/cyberarm_engine/ui/elements/button.rb +86 -16
- data/lib/cyberarm_engine/ui/elements/check_box.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/container.rb +44 -20
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +175 -2
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +121 -37
- data/lib/cyberarm_engine/ui/elements/flow.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/image.rb +12 -9
- data/lib/cyberarm_engine/ui/elements/label.rb +93 -14
- data/lib/cyberarm_engine/ui/elements/list_box.rb +64 -2
- data/lib/cyberarm_engine/ui/elements/progress.rb +5 -5
- data/lib/cyberarm_engine/ui/elements/radio.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/slider.rb +13 -16
- data/lib/cyberarm_engine/ui/elements/stack.rb +1 -1
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +27 -19
- data/lib/cyberarm_engine/ui/event.rb +7 -7
- data/lib/cyberarm_engine/ui/gui_state.rb +44 -10
- data/lib/cyberarm_engine/ui/style.rb +10 -9
- data/lib/cyberarm_engine/ui/theme.rb +28 -20
- data/lib/cyberarm_engine/vector.rb +33 -30
- data/lib/cyberarm_engine/version.rb +2 -2
- data/lib/cyberarm_engine/window.rb +27 -18
- metadata +65 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c56a2a5000efebf2274c880fed0b156ca41ed94216d7f3e7b5c15c24cc1cf2e
|
4
|
+
data.tar.gz: 7bbdf2cbf1812f8860411d53dcf99c8fcb90d286c130328cdf1d1570cb75df30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 626116a0cc8d2bdde83e7823ed604e67d573379277ac15be83c2f991c34e0f345c6ba286586125584eabb2e5bcf777a206b337903690ccb0cde09cb3a3504f67
|
7
|
+
data.tar.gz: 6f61c206112bfaf0885307ccb2cd9ae8aab9abc2ae70d167319866a735b8547500544a56f5c600c72c14003c4b9060db37a96bd958eab9ca88a346df3b04c004
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
Binary file
|
data/cyberarm_engine.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "cyberarm_engine/version"
|
5
4
|
|
@@ -9,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ["Cyberarm"]
|
10
9
|
spec.email = ["matthewlikesrobots@gmail.com"]
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
11
|
+
spec.summary = "Make games quickly and easily with gosu"
|
12
|
+
spec.description = "Yet another game making framework around gosu"
|
14
13
|
spec.homepage = "https://github.com/cyberarm/cyberarm_engine"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
@@ -21,17 +20,20 @@ Gem::Specification.new do |spec|
|
|
21
20
|
"public gem pushes."
|
22
21
|
end
|
23
22
|
|
24
|
-
spec.files
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
24
|
f.match(%r{^(test|spec|features)/})
|
26
25
|
end
|
27
26
|
spec.bindir = "exe"
|
28
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = %w[lib assets]
|
30
29
|
|
31
|
-
spec.add_dependency "
|
30
|
+
spec.add_dependency "clipboard", "~> 1.3.5"
|
31
|
+
spec.add_dependency "excon", "~> 0.78.0"
|
32
|
+
spec.add_dependency "gosu", "~> 1.0.0"
|
32
33
|
spec.add_dependency "gosu_more_drawables", "~> 0.3"
|
34
|
+
# spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
|
33
35
|
|
34
36
|
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
36
37
|
spec.add_development_dependency "minitest", "~> 5.0"
|
38
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
39
|
end
|
data/lib/cyberarm_engine.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
CYBERARM_ENGINE_ROOT_PATH = File.expand_path("..", __dir__)
|
2
|
+
|
1
3
|
begin
|
2
4
|
require File.expand_path("../../ffi-gosu/lib/gosu", File.dirname(__FILE__))
|
3
5
|
rescue LoadError => e
|
@@ -5,7 +7,9 @@ rescue LoadError => e
|
|
5
7
|
require "gosu"
|
6
8
|
end
|
7
9
|
require "json"
|
10
|
+
require "excon"
|
8
11
|
require "gosu_more_drawables"
|
12
|
+
require "clipboard"
|
9
13
|
|
10
14
|
require_relative "cyberarm_engine/version"
|
11
15
|
require_relative "cyberarm_engine/stats"
|
@@ -19,7 +23,6 @@ require_relative "cyberarm_engine/bounding_box"
|
|
19
23
|
require_relative "cyberarm_engine/vector"
|
20
24
|
require_relative "cyberarm_engine/transform"
|
21
25
|
require_relative "cyberarm_engine/ray"
|
22
|
-
require_relative "cyberarm_engine/shader" if defined?(OpenGL)
|
23
26
|
require_relative "cyberarm_engine/background"
|
24
27
|
require_relative "cyberarm_engine/animator"
|
25
28
|
|
@@ -35,9 +38,9 @@ require_relative "cyberarm_engine/ui/style"
|
|
35
38
|
require_relative "cyberarm_engine/ui/border_canvas"
|
36
39
|
require_relative "cyberarm_engine/ui/element"
|
37
40
|
require_relative "cyberarm_engine/ui/elements/label"
|
38
|
-
require_relative "cyberarm_engine/ui/elements/list_box"
|
39
41
|
require_relative "cyberarm_engine/ui/elements/button"
|
40
42
|
require_relative "cyberarm_engine/ui/elements/toggle_button"
|
43
|
+
require_relative "cyberarm_engine/ui/elements/list_box"
|
41
44
|
require_relative "cyberarm_engine/ui/elements/edit_line"
|
42
45
|
require_relative "cyberarm_engine/ui/elements/edit_box"
|
43
46
|
require_relative "cyberarm_engine/ui/elements/image"
|
@@ -51,3 +54,11 @@ require_relative "cyberarm_engine/ui/elements/slider"
|
|
51
54
|
|
52
55
|
require_relative "cyberarm_engine/game_state"
|
53
56
|
require_relative "cyberarm_engine/ui/gui_state"
|
57
|
+
|
58
|
+
require_relative "cyberarm_engine/model"
|
59
|
+
require_relative "cyberarm_engine/model_cache"
|
60
|
+
require_relative "cyberarm_engine/model/material"
|
61
|
+
require_relative "cyberarm_engine/model/model_object"
|
62
|
+
require_relative "cyberarm_engine/model/parser"
|
63
|
+
require_relative "cyberarm_engine/model/parsers/wavefront_parser"
|
64
|
+
require_relative "cyberarm_engine/model/parsers/collada_parser" if defined?(Nokogiri)
|
@@ -2,8 +2,10 @@ module CyberarmEngine
|
|
2
2
|
class Animator
|
3
3
|
DEFAULT_TWEEN = :linear
|
4
4
|
def initialize(start_time:, duration:, from:, to:, &block)
|
5
|
-
@start_time
|
6
|
-
@
|
5
|
+
@start_time = start_time
|
6
|
+
@duration = duration
|
7
|
+
@from = from.dup
|
8
|
+
@to = to.dup
|
7
9
|
@block = block
|
8
10
|
end
|
9
11
|
|
@@ -23,7 +25,7 @@ module CyberarmEngine
|
|
23
25
|
from + (to - from) * send("tween_#{tween}", progress)
|
24
26
|
end
|
25
27
|
|
26
|
-
def color_transition(from, to,
|
28
|
+
def color_transition(from, to, _tween = DEFAULT_TWEEN)
|
27
29
|
r = transition(from.red, to.red)
|
28
30
|
g = transition(from.green, to.green)
|
29
31
|
b = transition(from.blue, to.blue)
|
@@ -51,4 +53,4 @@ module CyberarmEngine
|
|
51
53
|
Math.sin(t) * t
|
52
54
|
end
|
53
55
|
end
|
54
|
-
end
|
56
|
+
end
|
@@ -2,9 +2,13 @@ module CyberarmEngine
|
|
2
2
|
class Background
|
3
3
|
attr_accessor :x, :y, :z, :width, :height, :angle, :debug
|
4
4
|
attr_reader :background
|
5
|
+
|
5
6
|
def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false)
|
6
|
-
@x
|
7
|
-
@
|
7
|
+
@x = x
|
8
|
+
@y = y
|
9
|
+
@z = z
|
10
|
+
@width = width
|
11
|
+
@height = height
|
8
12
|
@debug = debug
|
9
13
|
|
10
14
|
@paint = Paint.new(background)
|
@@ -31,8 +35,8 @@ module CyberarmEngine
|
|
31
35
|
end
|
32
36
|
|
33
37
|
def update
|
34
|
-
origin_x = (@x + (@width/2))
|
35
|
-
origin_y = (@y + (@height/2))
|
38
|
+
origin_x = (@x + (@width / 2))
|
39
|
+
origin_y = (@y + (@height / 2))
|
36
40
|
|
37
41
|
points = [
|
38
42
|
@top_left = Vector.new(@x, @y),
|
@@ -47,8 +51,8 @@ module CyberarmEngine
|
|
47
51
|
|
48
52
|
# 90 is up here, while gosu uses 0 for up.
|
49
53
|
radians = (@angle + 90).gosu_to_radians
|
50
|
-
vector.x = (@x + (@width/2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
|
51
|
-
vector.y = (@y + (@height/2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
|
54
|
+
vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
|
55
|
+
vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
|
52
56
|
end
|
53
57
|
|
54
58
|
# [
|
@@ -67,11 +71,11 @@ module CyberarmEngine
|
|
67
71
|
a = la.x - lb.x
|
68
72
|
b = la.y - lb.y
|
69
73
|
c = Gosu.distance(la.x, la.y, lb.x, lb.y)
|
70
|
-
p a,b,c
|
71
|
-
d = (a * point.x + b * point.y + c).abs /
|
74
|
+
p a, b, c
|
75
|
+
d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b)
|
72
76
|
puts "Distance: #{d}"
|
73
77
|
exit!
|
74
|
-
|
78
|
+
d
|
75
79
|
end
|
76
80
|
|
77
81
|
def debug_outline
|
@@ -117,6 +121,7 @@ module CyberarmEngine
|
|
117
121
|
|
118
122
|
class Paint
|
119
123
|
attr_accessor :top_left, :top_right, :bottom_left, :bottom_right
|
124
|
+
|
120
125
|
def initialize(background)
|
121
126
|
set(background)
|
122
127
|
end
|
@@ -124,7 +129,6 @@ module CyberarmEngine
|
|
124
129
|
def set(background)
|
125
130
|
@background = background
|
126
131
|
|
127
|
-
|
128
132
|
if background.is_a?(Numeric)
|
129
133
|
@top_left = background
|
130
134
|
@top_right = background
|
@@ -167,9 +171,9 @@ end
|
|
167
171
|
|
168
172
|
# Add <=> method to support Range based gradients
|
169
173
|
module Gosu
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
174
|
+
class Color
|
175
|
+
def <=>(_other)
|
176
|
+
self
|
177
|
+
end
|
178
|
+
end
|
175
179
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module CyberarmEngine
|
2
|
+
class BackgroundNineSlice
|
3
|
+
include CyberarmEngine::Common
|
4
|
+
attr_accessor :x, :y, :z, :width, :height
|
5
|
+
|
6
|
+
def initialize(image_path:, x: 0, y: 0, z: 0, width: 64, height: 64, mode: :tiled, left: 4, top: 4, right: 56, bottom: 56)
|
7
|
+
@image = get_image(image_path)
|
8
|
+
|
9
|
+
@x = x
|
10
|
+
@y = y
|
11
|
+
@z = z
|
12
|
+
|
13
|
+
@width = width
|
14
|
+
@height = height
|
15
|
+
|
16
|
+
@mode = mode
|
17
|
+
|
18
|
+
@left = left
|
19
|
+
@top = top
|
20
|
+
@right = right
|
21
|
+
@bottom = bottom
|
22
|
+
|
23
|
+
nine_slice
|
24
|
+
end
|
25
|
+
|
26
|
+
def nine_slice
|
27
|
+
@segment_top_left = Gosu.render(@left, @top) { @image.draw(0, 0, 0) }
|
28
|
+
@segment_top_right = Gosu.render(@image.width - @right, @top) { @image.draw(-@right, 0, 0) }
|
29
|
+
|
30
|
+
@segment_left = Gosu.render(@left, @bottom - @top) { @image.draw(0, -@top, 0) }
|
31
|
+
@segment_right = Gosu.render(@image.width - @right, @bottom - @top) { @image.draw(-@right, -@top, 0) }
|
32
|
+
|
33
|
+
@segment_bottom_left = Gosu.render(@left, @image.height - @bottom) { @image.draw(0, -@bottom, 0) }
|
34
|
+
@segment_bottom_right = Gosu.render(@image.width - @right, @image.height - @bottom) { @image.draw(-@right, -@bottom, 0) }
|
35
|
+
|
36
|
+
@segment_top = Gosu.render(@right - @left, @top) { @image.draw(-@left, 0, 0) }
|
37
|
+
@segment_bottom = Gosu.render(@right - @left, @image.height - @bottom) { @image.draw(-@left, -@bottom, 0) }
|
38
|
+
|
39
|
+
@segment_middle = Gosu.render(@right - @left, @bottom - @top) { @image.draw(-@left, -@top, 0) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def cx
|
43
|
+
@x + @left
|
44
|
+
end
|
45
|
+
|
46
|
+
def cy
|
47
|
+
@y + @top
|
48
|
+
end
|
49
|
+
|
50
|
+
def cwidth
|
51
|
+
@cx - @width
|
52
|
+
end
|
53
|
+
|
54
|
+
def cheight
|
55
|
+
@cy - @height
|
56
|
+
end
|
57
|
+
|
58
|
+
def width_scale
|
59
|
+
width_scale = (@width - (@left + (@image.width - @right))).to_f / (@right - @left)
|
60
|
+
end
|
61
|
+
|
62
|
+
def height_scale
|
63
|
+
height_scale = (@height - (@top + (@image.height - @bottom))).to_f / (@bottom - @top)
|
64
|
+
end
|
65
|
+
|
66
|
+
def draw
|
67
|
+
@mode == :tiled ? draw_tiled : draw_stretched
|
68
|
+
end
|
69
|
+
|
70
|
+
def draw_stretched
|
71
|
+
@segment_top_left.draw(@x, @y, @z)
|
72
|
+
@segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale) # SCALE X
|
73
|
+
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z)
|
74
|
+
|
75
|
+
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale) # SCALE Y
|
76
|
+
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z)
|
77
|
+
@segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale) # SCALE X
|
78
|
+
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z)
|
79
|
+
@segment_left.draw(@x, @y + @top, @z, 1, height_scale) # SCALE Y
|
80
|
+
@segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale) # SCALE X and SCALE Y
|
81
|
+
end
|
82
|
+
|
83
|
+
def draw_tiled
|
84
|
+
@segment_top_left.draw(@x, @y, @z)
|
85
|
+
|
86
|
+
Gosu.clip_to(@x + @segment_top_left.width, @y, @segment_top.width * width_scale, @segment_top.height) do
|
87
|
+
width_scale.ceil.times do |i|
|
88
|
+
@segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z) # SCALE X
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z)
|
93
|
+
|
94
|
+
Gosu.clip_to(@x + @width - @segment_top_right.width, @y + @top, @segment_right.width, @segment_right.height * height_scale) do
|
95
|
+
height_scale.ceil.times do |i|
|
96
|
+
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z) # SCALE Y
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z)
|
101
|
+
|
102
|
+
Gosu.clip_to(@x + @segment_top_left.width, @y + @height - @segment_bottom.height, @segment_top.width * width_scale, @segment_bottom.height) do
|
103
|
+
width_scale.ceil.times do |i|
|
104
|
+
@segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z) # SCALE X
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z)
|
109
|
+
|
110
|
+
Gosu.clip_to(@x, @y + @top, @segment_left.width, @segment_left.height * height_scale) do
|
111
|
+
height_scale.ceil.times do |i|
|
112
|
+
@segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z) # SCALE Y
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
Gosu.clip_to(@x + @segment_top_left.width, @y + @segment_top.height, @width - (@segment_left.width + @segment_right.width), @height - (@segment_top.height + @segment_bottom.height)) do
|
117
|
+
height_scale.ceil.times do |y|
|
118
|
+
width_scale.ceil.times do |x|
|
119
|
+
@segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z) # SCALE X and SCALE Y
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -23,7 +23,7 @@ module CyberarmEngine
|
|
23
23
|
|
24
24
|
def ==(other)
|
25
25
|
@min == other.min &&
|
26
|
-
|
26
|
+
@max == other.max
|
27
27
|
end
|
28
28
|
|
29
29
|
# returns a new bounding box that includes both bounding boxes
|
@@ -37,7 +37,7 @@ module CyberarmEngine
|
|
37
37
|
temp.max.y = [@max.y, other.max.y].max
|
38
38
|
temp.max.z = [@max.z, other.max.z].max
|
39
39
|
|
40
|
-
|
40
|
+
temp
|
41
41
|
end
|
42
42
|
|
43
43
|
# returns the difference between both bounding boxes
|
@@ -46,7 +46,7 @@ module CyberarmEngine
|
|
46
46
|
temp.min = @min - other.min
|
47
47
|
temp.max = @max - other.max
|
48
48
|
|
49
|
-
|
49
|
+
temp
|
50
50
|
end
|
51
51
|
|
52
52
|
# returns whether bounding box intersects other
|
@@ -55,8 +55,8 @@ module CyberarmEngine
|
|
55
55
|
other.intersect?(self)
|
56
56
|
elsif other.is_a?(BoundingBox)
|
57
57
|
(@min.x <= other.max.x && @max.x >= other.min.x) &&
|
58
|
-
|
59
|
-
|
58
|
+
(@min.y <= other.max.y && @max.y >= other.min.y) &&
|
59
|
+
(@min.z <= other.max.z && @max.z >= other.min.z)
|
60
60
|
else
|
61
61
|
raise "Unknown collider: #{other.class}"
|
62
62
|
end
|
@@ -65,20 +65,20 @@ module CyberarmEngine
|
|
65
65
|
# does this bounding box envelop other bounding box? (inclusive of border)
|
66
66
|
def contains?(other)
|
67
67
|
other.min.x >= min.x && other.min.y >= min.y && other.min.z >= min.z &&
|
68
|
-
|
68
|
+
other.max.x <= max.x && other.max.y <= max.y && other.max.z <= max.z
|
69
69
|
end
|
70
70
|
|
71
71
|
# returns whether the 3D vector is inside of the bounding box
|
72
72
|
def inside?(vector)
|
73
73
|
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
74
|
-
|
75
|
-
|
74
|
+
(vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y)) &&
|
75
|
+
(vector.z.between?(@min.z, @max.z) || vector.z.between?(@max.z, @min.z))
|
76
76
|
end
|
77
77
|
|
78
78
|
# returns whether the 2D vector is inside of the bounding box
|
79
79
|
def point?(vector)
|
80
80
|
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
81
|
-
|
81
|
+
(vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y))
|
82
82
|
end
|
83
83
|
|
84
84
|
def volume
|
@@ -107,7 +107,7 @@ module CyberarmEngine
|
|
107
107
|
temp.max.y = @max.y.to_f * entity.scale.y
|
108
108
|
temp.max.z = @max.z.to_f * entity.scale.z
|
109
109
|
|
110
|
-
|
110
|
+
temp
|
111
111
|
end
|
112
112
|
|
113
113
|
def normalize_with_offset(entity)
|
@@ -120,23 +120,23 @@ module CyberarmEngine
|
|
120
120
|
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
121
121
|
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
122
122
|
|
123
|
-
|
123
|
+
temp
|
124
124
|
end
|
125
125
|
|
126
126
|
def +(other)
|
127
127
|
box = BoundingBox.new
|
128
|
-
box.min =
|
129
|
-
box.min =
|
128
|
+
box.min = min + other.min
|
129
|
+
box.min = max + other.max
|
130
130
|
|
131
|
-
|
131
|
+
box
|
132
132
|
end
|
133
133
|
|
134
134
|
def -(other)
|
135
135
|
box = BoundingBox.new
|
136
|
-
box.min =
|
137
|
-
box.min =
|
136
|
+
box.min = min - other.min
|
137
|
+
box.min = max - other.max
|
138
138
|
|
139
|
-
|
139
|
+
box
|
140
140
|
end
|
141
141
|
|
142
142
|
def sum
|
@@ -147,4 +147,4 @@ module CyberarmEngine
|
|
147
147
|
BoundingBox.new(@min.x, @min.y, @min.z, @max.x, @max.y, @max.z)
|
148
148
|
end
|
149
149
|
end
|
150
|
-
end
|
150
|
+
end
|