blackbook3d 0.5.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 (134) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +341 -0
  3. data/README.md +92 -0
  4. data/SETUP.md +70 -0
  5. data/data/assets/Texture/A011a.tga +0 -0
  6. data/data/assets/untitled.awp3d +0 -0
  7. data/data/cube.mtl +12 -0
  8. data/data/cube.obj +246 -0
  9. data/data/cube.raw +12 -0
  10. data/data/engine_conf.json +9 -0
  11. data/data/fighter.raw +19198 -0
  12. data/data/font/100.raw +78 -0
  13. data/data/font/101.raw +99 -0
  14. data/data/font/102.raw +58 -0
  15. data/data/font/103.raw +258 -0
  16. data/data/font/104.raw +55 -0
  17. data/data/font/105.raw +48 -0
  18. data/data/font/106.raw +72 -0
  19. data/data/font/107.raw +6 -0
  20. data/data/font/108.raw +2 -0
  21. data/data/font/109.raw +105 -0
  22. data/data/font/110.raw +55 -0
  23. data/data/font/111.raw +96 -0
  24. data/data/font/112.raw +78 -0
  25. data/data/font/113.raw +78 -0
  26. data/data/font/114.raw +53 -0
  27. data/data/font/115.raw +132 -0
  28. data/data/font/116.raw +56 -0
  29. data/data/font/117.raw +54 -0
  30. data/data/font/118.raw +5 -0
  31. data/data/font/119.raw +11 -0
  32. data/data/font/120.raw +10 -0
  33. data/data/font/121.raw +6 -0
  34. data/data/font/122.raw +6 -0
  35. data/data/font/33.raw +118 -0
  36. data/data/font/37.raw +194 -0
  37. data/data/font/38.raw +200 -0
  38. data/data/font/39.raw +4 -0
  39. data/data/font/40.raw +48 -0
  40. data/data/font/41.raw +48 -0
  41. data/data/font/42.raw +226 -0
  42. data/data/font/43.raw +10 -0
  43. data/data/font/45.raw +2 -0
  44. data/data/font/46.raw +46 -0
  45. data/data/font/47.raw +2 -0
  46. data/data/font/48.raw +96 -0
  47. data/data/font/49.raw +2 -0
  48. data/data/font/50.raw +87 -0
  49. data/data/font/51.raw +145 -0
  50. data/data/font/52.raw +15 -0
  51. data/data/font/53.raw +76 -0
  52. data/data/font/54.raw +121 -0
  53. data/data/font/55.raw +4 -0
  54. data/data/font/56.raw +194 -0
  55. data/data/font/57.raw +133 -0
  56. data/data/font/61.raw +4 -0
  57. data/data/font/63.raw +117 -0
  58. data/data/font/65.raw +11 -0
  59. data/data/font/66.raw +108 -0
  60. data/data/font/67.raw +96 -0
  61. data/data/font/68.raw +54 -0
  62. data/data/font/69.raw +10 -0
  63. data/data/font/70.raw +8 -0
  64. data/data/font/71.raw +100 -0
  65. data/data/font/72.raw +10 -0
  66. data/data/font/73.raw +2 -0
  67. data/data/font/74.raw +39 -0
  68. data/data/font/75.raw +9 -0
  69. data/data/font/76.raw +4 -0
  70. data/data/font/77.raw +13 -0
  71. data/data/font/78.raw +8 -0
  72. data/data/font/79.raw +96 -0
  73. data/data/font/80.raw +56 -0
  74. data/data/font/81.raw +124 -0
  75. data/data/font/82.raw +94 -0
  76. data/data/font/83.raw +120 -0
  77. data/data/font/84.raw +6 -0
  78. data/data/font/85.raw +76 -0
  79. data/data/font/86.raw +5 -0
  80. data/data/font/87.raw +11 -0
  81. data/data/font/88.raw +10 -0
  82. data/data/font/89.raw +7 -0
  83. data/data/font/90.raw +6 -0
  84. data/data/font/91.raw +6 -0
  85. data/data/font/93.raw +6 -0
  86. data/data/font/94.raw +5 -0
  87. data/data/font/95.raw +2 -0
  88. data/data/font/97.raw +174 -0
  89. data/data/font/98.raw +100 -0
  90. data/data/font/99.raw +96 -0
  91. data/data/ground.raw +12 -0
  92. data/data/man.mtl +12 -0
  93. data/data/man.obj +7547 -0
  94. data/data/robo.mtl +11 -0
  95. data/data/robo.obj +42065 -0
  96. data/data/space.json +49 -0
  97. data/data/sphere.raw +1216 -0
  98. data/data/texture/Charcoal-2.jpg +0 -0
  99. data/data/texture/man.png +0 -0
  100. data/data/texture/man.tif +0 -0
  101. data/data/texture/t.jpg +0 -0
  102. data/data/texture/wood.jpg +0 -0
  103. data/data/texture/wood.png +0 -0
  104. data/data/texture/x.jpg +0 -0
  105. data/data/untitled.raw +124 -0
  106. data/data/w.raw +12474 -0
  107. data/data/wings.raw +45670 -0
  108. data/lib/BlackBook/anim.rb +184 -0
  109. data/lib/BlackBook/b3dobject.rb +475 -0
  110. data/lib/BlackBook/base.rb +79 -0
  111. data/lib/BlackBook/camera.rb +202 -0
  112. data/lib/BlackBook/color.rb +29 -0
  113. data/lib/BlackBook/constants.rb +327 -0
  114. data/lib/BlackBook/engine.rb +172 -0
  115. data/lib/BlackBook/functions.rb +650 -0
  116. data/lib/BlackBook/light.rb +91 -0
  117. data/lib/BlackBook/logger.rb +86 -0
  118. data/lib/BlackBook/material.rb +98 -0
  119. data/lib/BlackBook/registry.rb +71 -0
  120. data/lib/BlackBook/space.rb +396 -0
  121. data/lib/BlackBook/stime.rb +64 -0
  122. data/lib/Plugins/string_color.rb +74 -0
  123. data/lib/blackbook/version.rb +5 -0
  124. data/lib/blackbook.rb +52 -0
  125. data/lib/plugins.rb +32 -0
  126. data/lib/ui/button.rb +115 -0
  127. data/lib/ui/edit.rb +105 -0
  128. data/lib/ui/text.rb +284 -0
  129. data/lib/ui/ui.rb +88 -0
  130. data/lib/ui/ui_element.rb +45 -0
  131. data/lib/ui/window.rb +138 -0
  132. data/lib/ui.rb +30 -0
  133. data/lib/zipfile.rb +27 -0
  134. metadata +254 -0
