cyberarm_engine 0.24.3 → 0.24.5
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/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/assets/shaders/fragment/g_buffer.glsl +30 -30
- data/assets/shaders/fragment/lighting.glsl +115 -69
- data/assets/shaders/include/light_struct.glsl +11 -11
- data/assets/shaders/include/material_struct.glsl +16 -16
- data/assets/shaders/vertex/g_buffer.glsl +28 -28
- data/assets/shaders/vertex/lighting.glsl +24 -24
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +36 -36
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +180 -179
- data/lib/cyberarm_engine/background_image.rb +93 -93
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +128 -128
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +244 -244
- data/lib/cyberarm_engine/game_state.rb +124 -124
- data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
- data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
- data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +216 -213
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/notification.rb +82 -82
- data/lib/cyberarm_engine/notification_manager.rb +241 -241
- data/lib/cyberarm_engine/opengl/light.rb +52 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
- data/lib/cyberarm_engine/opengl/shader.rb +408 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +53 -40
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +200 -200
- data/lib/cyberarm_engine/text.rb +260 -260
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
- data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
- data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +142 -142
- data/lib/cyberarm_engine/ui/element.rb +662 -662
- data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +404 -410
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
- data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
- data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
- data/lib/cyberarm_engine/ui/style.rb +50 -50
- data/lib/cyberarm_engine/ui/theme.rb +225 -225
- data/lib/cyberarm_engine/vector.rb +312 -312
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +195 -195
- data/lib/cyberarm_engine.rb +70 -78
- data/mrbgem.rake +29 -29
- metadata +8 -7
@@ -1,142 +1,142 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class BackgroundNineSlice
|
3
|
-
include CyberarmEngine::Common
|
4
|
-
attr_accessor :x, :y, :z, :width, :height, :left, :top, :right, :bottom, :mode, :color
|
5
|
-
attr_reader :image
|
6
|
-
|
7
|
-
def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :tiled, left: 1, top: 1, right: 1, bottom: 1, color: Gosu::Color::WHITE)
|
8
|
-
@image = get_image(image_path) if image_path
|
9
|
-
|
10
|
-
@x = x
|
11
|
-
@y = y
|
12
|
-
@z = z
|
13
|
-
|
14
|
-
@width = width
|
15
|
-
@height = height
|
16
|
-
|
17
|
-
@mode = mode
|
18
|
-
|
19
|
-
@left = left
|
20
|
-
@top = top
|
21
|
-
@right = right
|
22
|
-
@bottom = bottom
|
23
|
-
|
24
|
-
@color = color
|
25
|
-
|
26
|
-
nine_slice if @image
|
27
|
-
end
|
28
|
-
|
29
|
-
def image=(image_path)
|
30
|
-
old_image = @image
|
31
|
-
@image = image_path ? get_image(image_path) : image_path
|
32
|
-
nine_slice if @image && old_image != @image
|
33
|
-
end
|
34
|
-
|
35
|
-
def nine_slice
|
36
|
-
# pp [@left, @top, @right, @bottom, @image.width]
|
37
|
-
|
38
|
-
@segment_top_left = @image.subimage(0, 0, @left, @top)
|
39
|
-
@segment_top_right = @image.subimage(@image.width - @right, 0, @right, @top)
|
40
|
-
|
41
|
-
@segment_left = @image.subimage(0, @top, @left, @image.height - (@top + @bottom))
|
42
|
-
@segment_right = @image.subimage(@image.width - @right, @top, @left, @image.height - (@top + @bottom))
|
43
|
-
|
44
|
-
@segment_bottom_left = @image.subimage(0, @image.height - @bottom, @left, @bottom)
|
45
|
-
@segment_bottom_right = @image.subimage(@image.width - @right, @image.height - @bottom, @right, @bottom)
|
46
|
-
|
47
|
-
@segment_top = @image.subimage(@left, 0, @image.width - (@left + @right), @top)
|
48
|
-
@segment_bottom = @image.subimage(@left, @image.height - @bottom, @image.width - (@left + @right), @bottom)
|
49
|
-
|
50
|
-
@segment_middle = @image.subimage(@left, @top, @image.width - (@left + @right), @image.height - (@top + @bottom))
|
51
|
-
end
|
52
|
-
|
53
|
-
def cx
|
54
|
-
@x + @left
|
55
|
-
end
|
56
|
-
|
57
|
-
def cy
|
58
|
-
@y + @top
|
59
|
-
end
|
60
|
-
|
61
|
-
def cwidth
|
62
|
-
@cx - @width
|
63
|
-
end
|
64
|
-
|
65
|
-
def cheight
|
66
|
-
@cy - @height
|
67
|
-
end
|
68
|
-
|
69
|
-
def width_scale
|
70
|
-
scale = (@width.to_f - (@left + @right)) / (@image.width - (@left + @right))
|
71
|
-
scale.abs
|
72
|
-
end
|
73
|
-
|
74
|
-
def height_scale
|
75
|
-
scale = (@height - (@top + @bottom)).to_f / (@image.height - (@top + @bottom))
|
76
|
-
scale.abs
|
77
|
-
end
|
78
|
-
|
79
|
-
def draw
|
80
|
-
return unless @image && @segment_top_left
|
81
|
-
|
82
|
-
@mode == :tiled ? draw_tiled : draw_stretched
|
83
|
-
end
|
84
|
-
|
85
|
-
def draw_stretched
|
86
|
-
@segment_top_left.draw(@x, @y, @z, 1, 1, @color)
|
87
|
-
@segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale, 1, @color) # SCALE X
|
88
|
-
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
|
89
|
-
|
90
|
-
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale, @color) # SCALE Y
|
91
|
-
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
|
92
|
-
@segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale, 1, @color) # SCALE X
|
93
|
-
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
|
94
|
-
@segment_left.draw(@x, @y + @top, @z, 1, height_scale, @color) # SCALE Y
|
95
|
-
@segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale, @color) # SCALE X and SCALE Y
|
96
|
-
end
|
97
|
-
|
98
|
-
def draw_tiled
|
99
|
-
@segment_top_left.draw(@x, @y, @z, 1, 1, @color)
|
100
|
-
|
101
|
-
# p [width_scale, height_scale]
|
102
|
-
|
103
|
-
Gosu.clip_to(@x + @segment_top_left.width, @y, @segment_top.width * width_scale, @segment_top.height) do
|
104
|
-
width_scale.ceil.times do |i|
|
105
|
-
@segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z, 1, 1, @color) # SCALE X
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
|
110
|
-
|
111
|
-
Gosu.clip_to(@x + @width - @segment_top_right.width, @y + @top, @segment_right.width, @segment_right.height * height_scale) do
|
112
|
-
height_scale.ceil.times do |i|
|
113
|
-
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z, 1, 1, @color) # SCALE Y
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
|
118
|
-
|
119
|
-
Gosu.clip_to(@x + @segment_top_left.width, @y + @height - @segment_bottom.height, @segment_top.width * width_scale, @segment_bottom.height) do
|
120
|
-
width_scale.ceil.times do |i|
|
121
|
-
@segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z, 1, 1, @color) # SCALE X
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
|
126
|
-
|
127
|
-
Gosu.clip_to(@x, @y + @top, @segment_left.width, @segment_left.height * height_scale) do
|
128
|
-
height_scale.ceil.times do |i|
|
129
|
-
@segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z, 1, 1, @color) # SCALE Y
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
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
|
134
|
-
height_scale.ceil.times do |y|
|
135
|
-
width_scale.ceil.times do |x|
|
136
|
-
@segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z, 1, 1, @color) # SCALE X and SCALE Y
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class BackgroundNineSlice
|
3
|
+
include CyberarmEngine::Common
|
4
|
+
attr_accessor :x, :y, :z, :width, :height, :left, :top, :right, :bottom, :mode, :color
|
5
|
+
attr_reader :image
|
6
|
+
|
7
|
+
def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :tiled, left: 1, top: 1, right: 1, bottom: 1, color: Gosu::Color::WHITE)
|
8
|
+
@image = get_image(image_path) if image_path
|
9
|
+
|
10
|
+
@x = x
|
11
|
+
@y = y
|
12
|
+
@z = z
|
13
|
+
|
14
|
+
@width = width
|
15
|
+
@height = height
|
16
|
+
|
17
|
+
@mode = mode
|
18
|
+
|
19
|
+
@left = left
|
20
|
+
@top = top
|
21
|
+
@right = right
|
22
|
+
@bottom = bottom
|
23
|
+
|
24
|
+
@color = color
|
25
|
+
|
26
|
+
nine_slice if @image
|
27
|
+
end
|
28
|
+
|
29
|
+
def image=(image_path)
|
30
|
+
old_image = @image
|
31
|
+
@image = image_path ? get_image(image_path) : image_path
|
32
|
+
nine_slice if @image && old_image != @image
|
33
|
+
end
|
34
|
+
|
35
|
+
def nine_slice
|
36
|
+
# pp [@left, @top, @right, @bottom, @image.width]
|
37
|
+
|
38
|
+
@segment_top_left = @image.subimage(0, 0, @left, @top)
|
39
|
+
@segment_top_right = @image.subimage(@image.width - @right, 0, @right, @top)
|
40
|
+
|
41
|
+
@segment_left = @image.subimage(0, @top, @left, @image.height - (@top + @bottom))
|
42
|
+
@segment_right = @image.subimage(@image.width - @right, @top, @left, @image.height - (@top + @bottom))
|
43
|
+
|
44
|
+
@segment_bottom_left = @image.subimage(0, @image.height - @bottom, @left, @bottom)
|
45
|
+
@segment_bottom_right = @image.subimage(@image.width - @right, @image.height - @bottom, @right, @bottom)
|
46
|
+
|
47
|
+
@segment_top = @image.subimage(@left, 0, @image.width - (@left + @right), @top)
|
48
|
+
@segment_bottom = @image.subimage(@left, @image.height - @bottom, @image.width - (@left + @right), @bottom)
|
49
|
+
|
50
|
+
@segment_middle = @image.subimage(@left, @top, @image.width - (@left + @right), @image.height - (@top + @bottom))
|
51
|
+
end
|
52
|
+
|
53
|
+
def cx
|
54
|
+
@x + @left
|
55
|
+
end
|
56
|
+
|
57
|
+
def cy
|
58
|
+
@y + @top
|
59
|
+
end
|
60
|
+
|
61
|
+
def cwidth
|
62
|
+
@cx - @width
|
63
|
+
end
|
64
|
+
|
65
|
+
def cheight
|
66
|
+
@cy - @height
|
67
|
+
end
|
68
|
+
|
69
|
+
def width_scale
|
70
|
+
scale = (@width.to_f - (@left + @right)) / (@image.width - (@left + @right))
|
71
|
+
scale.abs
|
72
|
+
end
|
73
|
+
|
74
|
+
def height_scale
|
75
|
+
scale = (@height - (@top + @bottom)).to_f / (@image.height - (@top + @bottom))
|
76
|
+
scale.abs
|
77
|
+
end
|
78
|
+
|
79
|
+
def draw
|
80
|
+
return unless @image && @segment_top_left
|
81
|
+
|
82
|
+
@mode == :tiled ? draw_tiled : draw_stretched
|
83
|
+
end
|
84
|
+
|
85
|
+
def draw_stretched
|
86
|
+
@segment_top_left.draw(@x, @y, @z, 1, 1, @color)
|
87
|
+
@segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale, 1, @color) # SCALE X
|
88
|
+
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
|
89
|
+
|
90
|
+
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale, @color) # SCALE Y
|
91
|
+
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
|
92
|
+
@segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale, 1, @color) # SCALE X
|
93
|
+
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
|
94
|
+
@segment_left.draw(@x, @y + @top, @z, 1, height_scale, @color) # SCALE Y
|
95
|
+
@segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale, @color) # SCALE X and SCALE Y
|
96
|
+
end
|
97
|
+
|
98
|
+
def draw_tiled
|
99
|
+
@segment_top_left.draw(@x, @y, @z, 1, 1, @color)
|
100
|
+
|
101
|
+
# p [width_scale, height_scale]
|
102
|
+
|
103
|
+
Gosu.clip_to(@x + @segment_top_left.width, @y, @segment_top.width * width_scale, @segment_top.height) do
|
104
|
+
width_scale.ceil.times do |i|
|
105
|
+
@segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z, 1, 1, @color) # SCALE X
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
|
110
|
+
|
111
|
+
Gosu.clip_to(@x + @width - @segment_top_right.width, @y + @top, @segment_right.width, @segment_right.height * height_scale) do
|
112
|
+
height_scale.ceil.times do |i|
|
113
|
+
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z, 1, 1, @color) # SCALE Y
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
|
118
|
+
|
119
|
+
Gosu.clip_to(@x + @segment_top_left.width, @y + @height - @segment_bottom.height, @segment_top.width * width_scale, @segment_bottom.height) do
|
120
|
+
width_scale.ceil.times do |i|
|
121
|
+
@segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z, 1, 1, @color) # SCALE X
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
|
126
|
+
|
127
|
+
Gosu.clip_to(@x, @y + @top, @segment_left.width, @segment_left.height * height_scale) do
|
128
|
+
height_scale.ceil.times do |i|
|
129
|
+
@segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z, 1, 1, @color) # SCALE Y
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
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
|
134
|
+
height_scale.ceil.times do |y|
|
135
|
+
width_scale.ceil.times do |x|
|
136
|
+
@segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z, 1, 1, @color) # SCALE X and SCALE Y
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -1,150 +1,150 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class BoundingBox
|
3
|
-
attr_accessor :min, :max
|
4
|
-
|
5
|
-
def initialize(*args)
|
6
|
-
case args.size
|
7
|
-
when 0
|
8
|
-
@min = Vector.new(0, 0, 0)
|
9
|
-
@max = Vector.new(0, 0, 0)
|
10
|
-
when 2
|
11
|
-
@min = args.first.clone
|
12
|
-
@max = args.last.clone
|
13
|
-
when 4
|
14
|
-
@min = Vector.new(args[0], args[1], 0)
|
15
|
-
@max = Vector.new(args[2], args[3], 0)
|
16
|
-
when 6
|
17
|
-
@min = Vector.new(args[0], args[1], args[2])
|
18
|
-
@max = Vector.new(args[3], args[4], args[5])
|
19
|
-
else
|
20
|
-
raise "Invalid number of arguments! Got: #{args.size}, expected: 0, 2, 4, or 6."
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def ==(other)
|
25
|
-
@min == other.min &&
|
26
|
-
@max == other.max
|
27
|
-
end
|
28
|
-
|
29
|
-
# returns a new bounding box that includes both bounding boxes
|
30
|
-
def union(other)
|
31
|
-
temp = BoundingBox.new
|
32
|
-
temp.min.x = [@min.x, other.min.x].min
|
33
|
-
temp.min.y = [@min.y, other.min.y].min
|
34
|
-
temp.min.z = [@min.z, other.min.z].min
|
35
|
-
|
36
|
-
temp.max.x = [@max.x, other.max.x].max
|
37
|
-
temp.max.y = [@max.y, other.max.y].max
|
38
|
-
temp.max.z = [@max.z, other.max.z].max
|
39
|
-
|
40
|
-
temp
|
41
|
-
end
|
42
|
-
|
43
|
-
# returns the difference between both bounding boxes
|
44
|
-
def difference(other)
|
45
|
-
temp = BoundingBox.new
|
46
|
-
temp.min = @min - other.min
|
47
|
-
temp.max = @max - other.max
|
48
|
-
|
49
|
-
temp
|
50
|
-
end
|
51
|
-
|
52
|
-
# returns whether bounding box intersects other
|
53
|
-
def intersect?(other)
|
54
|
-
if other.is_a?(Ray)
|
55
|
-
other.intersect?(self)
|
56
|
-
elsif other.is_a?(BoundingBox)
|
57
|
-
(@min.x <= other.max.x && @max.x >= other.min.x) &&
|
58
|
-
(@min.y <= other.max.y && @max.y >= other.min.y) &&
|
59
|
-
(@min.z <= other.max.z && @max.z >= other.min.z)
|
60
|
-
else
|
61
|
-
raise "Unknown collider: #{other.class}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# does this bounding box envelop other bounding box? (inclusive of border)
|
66
|
-
def contains?(other)
|
67
|
-
other.min.x >= min.x && other.min.y >= min.y && other.min.z >= min.z &&
|
68
|
-
other.max.x <= max.x && other.max.y <= max.y && other.max.z <= max.z
|
69
|
-
end
|
70
|
-
|
71
|
-
# returns whether the 3D vector is inside of the bounding box
|
72
|
-
def inside?(vector)
|
73
|
-
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
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
|
-
end
|
77
|
-
|
78
|
-
# returns whether the 2D vector is inside of the bounding box
|
79
|
-
def point?(vector)
|
80
|
-
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
81
|
-
(vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y))
|
82
|
-
end
|
83
|
-
|
84
|
-
def volume
|
85
|
-
width * height * depth
|
86
|
-
end
|
87
|
-
|
88
|
-
def width
|
89
|
-
@max.x - @min.x
|
90
|
-
end
|
91
|
-
|
92
|
-
def height
|
93
|
-
@max.y - @min.y
|
94
|
-
end
|
95
|
-
|
96
|
-
def depth
|
97
|
-
@max.z - @min.z
|
98
|
-
end
|
99
|
-
|
100
|
-
def normalize(entity)
|
101
|
-
temp = BoundingBox.new
|
102
|
-
temp.min.x = @min.x.to_f * entity.scale.x
|
103
|
-
temp.min.y = @min.y.to_f * entity.scale.y
|
104
|
-
temp.min.z = @min.z.to_f * entity.scale.z
|
105
|
-
|
106
|
-
temp.max.x = @max.x.to_f * entity.scale.x
|
107
|
-
temp.max.y = @max.y.to_f * entity.scale.y
|
108
|
-
temp.max.z = @max.z.to_f * entity.scale.z
|
109
|
-
|
110
|
-
temp
|
111
|
-
end
|
112
|
-
|
113
|
-
def normalize_with_offset(entity)
|
114
|
-
temp = BoundingBox.new
|
115
|
-
temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
|
116
|
-
temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
|
117
|
-
temp.min.z = @min.z.to_f * entity.scale.z + entity.position.z
|
118
|
-
|
119
|
-
temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
|
120
|
-
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
121
|
-
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
122
|
-
|
123
|
-
temp
|
124
|
-
end
|
125
|
-
|
126
|
-
def +(other)
|
127
|
-
box = BoundingBox.new
|
128
|
-
box.min = min + other.min
|
129
|
-
box.min = max + other.max
|
130
|
-
|
131
|
-
box
|
132
|
-
end
|
133
|
-
|
134
|
-
def -(other)
|
135
|
-
box = BoundingBox.new
|
136
|
-
box.min = min - other.min
|
137
|
-
box.min = max - other.max
|
138
|
-
|
139
|
-
box
|
140
|
-
end
|
141
|
-
|
142
|
-
def sum
|
143
|
-
@min.sum + @max.sum
|
144
|
-
end
|
145
|
-
|
146
|
-
def clone
|
147
|
-
BoundingBox.new(@min.x, @min.y, @min.z, @max.x, @max.y, @max.z)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class BoundingBox
|
3
|
+
attr_accessor :min, :max
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
case args.size
|
7
|
+
when 0
|
8
|
+
@min = Vector.new(0, 0, 0)
|
9
|
+
@max = Vector.new(0, 0, 0)
|
10
|
+
when 2
|
11
|
+
@min = args.first.clone
|
12
|
+
@max = args.last.clone
|
13
|
+
when 4
|
14
|
+
@min = Vector.new(args[0], args[1], 0)
|
15
|
+
@max = Vector.new(args[2], args[3], 0)
|
16
|
+
when 6
|
17
|
+
@min = Vector.new(args[0], args[1], args[2])
|
18
|
+
@max = Vector.new(args[3], args[4], args[5])
|
19
|
+
else
|
20
|
+
raise "Invalid number of arguments! Got: #{args.size}, expected: 0, 2, 4, or 6."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
@min == other.min &&
|
26
|
+
@max == other.max
|
27
|
+
end
|
28
|
+
|
29
|
+
# returns a new bounding box that includes both bounding boxes
|
30
|
+
def union(other)
|
31
|
+
temp = BoundingBox.new
|
32
|
+
temp.min.x = [@min.x, other.min.x].min
|
33
|
+
temp.min.y = [@min.y, other.min.y].min
|
34
|
+
temp.min.z = [@min.z, other.min.z].min
|
35
|
+
|
36
|
+
temp.max.x = [@max.x, other.max.x].max
|
37
|
+
temp.max.y = [@max.y, other.max.y].max
|
38
|
+
temp.max.z = [@max.z, other.max.z].max
|
39
|
+
|
40
|
+
temp
|
41
|
+
end
|
42
|
+
|
43
|
+
# returns the difference between both bounding boxes
|
44
|
+
def difference(other)
|
45
|
+
temp = BoundingBox.new
|
46
|
+
temp.min = @min - other.min
|
47
|
+
temp.max = @max - other.max
|
48
|
+
|
49
|
+
temp
|
50
|
+
end
|
51
|
+
|
52
|
+
# returns whether bounding box intersects other
|
53
|
+
def intersect?(other)
|
54
|
+
if other.is_a?(Ray)
|
55
|
+
other.intersect?(self)
|
56
|
+
elsif other.is_a?(BoundingBox)
|
57
|
+
(@min.x <= other.max.x && @max.x >= other.min.x) &&
|
58
|
+
(@min.y <= other.max.y && @max.y >= other.min.y) &&
|
59
|
+
(@min.z <= other.max.z && @max.z >= other.min.z)
|
60
|
+
else
|
61
|
+
raise "Unknown collider: #{other.class}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# does this bounding box envelop other bounding box? (inclusive of border)
|
66
|
+
def contains?(other)
|
67
|
+
other.min.x >= min.x && other.min.y >= min.y && other.min.z >= min.z &&
|
68
|
+
other.max.x <= max.x && other.max.y <= max.y && other.max.z <= max.z
|
69
|
+
end
|
70
|
+
|
71
|
+
# returns whether the 3D vector is inside of the bounding box
|
72
|
+
def inside?(vector)
|
73
|
+
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
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
|
+
end
|
77
|
+
|
78
|
+
# returns whether the 2D vector is inside of the bounding box
|
79
|
+
def point?(vector)
|
80
|
+
(vector.x.between?(@min.x, @max.x) || vector.x.between?(@max.x, @min.x)) &&
|
81
|
+
(vector.y.between?(@min.y, @max.y) || vector.y.between?(@max.y, @min.y))
|
82
|
+
end
|
83
|
+
|
84
|
+
def volume
|
85
|
+
width * height * depth
|
86
|
+
end
|
87
|
+
|
88
|
+
def width
|
89
|
+
@max.x - @min.x
|
90
|
+
end
|
91
|
+
|
92
|
+
def height
|
93
|
+
@max.y - @min.y
|
94
|
+
end
|
95
|
+
|
96
|
+
def depth
|
97
|
+
@max.z - @min.z
|
98
|
+
end
|
99
|
+
|
100
|
+
def normalize(entity)
|
101
|
+
temp = BoundingBox.new
|
102
|
+
temp.min.x = @min.x.to_f * entity.scale.x
|
103
|
+
temp.min.y = @min.y.to_f * entity.scale.y
|
104
|
+
temp.min.z = @min.z.to_f * entity.scale.z
|
105
|
+
|
106
|
+
temp.max.x = @max.x.to_f * entity.scale.x
|
107
|
+
temp.max.y = @max.y.to_f * entity.scale.y
|
108
|
+
temp.max.z = @max.z.to_f * entity.scale.z
|
109
|
+
|
110
|
+
temp
|
111
|
+
end
|
112
|
+
|
113
|
+
def normalize_with_offset(entity)
|
114
|
+
temp = BoundingBox.new
|
115
|
+
temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
|
116
|
+
temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
|
117
|
+
temp.min.z = @min.z.to_f * entity.scale.z + entity.position.z
|
118
|
+
|
119
|
+
temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
|
120
|
+
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
121
|
+
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
122
|
+
|
123
|
+
temp
|
124
|
+
end
|
125
|
+
|
126
|
+
def +(other)
|
127
|
+
box = BoundingBox.new
|
128
|
+
box.min = min + other.min
|
129
|
+
box.min = max + other.max
|
130
|
+
|
131
|
+
box
|
132
|
+
end
|
133
|
+
|
134
|
+
def -(other)
|
135
|
+
box = BoundingBox.new
|
136
|
+
box.min = min - other.min
|
137
|
+
box.min = max - other.max
|
138
|
+
|
139
|
+
box
|
140
|
+
end
|
141
|
+
|
142
|
+
def sum
|
143
|
+
@min.sum + @max.sum
|
144
|
+
end
|
145
|
+
|
146
|
+
def clone
|
147
|
+
BoundingBox.new(@min.x, @min.y, @min.z, @max.x, @max.y, @max.z)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|