cyberarm_engine 0.25.0 → 0.30.0

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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/Gemfile.lock +37 -25
  7. data/LICENSE.txt +21 -21
  8. data/README.md +74 -74
  9. data/Rakefile +10 -10
  10. data/assets/shaders/fragment/g_buffer.glsl +30 -30
  11. data/assets/shaders/fragment/lighting.glsl +115 -115
  12. data/assets/shaders/include/light_struct.glsl +11 -11
  13. data/assets/shaders/include/material_struct.glsl +16 -16
  14. data/assets/shaders/vertex/g_buffer.glsl +28 -28
  15. data/assets/shaders/vertex/lighting.glsl +24 -24
  16. data/assets/textures/ui/circle.png +0 -0
  17. data/assets/textures/ui/circle_small.png +0 -0
  18. data/assets/textures/ui/rounded.png +0 -0
  19. data/assets/textures/ui/rounded_bottom.png +0 -0
  20. data/assets/textures/ui/rounded_left.png +0 -0
  21. data/assets/textures/ui/rounded_left_bottom.png +0 -0
  22. data/assets/textures/ui/rounded_left_top.png +0 -0
  23. data/assets/textures/ui/rounded_right.png +0 -0
  24. data/assets/textures/ui/rounded_right_bottom.png +0 -0
  25. data/assets/textures/ui/rounded_right_top.png +0 -0
  26. data/assets/textures/ui/rounded_small.png +0 -0
  27. data/assets/textures/ui/rounded_tiny.png +0 -0
  28. data/assets/textures/ui/rounded_top.png +0 -0
  29. data/assets/textures/ui/square.png +0 -0
  30. data/bin/console +14 -14
  31. data/bin/setup +8 -8
  32. data/cyberarm_engine.gemspec +35 -36
  33. data/lib/cyberarm_engine/animator.rb +219 -219
  34. data/lib/cyberarm_engine/background.rb +156 -158
  35. data/lib/cyberarm_engine/background_image.rb +93 -93
  36. data/lib/cyberarm_engine/background_nine_slice.rb +182 -142
  37. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  38. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  39. data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
  40. data/lib/cyberarm_engine/cache.rb +4 -4
  41. data/lib/cyberarm_engine/common.rb +133 -131
  42. data/lib/cyberarm_engine/config_file.rb +46 -46
  43. data/lib/cyberarm_engine/console/command.rb +157 -157
  44. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  45. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  46. data/lib/cyberarm_engine/console.rb +248 -248
  47. data/lib/cyberarm_engine/event_bus.rb +39 -0
  48. data/lib/cyberarm_engine/game_object.rb +244 -244
  49. data/lib/cyberarm_engine/game_state.rb +134 -124
  50. data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +111 -111
  51. data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
  52. data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
  53. data/lib/cyberarm_engine/model/material.rb +21 -21
  54. data/lib/cyberarm_engine/model/mesh.rb +131 -131
  55. data/lib/cyberarm_engine/model/parser.rb +74 -74
  56. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  57. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  58. data/lib/cyberarm_engine/model.rb +216 -216
  59. data/lib/cyberarm_engine/model_cache.rb +31 -31
  60. data/lib/cyberarm_engine/notification.rb +82 -82
  61. data/lib/cyberarm_engine/notification_manager.rb +241 -241
  62. data/lib/cyberarm_engine/opengl/light.rb +52 -52
  63. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  64. data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -41
  65. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  66. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -167
  67. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -307
  68. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
  69. data/lib/cyberarm_engine/opengl/shader.rb +408 -408
  70. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  71. data/lib/cyberarm_engine/opengl.rb +53 -53
  72. data/lib/cyberarm_engine/pathfinding/graph.rb +64 -0
  73. data/lib/cyberarm_engine/pathfinding/graph_search.rb +6 -0
  74. data/lib/cyberarm_engine/pathfinding/graph_searches/astar_search.rb +6 -0
  75. data/lib/cyberarm_engine/pathfinding/graph_searches/breadth_first_search.rb +27 -0
  76. data/lib/cyberarm_engine/pathfinding/graph_searches/dijkstra_search.rb +6 -0
  77. data/lib/cyberarm_engine/pathfinding/graphs/grid.rb +52 -0
  78. data/lib/cyberarm_engine/ray.rb +56 -56
  79. data/lib/cyberarm_engine/result.rb +19 -0
  80. data/lib/cyberarm_engine/stats.rb +200 -200
  81. data/lib/cyberarm_engine/text.rb +288 -260
  82. data/lib/cyberarm_engine/timer.rb +27 -23
  83. data/lib/cyberarm_engine/transform.rb +296 -296
  84. data/lib/cyberarm_engine/trees/aabb_node.rb +126 -126
  85. data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -55
  86. data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -29
  87. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  88. data/lib/cyberarm_engine/ui/dialog.rb +24 -0
  89. data/lib/cyberarm_engine/ui/dsl.rb +170 -142
  90. data/lib/cyberarm_engine/ui/element.rb +664 -662
  91. data/lib/cyberarm_engine/ui/elements/button.rb +99 -100
  92. data/lib/cyberarm_engine/ui/elements/check_box.rb +58 -54
  93. data/lib/cyberarm_engine/ui/elements/container.rb +413 -407
  94. data/lib/cyberarm_engine/ui/elements/edit_box.rb +200 -179
  95. data/lib/cyberarm_engine/ui/elements/edit_line.rb +299 -297
  96. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  97. data/lib/cyberarm_engine/ui/elements/image.rb +78 -72
  98. data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
  99. data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
  100. data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
  101. data/lib/cyberarm_engine/ui/elements/progress.rb +95 -93
  102. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  103. data/lib/cyberarm_engine/ui/elements/slider.rb +111 -107
  104. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  105. data/lib/cyberarm_engine/ui/elements/text_block.rb +236 -222
  106. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +71 -67
  107. data/lib/cyberarm_engine/ui/elements/widget.rb +45 -0
  108. data/lib/cyberarm_engine/ui/event.rb +54 -54
  109. data/lib/cyberarm_engine/ui/gui_state.rb +402 -326
  110. data/lib/cyberarm_engine/ui/page.rb +39 -0
  111. data/lib/cyberarm_engine/ui/style.rb +94 -61
  112. data/lib/cyberarm_engine/ui/theme.rb +237 -225
  113. data/lib/cyberarm_engine/vector.rb +312 -312
  114. data/lib/cyberarm_engine/version.rb +4 -4
  115. data/lib/cyberarm_engine/window.rb +234 -195
  116. data/lib/cyberarm_engine.rb +88 -76
  117. data/mrbgem.rake +29 -29
  118. metadata +30 -5