@@ -0,0 +1,91 @@
1
+ ##############################################################################
2
+ # BlackBook 3D Engine
3
+ # Copyright (C) 2015 Sinan ISLEKDEMIR
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program; if not, write to the Free Software Foundation, Inc.,
17
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ ##############################################################################
19
+
20
+ #################################################################
21
+ # Project BlackBook
22
+ # Lead Engineer: Sinan ISLEKDEMIR
23
+ # Simulation Engine Ruby Sources
24
+ ################################################################
25
+
26
+ require 'opengl'
27
+ require 'BlackBook/base'
28
+ require 'BlackBook/functions'
29
+
30
+ module BlackBook
31
+ #
32
+ # Main Light Object
33
+ #
34
+ # @author [sinan islekdemir]
35
+ #
36
+ # @attr index [Integer] Main index counter of OpenGL Lights (1..8)
37
+ # @attr self_index [Integer] Light Index of the current light
38
+ # @attr position [CVector] Position of the light
39
+ # @attr draw_light [Boolean] Draw the light sphere or not?
40
+ # @attr diffuse [CVector] Diffuse color RGBA(255, 255, 255, 1)
41
+ # @attr light_draw_radius [Float] Draw sphere radius if draw_light is true
42
+ #
43
+ class Light < Base
44
+ attr_accessor :index, :self_index, :position, :draw_light, :diffuse,
45
+ :light_draw_radius
46
+
47
+ @@index = 0
48
+ #
49
+ # Create a new light object
50
+ # @param options [Hash] Options (:position, :draw_light, :diffuse...)
51
+ #
52
+ # @return [Boolean] Success
53
+ def initialize( opts = {} )
54
+ @light_draw_radius = opts[:light_draw_raidus] || 1.0
55
+ @self_index = @@index
56
+ @draw_light = true
57
+ @position = opts[:position] || CVector.new(0.0, 0.0, 10.0)
58
+ @diffuse = opts[:diffuse] || CVector.new(1.0, 1.0, 1.0, 1.0)
59
+ @draw_light = opts[:draw_light] || true
60
+ @@index += 1
61
+ end
62
+
63
+ #
64
+ # Simple rendering procedure
65
+ #
66
+ # @return [Boolean] Success
67
+ def render
68
+ return false if @self_index > 7
69
+ GL.Enable(GL::COLOR_MATERIAL)
70
+ if @draw_light
71
+ GL.Disable(GL::LIGHTING)
72
+ GL.PushMatrix
73
+ BlackBook.apply_color(CVector.new(255, 255, 0, 1))
74
+ GL.Translatef(@position.x, @position.y, @position.z)
75
+ BlackBook.draw_circle(@light_draw_radius, 10)
76
+ GL.Rotatef(90.0, 1.0, 0, 0)
77
+ BlackBook.draw_circle(@light_draw_radius, 10)
78
+ BlackBook.apply_color(CVector.new(255, 255, 255, 1))
79
+ GL.PopMatrix
80
+ GL.Enable(GL::LIGHTING)
81
+ end
82
+ light = GL::LIGHT0 + @self_index # (16384 + ...)
83
+ GL.Light(light, GL::DIFFUSE, @diffuse.to_array)
84
+ GL.Light(light, GL::POSITION, @position.to_array)
85
+ GL.Enable(light)
86
+ GL.Enable(GL::LIGHTING)
87
+ GL.Enable(GL::DEPTH_TEST)
88
+ return true
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,86 @@
1
+ ##############################################################################
2
+ # BlackBook 3D Engine
3
+ # Copyright (C) 2015 Sinan ISLEKDEMIR
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program; if not, write to the Free Software Foundation, Inc.,
17
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ ##############################################################################
19
+
20
+ ################################################################
21
+ # Project BlackBook
22
+ # Lead Engineer: Sinan ISLEKDEMIR
23
+ # Simulation Engine Ruby Sources
24
+ ################################################################
25
+
26
+ require 'pp'
27
+ require 'singleton'
28
+
29
+ module BlackBook
30
+ # Application-wide logging class
31
+ class Logger
32
+ include Singleton
33
+ attr_accessor :filename, :stdout, :file
34
+
35
+ def initialize
36
+ end
37
+
38
+ def define(args)
39
+ @file = nil # There has to be only one file instance
40
+ if args.key?(:filename)
41
+ @filename = args[:filename]
42
+ @file = File.open(@filename, 'a')
43
+ end
44
+ @stdout = args.key?(:stdout) && args[:stdout]
45
+ end
46
+
47
+ def warning(message)
48
+ @file.printf(
49
+ "%-27s - %-10s : %s \n",
50
+ Time.now.to_s,
51
+ 'WARNING',
52
+ message
53
+ ) unless @file.nil?
54
+ printf "%-10s : %s\n", 'WARNING', message if @stdout
55
+ end
56
+
57
+ def error(message)
58
+ @file.printf(
59
+ "%-27s - %-10s : %s \n",
60
+ Time.now.to_s,
61
+ 'ERROR',
62
+ message
63
+ ) unless @file.nil?
64
+ printf "%-10s : %s\n", 'ERROR', message if @stdout
65
+ end
66
+
67
+ def info(message)
68
+ @file.printf(
69
+ "%-27s - %-10s : %s \n",
70
+ Time.now.to_s,
71
+ 'INFORM',
72
+ message
73
+ ) unless @file.nil?
74
+ printf "%-10s : %s\n", 'INFORM', message if @stdout
75
+ end
76
+
77
+ def dump(data)
78
+ @file.printf "%-27s - %-10s : \n", Time.now.to_s, 'DATA:'
79
+ PP.pp(data, @file)
80
+ @file.printf "\n"
81
+ printf "%-10s : \n", 'DATA:'
82
+ PP.pp(data)
83
+ printf "\n"
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,98 @@
1
+ ##############################################################################
2
+ # BlackBook 3D Engine
3
+ # Copyright (C) 2015 Sinan ISLEKDEMIR
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program; if not, write to the Free Software Foundation, Inc.,
17
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ ##############################################################################
19
+
20
+ ################################################################
21
+ # Project BlackBook
22
+ # Lead Engineer: Sinan ISLEKDEMIR
23
+ # Simulation Engine Ruby Sources
24
+ ################################################################
25
+
26
+ require 'opengl'
27
+ require 'mini_magick'
28
+ require 'BlackBook/base'
29
+ require 'BlackBook/constants'
30
+
31
+ # BlackBook Material
32
+ module BlackBook
33
+ # BlackBook Material
34
+ class Material
35
+ attr_accessor :color, :texture_data, :image_w, :image_h
36
+
37
+ # Initialize material
38
+ def initialize
39
+ @color = CVector.new(1.0, 1.0, 1.0, 1.0)
40
+ @image_w = 0
41
+ @image_h = 0
42
+ @texture_file = ''
43
+ @loaded = false
44
+ end
45
+
46
+ def load_texture(filename)
47
+ @texture_file = filename
48
+ end
49
+
50
+ def texture(filename)
51
+ image = MiniMagick::Image.open(filename)
52
+ @image_w = image.width
53
+ @image_h = image.height
54
+
55
+ # Export pixels as RGBA using ImageMagick
56
+ rgba_data = image.get_pixels('RGBA')
57
+ # Flatten the 2D array of pixels and convert to byte array
58
+ @texture_data = rgba_data.flatten
59
+
60
+ @tex = GL::GenTextures(1)
61
+ GL.BindTexture(GL::TEXTURE_2D, @tex[0])
62
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_S, GL::CLAMP)
63
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_WRAP_T, GL::CLAMP)
64
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::NEAREST)
65
+ GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::NEAREST)
66
+ GL.TexImage2D(
67
+ GL::TEXTURE_2D, 0, GL::RGBA, @image_w,
68
+ @image_h, 0, GL::RGBA, GL::UNSIGNED_BYTE, @texture_data.pack('C*')
69
+ )
70
+ @loaded = true
71
+ end
72
+
73
+ # Render material
74
+ def start_render
75
+ texture(@texture_file) if @loaded == false && !@texture_file.empty?
76
+
77
+ if @image_w + @image_h > 0
78
+ GL.Enable(GL::TEXTURE_2D)
79
+ GL.BindTexture(GL::TEXTURE_2D, @tex[0])
80
+ else
81
+ GL.Enable(GL::COLOR_MATERIAL)
82
+ GL.Enable(GL::BLEND)
83
+ GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA)
84
+ GL.Color4f(@color.x, @color.y, @color.z, @color.w)
85
+ end
86
+ end
87
+
88
+ # End Material
89
+ def end_render
90
+ if @image_w + @image_h > 0
91
+ GL.Disable(GL::TEXTURE_2D)
92
+ else
93
+ GL.Disable(GL::BLEND)
94
+ GL.Disable(GL::COLOR_MATERIAL)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,71 @@
1
+ ##############################################################################
2
+ # BlackBook 3D Engine
3
+ # Copyright (C) 2015 Sinan ISLEKDEMIR
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program; if not, write to the Free Software Foundation, Inc.,
17
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
+ ##############################################################################
19
+
20
+ require 'singleton'
21
+ require 'json'
22
+
23
+ # Blackbook Registry for global variables
24
+ module BlackBook
25
+ # Singleton Registry class
26
+ class Registry
27
+ include Singleton
28
+
29
+ attr_accessor :params
30
+
31
+ # Create empty hash
32
+ def initialize
33
+ @params = {}
34
+ end
35
+
36
+ # read object from hash, return nil if not found
37
+ def read(key)
38
+ @params[key] || nil
39
+ end
40
+
41
+ # write to instance hash
42
+ def write(key, value)
43
+ @params[key] = value
44
+ end
45
+
46
+ # actually just a shortcut :)
47
+ def exists(key)
48
+ @params.key? key
49
+ end
50
+
51
+ # save current parameters to file as json
52
+ def save_to_file(filename)
53
+ File.write filename, @params.to_json
54
+ end
55
+
56
+ # load from json file
57
+ def load_from_file(filename)
58
+ buffer = File.read(filename)
59
+ @params = JSON.parse(buffer)
60
+ end
61
+
62
+ class << self
63
+ def setup( opts = {} )
64
+ opts.map do |x, y|
65
+ BlackBook::Registry.instance.write x.to_s, y
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end