@@ -1,41 +1,41 @@
1
- module CyberarmEngine
2
- class PerspectiveCamera
3
- include OpenGL
4
- include GLU
5
-
6
- attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
7
- :min_view_distance, :max_view_distance
8
-
9
- def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0, 0),
10
- field_of_view: 70.0, min_view_distance: 0.1, max_view_distance: 1024.0)
11
- @position = position
12
- @orientation = orientation
13
-
14
- @aspect_ratio = aspect_ratio
15
- @field_of_view = field_of_view
16
-
17
- @min_view_distance = min_view_distance
18
- @max_view_distance = max_view_distance
19
- end
20
-
21
- def draw
22
- glMatrixMode(GL_PROJECTION)
23
- glLoadIdentity
24
- gluPerspective(@field_of_view, @aspect_ratio, @min_view_distance, @max_view_distance)
25
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
26
- glRotatef(@orientation.x, 1, 0, 0)
27
- glRotatef(@orientation.y, 0, 1, 0)
28
- glTranslatef(-@position.x, -@position.y, -@position.z)
29
- glMatrixMode(GL_MODELVIEW)
30
- glLoadIdentity
31
- end
32
-
33
- def projection_matrix
34
- Transform.perspective(@field_of_view, @aspect_ratio, @min_view_distance, @max_view_distance)
35
- end
36
-
37
- def view_matrix
38
- Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
39
- end
40
- end
41
- end
1
+ module CyberarmEngine
2
+ class PerspectiveCamera
3
+ include OpenGL
4
+ include GLU
5
+
6
+ attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
7
+ :min_view_distance, :max_view_distance
8
+
9
+ def initialize(position:, aspect_ratio:, orientation: Vector.new(0, 0, 0),
10
+ field_of_view: 70.0, min_view_distance: 0.1, max_view_distance: 1024.0)
11
+ @position = position
12
+ @orientation = orientation
13
+
14
+ @aspect_ratio = aspect_ratio
15
+ @field_of_view = field_of_view
16
+
17
+ @min_view_distance = min_view_distance
18
+ @max_view_distance = max_view_distance
19
+ end
20
+
21
+ def draw
22
+ glMatrixMode(GL_PROJECTION)
23
+ glLoadIdentity
24
+ gluPerspective(@field_of_view, @aspect_ratio, @min_view_distance, @max_view_distance)
25
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
26
+ glRotatef(@orientation.x, 1, 0, 0)
27
+ glRotatef(@orientation.y, 0, 1, 0)
28
+ glTranslatef(-@position.x, -@position.y, -@position.z)
29
+ glMatrixMode(GL_MODELVIEW)
30
+ glLoadIdentity
31
+ end
32
+
33
+ def projection_matrix
34
+ Transform.perspective(@field_of_view, @aspect_ratio, @min_view_distance, @max_view_distance)
35
+ end
36
+
37
+ def view_matrix
38
+ Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
39
+ end
40
+ end
41
+ end
@@ -1,249 +1,249 @@
1
- module CyberarmEngine
2
- class BoundingBoxRenderer
3
- attr_reader :bounding_boxes, :vertex_count
4
-
5
- def initialize
6
- @bounding_boxes = {}
7
- @vertex_count = 0
8
- end
9
-
10
- def render(entities)
11
- entities.each do |entity|
12
- create_bounding_box(entity, color = nil)
13
- draw_bounding_boxes
14
- end
15
-
16
- (@bounding_boxes.keys - entities.map { |e| e.object_id }).each do |key|
17
- @bounding_boxes.delete(key)
18
- end
19
- end
20
-
21
- def create_bounding_box(entity, color = nil)
22
- color ||= entity.debug_color
23
- entity_id = entity.object_id
24
-
25
- if @bounding_boxes[entity_id]
26
- if @bounding_boxes[entity_id][:color] != color
27
- @bounding_boxes[entity_id][:colors] = mesh_colors(color).pack("f*")
28
- @bounding_boxes[entity_id][:color] = color
29
- return
30
- else
31
- return
32
- end
33
- end
34
-
35
- @bounding_boxes[entity_id] = {
36
- entity: entity,
37
- color: color,
38
- objects: []
39
- }
40
-
41
- box = entity.normalize_bounding_box
42
-
43
- normals = mesh_normals
44
- colors = mesh_colors(color)
45
- vertices = mesh_vertices(box)
46
-
47
- @vertex_count += vertices.size
48
-
49
- @bounding_boxes[entity_id][:vertices_size] = vertices.size
50
- @bounding_boxes[entity_id][:vertices] = vertices.pack("f*")
51
- @bounding_boxes[entity_id][:normals] = normals.pack("f*")
52
- @bounding_boxes[entity_id][:colors] = colors.pack("f*")
53
-
54
- entity.model.objects.each do |mesh|
55
- data = {}
56
- box = mesh.bounding_box.normalize(entity)
57
-
58
- normals = mesh_normals
59
- colors = mesh_colors(mesh.debug_color)
60
- vertices = mesh_vertices(box)
61
-
62
- @vertex_count += vertices.size
63
-
64
- data[:vertices_size] = vertices.size
65
- data[:vertices] = vertices.pack("f*")
66
- data[:normals] = normals.pack("f*")
67
- data[:colors] = colors.pack("f*")
68
-
69
- @bounding_boxes[entity_id][:objects] << data
70
- end
71
- end
72
-
73
- def mesh_normals
74
- [
75
- 0, 1, 0,
76
- 0, 1, 0,
77
- 0, 1, 0,
78
- 0, 1, 0,
79
- 0, 1, 0,
80
- 0, 1, 0,
81
-
82
- 0, -1, 0,
83
- 0, -1, 0,
84
- 0, -1, 0,
85
- 0, -1, 0,
86
- 0, -1, 0,
87
- 0, -1, 0,
88
-
89
- 0, 0, 1,
90
- 0, 0, 1,
91
- 0, 0, 1,
92
- 0, 0, 1,
93
- 0, 0, 1,
94
- 0, 0, 1,
95
-
96
- 1, 0, 0,
97
- 1, 0, 0,
98
- 1, 0, 0,
99
- 1, 0, 0,
100
- 1, 0, 0,
101
- 1, 0, 0,
102
-
103
- -1, 0, 0,
104
- -1, 0, 0,
105
- -1, 0, 0,
106
- -1, 0, 0,
107
- -1, 0, 0,
108
- -1, 0, 0,
109
-
110
- -1, 0, 0,
111
- -1, 0, 0,
112
- -1, 0, 0,
113
-
114
- -1, 0, 0,
115
- -1, 0, 0,
116
- -1, 0, 0
117
- ]
118
- end
119
-
120
- def mesh_colors(color)
121
- [
122
- color.red, color.green, color.blue,
123
- color.red, color.green, color.blue,
124
- color.red, color.green, color.blue,
125
- color.red, color.green, color.blue,
126
- color.red, color.green, color.blue,
127
- color.red, color.green, color.blue,
128
- color.red, color.green, color.blue,
129
- color.red, color.green, color.blue,
130
- color.red, color.green, color.blue,
131
- color.red, color.green, color.blue,
132
- color.red, color.green, color.blue,
133
- color.red, color.green, color.blue,
134
- color.red, color.green, color.blue,
135
- color.red, color.green, color.blue,
136
- color.red, color.green, color.blue,
137
- color.red, color.green, color.blue,
138
- color.red, color.green, color.blue,
139
- color.red, color.green, color.blue,
140
- color.red, color.green, color.blue,
141
- color.red, color.green, color.blue,
142
- color.red, color.green, color.blue,
143
- color.red, color.green, color.blue,
144
- color.red, color.green, color.blue,
145
- color.red, color.green, color.blue,
146
- color.red, color.green, color.blue,
147
- color.red, color.green, color.blue,
148
- color.red, color.green, color.blue,
149
- color.red, color.green, color.blue,
150
- color.red, color.green, color.blue,
151
- color.red, color.green, color.blue,
152
- color.red, color.green, color.blue,
153
- color.red, color.green, color.blue,
154
- color.red, color.green, color.blue,
155
- color.red, color.green, color.blue,
156
- color.red, color.green, color.blue,
157
- color.red, color.green, color.blue
158
- ]
159
- end
160
-
161
- def mesh_vertices(box)
162
- [
163
- box.min.x, box.max.y, box.max.z,
164
- box.min.x, box.max.y, box.min.z,
165
- box.max.x, box.max.y, box.min.z,
166
-
167
- box.min.x, box.max.y, box.max.z,
168
- box.max.x, box.max.y, box.max.z,
169
- box.max.x, box.max.y, box.min.z,
170
-
171
- box.max.x, box.min.y, box.min.z,
172
- box.max.x, box.min.y, box.max.z,
173
- box.min.x, box.min.y, box.max.z,
174
-
175
- box.max.x, box.min.y, box.min.z,
176
- box.min.x, box.min.y, box.min.z,
177
- box.min.x, box.min.y, box.max.z,
178
-
179
- box.min.x, box.max.y, box.max.z,
180
- box.min.x, box.max.y, box.min.z,
181
- box.min.x, box.min.y, box.min.z,
182
-
183
- box.min.x, box.min.y, box.max.z,
184
- box.min.x, box.min.y, box.min.z,
185
- box.min.x, box.max.y, box.max.z,
186
-
187
- box.max.x, box.max.y, box.max.z,
188
- box.max.x, box.max.y, box.min.z,
189
- box.max.x, box.min.y, box.min.z,
190
-
191
- box.max.x, box.min.y, box.max.z,
192
- box.max.x, box.min.y, box.min.z,
193
- box.max.x, box.max.y, box.max.z,
194
-
195
- box.min.x, box.max.y, box.max.z,
196
- box.max.x, box.max.y, box.max.z,
197
- box.max.x, box.min.y, box.max.z,
198
-
199
- box.min.x, box.max.y, box.max.z,
200
- box.max.x, box.min.y, box.max.z,
201
- box.min.x, box.min.y, box.max.z,
202
-
203
- box.max.x, box.min.y, box.min.z,
204
- box.min.x, box.min.y, box.min.z,
205
- box.min.x, box.max.y, box.min.z,
206
-
207
- box.max.x, box.min.y, box.min.z,
208
- box.min.x, box.max.y, box.min.z,
209
- box.max.x, box.max.y, box.min.z
210
- ]
211
- end
212
-
213
- def draw_bounding_boxes
214
- @bounding_boxes.each do |key, bounding_box|
215
- glPushMatrix
216
-
217
- glTranslatef(
218
- bounding_box[:entity].position.x,
219
- bounding_box[:entity].position.y,
220
- bounding_box[:entity].position.z
221
- )
222
- draw_bounding_box(bounding_box)
223
- @bounding_boxes[key][:objects].each { |o| draw_bounding_box(o) }
224
-
225
- glPopMatrix
226
- end
227
- end
228
-
229
- def draw_bounding_box(bounding_box)
230
- glEnableClientState(GL_VERTEX_ARRAY)
231
- glEnableClientState(GL_COLOR_ARRAY)
232
- glEnableClientState(GL_NORMAL_ARRAY)
233
-
234
- glVertexPointer(3, GL_FLOAT, 0, bounding_box[:vertices])
235
- glColorPointer(3, GL_FLOAT, 0, bounding_box[:colors])
236
- glNormalPointer(GL_FLOAT, 0, bounding_box[:normals])
237
-
238
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
239
- glDisable(GL_LIGHTING)
240
- glDrawArrays(GL_TRIANGLES, 0, bounding_box[:vertices_size] / 3)
241
- glEnable(GL_LIGHTING)
242
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
243
-
244
- glDisableClientState(GL_VERTEX_ARRAY)
245
- glDisableClientState(GL_COLOR_ARRAY)
246
- glDisableClientState(GL_NORMAL_ARRAY)
247
- end
248
- end
249
- end
1
+ module CyberarmEngine
2
+ class BoundingBoxRenderer
3
+ attr_reader :bounding_boxes, :vertex_count
4
+
5
+ def initialize
6
+ @bounding_boxes = {}
7
+ @vertex_count = 0
8
+ end
9
+
10
+ def render(entities)
11
+ entities.each do |entity|
12
+ create_bounding_box(entity, color = nil)
13
+ draw_bounding_boxes
14
+ end
15
+
16
+ (@bounding_boxes.keys - entities.map { |e| e.object_id }).each do |key|
17
+ @bounding_boxes.delete(key)
18
+ end
19
+ end
20
+
21
+ def create_bounding_box(entity, color = nil)
22
+ color ||= entity.debug_color
23
+ entity_id = entity.object_id
24
+
25
+ if @bounding_boxes[entity_id]
26
+ if @bounding_boxes[entity_id][:color] != color
27
+ @bounding_boxes[entity_id][:colors] = mesh_colors(color).pack("f*")
28
+ @bounding_boxes[entity_id][:color] = color
29
+ return
30
+ else
31
+ return
32
+ end
33
+ end
34
+
35
+ @bounding_boxes[entity_id] = {
36
+ entity: entity,
37
+ color: color,
38
+ objects: []
39
+ }
40
+
41
+ box = entity.normalize_bounding_box
42
+
43
+ normals = mesh_normals
44
+ colors = mesh_colors(color)
45
+ vertices = mesh_vertices(box)
46
+
47
+ @vertex_count += vertices.size
48
+
49
+ @bounding_boxes[entity_id][:vertices_size] = vertices.size
50
+ @bounding_boxes[entity_id][:vertices] = vertices.pack("f*")
51
+ @bounding_boxes[entity_id][:normals] = normals.pack("f*")
52
+ @bounding_boxes[entity_id][:colors] = colors.pack("f*")
53
+
54
+ entity.model.objects.each do |mesh|
55
+ data = {}
56
+ box = mesh.bounding_box.normalize(entity)
57
+
58
+ normals = mesh_normals
59
+ colors = mesh_colors(mesh.debug_color)
60
+ vertices = mesh_vertices(box)
61
+
62
+ @vertex_count += vertices.size
63
+
64
+ data[:vertices_size] = vertices.size
65
+ data[:vertices] = vertices.pack("f*")
66
+ data[:normals] = normals.pack("f*")
67
+ data[:colors] = colors.pack("f*")
68
+
69
+ @bounding_boxes[entity_id][:objects] << data
70
+ end
71
+ end
72
+
73
+ def mesh_normals
74
+ [
75
+ 0, 1, 0,
76
+ 0, 1, 0,
77
+ 0, 1, 0,
78
+ 0, 1, 0,
79
+ 0, 1, 0,
80
+ 0, 1, 0,
81
+
82
+ 0, -1, 0,
83
+ 0, -1, 0,
84
+ 0, -1, 0,
85
+ 0, -1, 0,
86
+ 0, -1, 0,
87
+ 0, -1, 0,
88
+
89
+ 0, 0, 1,
90
+ 0, 0, 1,
91
+ 0, 0, 1,
92
+ 0, 0, 1,
93
+ 0, 0, 1,
94
+ 0, 0, 1,
95
+
96
+ 1, 0, 0,
97
+ 1, 0, 0,
98
+ 1, 0, 0,
99
+ 1, 0, 0,
100
+ 1, 0, 0,
101
+ 1, 0, 0,
102
+
103
+ -1, 0, 0,
104
+ -1, 0, 0,
105
+ -1, 0, 0,
106
+ -1, 0, 0,
107
+ -1, 0, 0,
108
+ -1, 0, 0,
109
+
110
+ -1, 0, 0,
111
+ -1, 0, 0,
112
+ -1, 0, 0,
113
+
114
+ -1, 0, 0,
115
+ -1, 0, 0,
116
+ -1, 0, 0
117
+ ]
118
+ end
119
+
120
+ def mesh_colors(color)
121
+ [
122
+ color.red, color.green, color.blue,
123
+ color.red, color.green, color.blue,
124
+ color.red, color.green, color.blue,
125
+ color.red, color.green, color.blue,
126
+ color.red, color.green, color.blue,
127
+ color.red, color.green, color.blue,
128
+ color.red, color.green, color.blue,
129
+ color.red, color.green, color.blue,
130
+ color.red, color.green, color.blue,
131
+ color.red, color.green, color.blue,
132
+ color.red, color.green, color.blue,
133
+ color.red, color.green, color.blue,
134
+ color.red, color.green, color.blue,
135
+ color.red, color.green, color.blue,
136
+ color.red, color.green, color.blue,
137
+ color.red, color.green, color.blue,
138
+ color.red, color.green, color.blue,
139
+ color.red, color.green, color.blue,
140
+ color.red, color.green, color.blue,
141
+ color.red, color.green, color.blue,
142
+ color.red, color.green, color.blue,
143
+ color.red, color.green, color.blue,
144
+ color.red, color.green, color.blue,
145
+ color.red, color.green, color.blue,
146
+ color.red, color.green, color.blue,
147
+ color.red, color.green, color.blue,
148
+ color.red, color.green, color.blue,
149
+ color.red, color.green, color.blue,
150
+ color.red, color.green, color.blue,
151
+ color.red, color.green, color.blue,
152
+ color.red, color.green, color.blue,
153
+ color.red, color.green, color.blue,
154
+ color.red, color.green, color.blue,
155
+ color.red, color.green, color.blue,
156
+ color.red, color.green, color.blue,
157
+ color.red, color.green, color.blue
158
+ ]
159
+ end
160
+
161
+ def mesh_vertices(box)
162
+ [
163
+ box.min.x, box.max.y, box.max.z,
164
+ box.min.x, box.max.y, box.min.z,
165
+ box.max.x, box.max.y, box.min.z,
166
+
167
+ box.min.x, box.max.y, box.max.z,
168
+ box.max.x, box.max.y, box.max.z,
169
+ box.max.x, box.max.y, box.min.z,
170
+
171
+ box.max.x, box.min.y, box.min.z,
172
+ box.max.x, box.min.y, box.max.z,
173
+ box.min.x, box.min.y, box.max.z,
174
+
175
+ box.max.x, box.min.y, box.min.z,
176
+ box.min.x, box.min.y, box.min.z,
177
+ box.min.x, box.min.y, box.max.z,
178
+
179
+ box.min.x, box.max.y, box.max.z,
180
+ box.min.x, box.max.y, box.min.z,
181
+ box.min.x, box.min.y, box.min.z,
182
+
183
+ box.min.x, box.min.y, box.max.z,
184
+ box.min.x, box.min.y, box.min.z,
185
+ box.min.x, box.max.y, box.max.z,
186
+
187
+ box.max.x, box.max.y, box.max.z,
188
+ box.max.x, box.max.y, box.min.z,
189
+ box.max.x, box.min.y, box.min.z,
190
+
191
+ box.max.x, box.min.y, box.max.z,
192
+ box.max.x, box.min.y, box.min.z,
193
+ box.max.x, box.max.y, box.max.z,
194
+
195
+ box.min.x, box.max.y, box.max.z,
196
+ box.max.x, box.max.y, box.max.z,
197
+ box.max.x, box.min.y, box.max.z,
198
+
199
+ box.min.x, box.max.y, box.max.z,
200
+ box.max.x, box.min.y, box.max.z,
201
+ box.min.x, box.min.y, box.max.z,
202
+
203
+ box.max.x, box.min.y, box.min.z,
204
+ box.min.x, box.min.y, box.min.z,
205
+ box.min.x, box.max.y, box.min.z,
206
+
207
+ box.max.x, box.min.y, box.min.z,
208
+ box.min.x, box.max.y, box.min.z,
209
+ box.max.x, box.max.y, box.min.z
210
+ ]
211
+ end
212
+
213
+ def draw_bounding_boxes
214
+ @bounding_boxes.each do |key, bounding_box|
215
+ glPushMatrix
216
+
217
+ glTranslatef(
218
+ bounding_box[:entity].position.x,
219
+ bounding_box[:entity].position.y,
220
+ bounding_box[:entity].position.z
221
+ )
222
+ draw_bounding_box(bounding_box)
223
+ @bounding_boxes[key][:objects].each { |o| draw_bounding_box(o) }
224
+
225
+ glPopMatrix
226
+ end
227
+ end
228
+
229
+ def draw_bounding_box(bounding_box)
230
+ glEnableClientState(GL_VERTEX_ARRAY)
231
+ glEnableClientState(GL_COLOR_ARRAY)
232
+ glEnableClientState(GL_NORMAL_ARRAY)
233
+
234
+ glVertexPointer(3, GL_FLOAT, 0, bounding_box[:vertices])
235
+ glColorPointer(3, GL_FLOAT, 0, bounding_box[:colors])
236
+ glNormalPointer(GL_FLOAT, 0, bounding_box[:normals])
237
+
238
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
239
+ glDisable(GL_LIGHTING)
240
+ glDrawArrays(GL_TRIANGLES, 0, bounding_box[:vertices_size] / 3)
241
+ glEnable(GL_LIGHTING)
242
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
243
+
244
+ glDisableClientState(GL_VERTEX_ARRAY)
245
+ glDisableClientState(GL_COLOR_ARRAY)
246
+ glDisableClientState(GL_NORMAL_ARRAY)
247
+ end
248
+ end
249
+ end