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.
- checksums.yaml +7 -0
- data/LICENSE +341 -0
- data/README.md +92 -0
- data/SETUP.md +70 -0
- data/data/assets/Texture/A011a.tga +0 -0
- data/data/assets/untitled.awp3d +0 -0
- data/data/cube.mtl +12 -0
- data/data/cube.obj +246 -0
- data/data/cube.raw +12 -0
- data/data/engine_conf.json +9 -0
- data/data/fighter.raw +19198 -0
- data/data/font/100.raw +78 -0
- data/data/font/101.raw +99 -0
- data/data/font/102.raw +58 -0
- data/data/font/103.raw +258 -0
- data/data/font/104.raw +55 -0
- data/data/font/105.raw +48 -0
- data/data/font/106.raw +72 -0
- data/data/font/107.raw +6 -0
- data/data/font/108.raw +2 -0
- data/data/font/109.raw +105 -0
- data/data/font/110.raw +55 -0
- data/data/font/111.raw +96 -0
- data/data/font/112.raw +78 -0
- data/data/font/113.raw +78 -0
- data/data/font/114.raw +53 -0
- data/data/font/115.raw +132 -0
- data/data/font/116.raw +56 -0
- data/data/font/117.raw +54 -0
- data/data/font/118.raw +5 -0
- data/data/font/119.raw +11 -0
- data/data/font/120.raw +10 -0
- data/data/font/121.raw +6 -0
- data/data/font/122.raw +6 -0
- data/data/font/33.raw +118 -0
- data/data/font/37.raw +194 -0
- data/data/font/38.raw +200 -0
- data/data/font/39.raw +4 -0
- data/data/font/40.raw +48 -0
- data/data/font/41.raw +48 -0
- data/data/font/42.raw +226 -0
- data/data/font/43.raw +10 -0
- data/data/font/45.raw +2 -0
- data/data/font/46.raw +46 -0
- data/data/font/47.raw +2 -0
- data/data/font/48.raw +96 -0
- data/data/font/49.raw +2 -0
- data/data/font/50.raw +87 -0
- data/data/font/51.raw +145 -0
- data/data/font/52.raw +15 -0
- data/data/font/53.raw +76 -0
- data/data/font/54.raw +121 -0
- data/data/font/55.raw +4 -0
- data/data/font/56.raw +194 -0
- data/data/font/57.raw +133 -0
- data/data/font/61.raw +4 -0
- data/data/font/63.raw +117 -0
- data/data/font/65.raw +11 -0
- data/data/font/66.raw +108 -0
- data/data/font/67.raw +96 -0
- data/data/font/68.raw +54 -0
- data/data/font/69.raw +10 -0
- data/data/font/70.raw +8 -0
- data/data/font/71.raw +100 -0
- data/data/font/72.raw +10 -0
- data/data/font/73.raw +2 -0
- data/data/font/74.raw +39 -0
- data/data/font/75.raw +9 -0
- data/data/font/76.raw +4 -0
- data/data/font/77.raw +13 -0
- data/data/font/78.raw +8 -0
- data/data/font/79.raw +96 -0
- data/data/font/80.raw +56 -0
- data/data/font/81.raw +124 -0
- data/data/font/82.raw +94 -0
- data/data/font/83.raw +120 -0
- data/data/font/84.raw +6 -0
- data/data/font/85.raw +76 -0
- data/data/font/86.raw +5 -0
- data/data/font/87.raw +11 -0
- data/data/font/88.raw +10 -0
- data/data/font/89.raw +7 -0
- data/data/font/90.raw +6 -0
- data/data/font/91.raw +6 -0
- data/data/font/93.raw +6 -0
- data/data/font/94.raw +5 -0
- data/data/font/95.raw +2 -0
- data/data/font/97.raw +174 -0
- data/data/font/98.raw +100 -0
- data/data/font/99.raw +96 -0
- data/data/ground.raw +12 -0
- data/data/man.mtl +12 -0
- data/data/man.obj +7547 -0
- data/data/robo.mtl +11 -0
- data/data/robo.obj +42065 -0
- data/data/space.json +49 -0
- data/data/sphere.raw +1216 -0
- data/data/texture/Charcoal-2.jpg +0 -0
- data/data/texture/man.png +0 -0
- data/data/texture/man.tif +0 -0
- data/data/texture/t.jpg +0 -0
- data/data/texture/wood.jpg +0 -0
- data/data/texture/wood.png +0 -0
- data/data/texture/x.jpg +0 -0
- data/data/untitled.raw +124 -0
- data/data/w.raw +12474 -0
- data/data/wings.raw +45670 -0
- data/lib/BlackBook/anim.rb +184 -0
- data/lib/BlackBook/b3dobject.rb +475 -0
- data/lib/BlackBook/base.rb +79 -0
- data/lib/BlackBook/camera.rb +202 -0
- data/lib/BlackBook/color.rb +29 -0
- data/lib/BlackBook/constants.rb +327 -0
- data/lib/BlackBook/engine.rb +172 -0
- data/lib/BlackBook/functions.rb +650 -0
- data/lib/BlackBook/light.rb +91 -0
- data/lib/BlackBook/logger.rb +86 -0
- data/lib/BlackBook/material.rb +98 -0
- data/lib/BlackBook/registry.rb +71 -0
- data/lib/BlackBook/space.rb +396 -0
- data/lib/BlackBook/stime.rb +64 -0
- data/lib/Plugins/string_color.rb +74 -0
- data/lib/blackbook/version.rb +5 -0
- data/lib/blackbook.rb +52 -0
- data/lib/plugins.rb +32 -0
- data/lib/ui/button.rb +115 -0
- data/lib/ui/edit.rb +105 -0
- data/lib/ui/text.rb +284 -0
- data/lib/ui/ui.rb +88 -0
- data/lib/ui/ui_element.rb +45 -0
- data/lib/ui/window.rb +138 -0
- data/lib/ui.rb +30 -0
- data/lib/zipfile.rb +27 -0
- metadata +254 -0
data/lib/ui/button.rb
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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 'ui/ui_element'
|
|
27
|
+
require 'ui/text'
|
|
28
|
+
require 'BlackBook/constants'
|
|
29
|
+
require 'BlackBook/functions'
|
|
30
|
+
|
|
31
|
+
module UI
|
|
32
|
+
#
|
|
33
|
+
# BB Button Class
|
|
34
|
+
#
|
|
35
|
+
# @attr label [String] Label on button
|
|
36
|
+
# @attr click [Method] OnClick event handler
|
|
37
|
+
# @attr caption [BBText] Caption object over button surface
|
|
38
|
+
# @attr hover [CVector] OnHover Color
|
|
39
|
+
# @attr font_size [Integer] Font Size in Pixels
|
|
40
|
+
# @attr caption_w [Integer] width of the caption in pixels
|
|
41
|
+
# @author [sinan islekdemir]
|
|
42
|
+
#
|
|
43
|
+
class Button < UiElement
|
|
44
|
+
attr_accessor :label, :click, :caption, :hover, :font_size, :caption_w
|
|
45
|
+
|
|
46
|
+
#
|
|
47
|
+
# Initialize BBButton Element
|
|
48
|
+
# @param options [Hash] (x, y, z, w, h, title, font_size)
|
|
49
|
+
#
|
|
50
|
+
# @return [Boolean] Reposition done
|
|
51
|
+
def initialize( opts = {} )
|
|
52
|
+
super
|
|
53
|
+
title = opts[:title] || ''
|
|
54
|
+
@font_size = opts[:font_size] || 13
|
|
55
|
+
@caption = Text.new(x: 0,
|
|
56
|
+
y: 0,
|
|
57
|
+
h: @font_size,
|
|
58
|
+
title: title)
|
|
59
|
+
@caption_w = @caption.width
|
|
60
|
+
@click = nil
|
|
61
|
+
@hover = false
|
|
62
|
+
@h = @font_size + 2
|
|
63
|
+
reposition
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# Reposition text on button in case of changing title
|
|
68
|
+
#
|
|
69
|
+
# @return [Boolean] Success
|
|
70
|
+
def reposition
|
|
71
|
+
@w = @caption.width + 30 if @w < @caption.width + 30
|
|
72
|
+
@caption.d = 2
|
|
73
|
+
@caption.position.z = 2
|
|
74
|
+
@caption.position.x = (@w - @caption_w) / 2
|
|
75
|
+
@caption.position.y = @y + @font_size
|
|
76
|
+
true
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# Mouse event handler
|
|
81
|
+
# @param x [Integer] Cursor X Position
|
|
82
|
+
# @param y [Integer] Cursor Y Position
|
|
83
|
+
# @param right_b [Integer] Right Mouse Button
|
|
84
|
+
# @param left_b [Integer] Left Mouse Button
|
|
85
|
+
# @param middle_b [Integer] Middle Mouse Button
|
|
86
|
+
#
|
|
87
|
+
# @return [Boolean] Success
|
|
88
|
+
def mouse(x_coord, y_coord, right_b, left_b, middle_b)
|
|
89
|
+
@hover = x_coord > @x && x_coord < @x + @w && y_coord > @y && y_coord < @y + @h
|
|
90
|
+
click.call if left_b == 1 && @hover
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# General Renderer
|
|
95
|
+
#
|
|
96
|
+
# @return [Boolean] Success
|
|
97
|
+
def render
|
|
98
|
+
color_hover = BlackBook::CVector.new(255, 165, 0, 0.8)
|
|
99
|
+
color_normal = BlackBook::CVector.new(0, 0, 0, 0.8)
|
|
100
|
+
color = @hover ? color_hover : color_normal
|
|
101
|
+
options = {
|
|
102
|
+
x: @x, y: @y, z: 1 / (10000 - @z.to_f),
|
|
103
|
+
width: @w, height: @h, color: color,
|
|
104
|
+
border: true, border_color: BlackBook::CVector.new(255, 165, 0, 0.8)
|
|
105
|
+
}
|
|
106
|
+
BlackBook.draw_box_2d(options)
|
|
107
|
+
GL.PushMatrix
|
|
108
|
+
GL.Translatef(5, 0, 1 / (10000 - @z.to_f))
|
|
109
|
+
@hover ? @caption.color.set(0, 0, 0) : @caption.color.set(1.0, 1.0, 1.0)
|
|
110
|
+
@caption.y = 5
|
|
111
|
+
@caption.render
|
|
112
|
+
GL.PopMatrix
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
data/lib/ui/edit.rb
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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 'ui/ui_element'
|
|
27
|
+
require 'ui/text'
|
|
28
|
+
require 'BlackBook/functions'
|
|
29
|
+
|
|
30
|
+
module UI
|
|
31
|
+
#
|
|
32
|
+
# BB Edit Class
|
|
33
|
+
#
|
|
34
|
+
# @attr value [String] String Value of edit
|
|
35
|
+
# @attr on_keypress [Method] On Keypress Event
|
|
36
|
+
# @attr font_size [Integer] Font size in Pixels
|
|
37
|
+
# @attr max_chars [Integer] Max Size of characters
|
|
38
|
+
# @attr focus [Boolean] Item focusted?
|
|
39
|
+
# @author [sinan islekdemir]
|
|
40
|
+
#
|
|
41
|
+
class Edit < UiElement
|
|
42
|
+
attr_accessor :value, :on_keypress, :font_size, :max_chars, :focus,
|
|
43
|
+
:text
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Initialize BBEdit Element
|
|
47
|
+
# @param options [Hash] (x,y,z,w,h,value,font_size)
|
|
48
|
+
#
|
|
49
|
+
# @return [Boolean] Focus
|
|
50
|
+
def initialize( opts = {} )
|
|
51
|
+
super
|
|
52
|
+
@font_size = opts[:font_size] || 13
|
|
53
|
+
@max_chars = opts[:max_chars] || 255
|
|
54
|
+
@value = opts[:value] || ''
|
|
55
|
+
@focus = opts[:focus] || false
|
|
56
|
+
@on_keypress = nil
|
|
57
|
+
@text = Text.new(x: 0, y: 0, h: @font_size, title: value)
|
|
58
|
+
@text.color.set(200, 200, 200)
|
|
59
|
+
@text.d = 2
|
|
60
|
+
@h = @font_size + 10.0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def render
|
|
64
|
+
color = BlackBook::CVector.new(0, 0, 0, 0.8)
|
|
65
|
+
options = {
|
|
66
|
+
x: @x, y: @y, z: 1 / (10000 - @z.to_f),
|
|
67
|
+
width: @w, height: @h, color: color,
|
|
68
|
+
border: true, border_color: BlackBook::CVector.new(0, 255, 255, 0.8)
|
|
69
|
+
}
|
|
70
|
+
BlackBook.draw_box_2d(options)
|
|
71
|
+
GL.PushMatrix
|
|
72
|
+
GL.Translatef(@x, @y, 1 / (10000 - @z.to_f + 1000))
|
|
73
|
+
@text.text = @value
|
|
74
|
+
@text.position.x = 10
|
|
75
|
+
@text.position.y = 30
|
|
76
|
+
@text.render
|
|
77
|
+
GL.PopMatrix
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
#
|
|
81
|
+
# Mouse event handler
|
|
82
|
+
# @param x [Integer] Cursor X Position
|
|
83
|
+
# @param y [Integer] Cursor Y Position
|
|
84
|
+
# @param right_b [Integer] Right Mouse Button
|
|
85
|
+
# @param left_b [Integer] Left Mouse Button
|
|
86
|
+
# @param middle_b [Integer] Middle Mouse Button
|
|
87
|
+
#
|
|
88
|
+
# @return [Boolean] Success
|
|
89
|
+
def mouse(x, y, right_b, left_b, middle_b)
|
|
90
|
+
x -= @x
|
|
91
|
+
y -= @y
|
|
92
|
+
@hover = false
|
|
93
|
+
return false unless left_b == 1
|
|
94
|
+
if (x > 0 && x < @w && y > 0 && y < @h) && left_b == 1
|
|
95
|
+
focus = true
|
|
96
|
+
elsif (x < 0 || x > @w || y < 0 || y > @h) && left_b == 1
|
|
97
|
+
focus = false
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def key(char)
|
|
102
|
+
@value += char
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
data/lib/ui/text.rb
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
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/constants'
|
|
28
|
+
require 'BlackBook/base'
|
|
29
|
+
require 'ui/ui_element'
|
|
30
|
+
|
|
31
|
+
module UI
|
|
32
|
+
#
|
|
33
|
+
# BBChar Item - Holds 3D Vertex data for a character
|
|
34
|
+
#
|
|
35
|
+
# @attr index [Integer] OpenGL ListIndex
|
|
36
|
+
# @attr char [String] Character
|
|
37
|
+
# @attr width [Float] Char Width
|
|
38
|
+
# @attr font_path [String] Path to font files
|
|
39
|
+
# @attr faces [Array] Vertice Array for Faces
|
|
40
|
+
# @attr position [CVector] Position Vector
|
|
41
|
+
# @attr min [CVector] Min. Vertice
|
|
42
|
+
# @attr max [CVector] Max. Vertice
|
|
43
|
+
# @author [sinan islekdemir]
|
|
44
|
+
#
|
|
45
|
+
class Char < BlackBook::Base
|
|
46
|
+
attr_accessor :index, :char, :width, :font_path, :faces, :position,
|
|
47
|
+
:min, :max
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# Initialize character
|
|
51
|
+
#
|
|
52
|
+
# @return [Boolean] Success
|
|
53
|
+
def initialize
|
|
54
|
+
@index = -1
|
|
55
|
+
@position = BlackBook::CVector.new(0, 0, 0, 1)
|
|
56
|
+
@faces = []
|
|
57
|
+
@min = nil
|
|
58
|
+
@max = nil
|
|
59
|
+
super
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
#
|
|
63
|
+
# Add Face to Character Object
|
|
64
|
+
# @param vertex_array [Array] Array of vertices (raw file format)
|
|
65
|
+
#
|
|
66
|
+
# @return [Boolean] Success
|
|
67
|
+
def add_face(vertex_array)
|
|
68
|
+
@faces.push(vertex_array)
|
|
69
|
+
return true
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def get_width
|
|
73
|
+
@width = 0.0
|
|
74
|
+
min_x = 9e10
|
|
75
|
+
min_y = 9e10
|
|
76
|
+
min_z = 9e10
|
|
77
|
+
max_x = -9e10
|
|
78
|
+
max_y = -9e10
|
|
79
|
+
max_z = -9e10
|
|
80
|
+
@faces.each do |face|
|
|
81
|
+
dx = [face[0], face[3], face[6]].minmax
|
|
82
|
+
dy = [face[1], face[4], face[7]].minmax
|
|
83
|
+
dz = [face[2], face[5], face[8]].minmax
|
|
84
|
+
min_x = dx[0] if dx[0] < min_x
|
|
85
|
+
min_y = dy[0] if dy[0] < min_y
|
|
86
|
+
min_z = dz[0] if dz[0] < min_z
|
|
87
|
+
max_x = dx[1] if dx[1] > max_x
|
|
88
|
+
max_y = dy[1] if dy[1] > max_y
|
|
89
|
+
max_z = dz[1] if dz[1] > max_z
|
|
90
|
+
end
|
|
91
|
+
@width = max_x - min_x
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
#
|
|
95
|
+
# Build OpenGL Display List
|
|
96
|
+
#
|
|
97
|
+
# @return [Float] Char Width
|
|
98
|
+
def build_list
|
|
99
|
+
@index = GL.GenLists(1)
|
|
100
|
+
@width = 0.0
|
|
101
|
+
min_x = 9e10
|
|
102
|
+
min_y = 9e10
|
|
103
|
+
min_z = 9e10
|
|
104
|
+
max_x = -9e10
|
|
105
|
+
max_y = -9e10
|
|
106
|
+
max_z = -9e10
|
|
107
|
+
v1 = BlackBook::CVector.new(0, 0, 0, 1)
|
|
108
|
+
v2 = BlackBook::CVector.new(0, 0, 0, 1)
|
|
109
|
+
v3 = BlackBook::CVector.new(0, 0, 0, 1)
|
|
110
|
+
GL.NewList(@index, GL::COMPILE)
|
|
111
|
+
GL.LineWidth(2)
|
|
112
|
+
@faces.each do |face|
|
|
113
|
+
vertex_count = face.count / 3
|
|
114
|
+
v1.x = face[0]
|
|
115
|
+
v1.y = face[1]
|
|
116
|
+
v1.z = face[2]
|
|
117
|
+
v2.x = face[3]
|
|
118
|
+
v2.y = face[4]
|
|
119
|
+
v2.z = face[5]
|
|
120
|
+
v3.x = face[6]
|
|
121
|
+
v3.y = face[7]
|
|
122
|
+
v3.z = face[8]
|
|
123
|
+
dx = [face[0], face[3], face[6]].minmax
|
|
124
|
+
dy = [face[1], face[4], face[7]].minmax
|
|
125
|
+
dz = [face[2], face[5], face[8]].minmax
|
|
126
|
+
min_x = dx[0] if dx[0] < min_x
|
|
127
|
+
min_y = dy[0] if dy[0] < min_y
|
|
128
|
+
min_z = dz[0] if dz[0] < min_z
|
|
129
|
+
max_x = dx[1] if dx[1] > max_x
|
|
130
|
+
max_y = dy[1] if dy[1] > max_y
|
|
131
|
+
max_z = dz[1] if dz[1] > max_z
|
|
132
|
+
normal = BlackBook.calc_plane_normal(v1, v2, v3)
|
|
133
|
+
GL.Begin(GL::TRIANGLES)
|
|
134
|
+
1.upto(vertex_count) do |index|
|
|
135
|
+
i = (index - 1) * 3
|
|
136
|
+
GL.Normal3f(normal.x, normal.y, normal.z)
|
|
137
|
+
GL.Vertex3f(face[i], face[i + 1], face[i + 2])
|
|
138
|
+
end
|
|
139
|
+
GL.End
|
|
140
|
+
end
|
|
141
|
+
GL.EndList
|
|
142
|
+
@width = max_x - min_x
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
#
|
|
146
|
+
# Load Character from file and build display list
|
|
147
|
+
# @param c [String] Character to load
|
|
148
|
+
# @param build_list [boolean] Build list?
|
|
149
|
+
#
|
|
150
|
+
# @return [Float] Character width
|
|
151
|
+
def load_char(c, build_lists = false)
|
|
152
|
+
filename = @font_path + '/' + c.ord.to_s + '.raw'
|
|
153
|
+
file = File.open(filename, 'r')
|
|
154
|
+
file.each_line do |line|
|
|
155
|
+
items = line.split(' ')
|
|
156
|
+
f_items = []
|
|
157
|
+
items.each do |item|
|
|
158
|
+
f_items.push item.to_f
|
|
159
|
+
end
|
|
160
|
+
add_face f_items
|
|
161
|
+
end
|
|
162
|
+
@char = c
|
|
163
|
+
get_width
|
|
164
|
+
build_list if build_lists
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
#
|
|
168
|
+
# Render Function
|
|
169
|
+
#
|
|
170
|
+
def render
|
|
171
|
+
build_list if @index == -1
|
|
172
|
+
GL.CallList(@index)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
#
|
|
177
|
+
# BBText Object. Suitable for both 2D and 3D Rendering
|
|
178
|
+
#
|
|
179
|
+
# @attr font [Hash] Font char hash
|
|
180
|
+
# @attr position [CVector] Position of text
|
|
181
|
+
# @attr roll [Float] Roll angle in degrees
|
|
182
|
+
# @attr yaw [Float] Yaw angle in degrees
|
|
183
|
+
# @attr pitch [Float] Pitch angle in degrees
|
|
184
|
+
# @attr scale [Float] Scale factor
|
|
185
|
+
# @attr d [Integer] 2 - Draw in 2D | 3 - Draw in 3D
|
|
186
|
+
# @attr text [String] Text to render
|
|
187
|
+
# @attr color [CVector] Color of text
|
|
188
|
+
# @attr gl_active [Boolean] OpenGL Initialized and activated
|
|
189
|
+
#
|
|
190
|
+
# @author [sinan]
|
|
191
|
+
#
|
|
192
|
+
class Text < UiElement
|
|
193
|
+
attr_accessor :font, :position, :roll, :pitch, :yaw, :scale, :d, :text,
|
|
194
|
+
:color, :gl_active
|
|
195
|
+
|
|
196
|
+
#
|
|
197
|
+
# Initialize BBText
|
|
198
|
+
# @param options [Hash] (x, y, z, w, h, title)
|
|
199
|
+
#
|
|
200
|
+
# @return [type] [description]
|
|
201
|
+
def initialize( opts = {} )
|
|
202
|
+
super
|
|
203
|
+
@d = 3
|
|
204
|
+
@text = opts[:title]
|
|
205
|
+
@font = {}
|
|
206
|
+
@position = BlackBook::CVector.new(0, 0, 0, 1)
|
|
207
|
+
@scale = BlackBook::CVector.new(1, 1, 1, 1)
|
|
208
|
+
@scale.multiply(opts[:h] || 13)
|
|
209
|
+
@color = BlackBook::CVector.new(1, 1, 1, 1)
|
|
210
|
+
@roll = 0.0
|
|
211
|
+
@pitch = 0.0
|
|
212
|
+
@yaw = 0.0
|
|
213
|
+
@gl_active = false
|
|
214
|
+
data_path = BlackBook::Registry.instance.read('data_path') || './data'
|
|
215
|
+
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
|
|
216
|
+
'01234567890!\'^+%&/()=?-_.'
|
|
217
|
+
chars.each_char do |c|
|
|
218
|
+
bb_char = Char.new
|
|
219
|
+
bb_char.font_path = data_path + '/font'
|
|
220
|
+
bb_char.load_char c
|
|
221
|
+
@font[c] = bb_char
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
#
|
|
226
|
+
# Total width of the text
|
|
227
|
+
#
|
|
228
|
+
# @return [Float] Width
|
|
229
|
+
def width
|
|
230
|
+
w = 0.0
|
|
231
|
+
@text.each_char do |c|
|
|
232
|
+
w += 0.5 if c == ' '
|
|
233
|
+
w += @font[c].width + 0.1 if @font.key?(c)
|
|
234
|
+
end
|
|
235
|
+
w * @scale.x
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
#
|
|
239
|
+
# Render Function
|
|
240
|
+
#
|
|
241
|
+
def render
|
|
242
|
+
if @gl_active == false
|
|
243
|
+
@font.each do |k, f|
|
|
244
|
+
f.build_list
|
|
245
|
+
end
|
|
246
|
+
@gl_active = true
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
GL.PushMatrix
|
|
250
|
+
GL.Disable(GL::LIGHTING)
|
|
251
|
+
GL.Enable(GL::COLOR_MATERIAL)
|
|
252
|
+
GL.Color3f(@color.x, @color.y, @color.z)
|
|
253
|
+
|
|
254
|
+
GL.Translate(
|
|
255
|
+
@position.x,
|
|
256
|
+
@position.y,
|
|
257
|
+
@d == 2 ? 1 / (10000 - @position.z.to_f) : @position.z
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
total_forward = 0
|
|
261
|
+
|
|
262
|
+
GL.Rotate(@d == 2 ? 180 : @roll, 1, 0, 0)
|
|
263
|
+
GL.Rotate(@pitch, 0, 1, 0)
|
|
264
|
+
GL.Rotate(@yaw, 0, 0, 1)
|
|
265
|
+
GL.Scalef(@scale.x, @scale.y, @scale.z)
|
|
266
|
+
|
|
267
|
+
@text.each_char do |c|
|
|
268
|
+
GL.Translate(0.5, 0, 0) if c == ' '
|
|
269
|
+
total_forward += 0.5 if c == ' '
|
|
270
|
+
if c == "\n"
|
|
271
|
+
GL.Translate(-1 * total_forward, 1, 0)
|
|
272
|
+
total_forward = 0
|
|
273
|
+
end
|
|
274
|
+
if @font.key?(c)
|
|
275
|
+
@font[c].render
|
|
276
|
+
GL.Translate(@font[c].width + 0.1, 0, 0)
|
|
277
|
+
total_forward += @font[c].width + 0.1
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
GL.PopMatrix
|
|
281
|
+
GL.Enable(GL::LIGHTING)
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
end
|
data/lib/ui/ui.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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 'ui/text'
|
|
29
|
+
require 'ui/window'
|
|
30
|
+
|
|
31
|
+
module UI
|
|
32
|
+
# Main UI Hud Controller
|
|
33
|
+
class Ui < BlackBook::Base
|
|
34
|
+
attr_accessor :w, :h, :items, :scale, :depth
|
|
35
|
+
|
|
36
|
+
def initialize(w, h, scale = 10)
|
|
37
|
+
super
|
|
38
|
+
@items = {}
|
|
39
|
+
@w = w
|
|
40
|
+
@h = h
|
|
41
|
+
@scale = scale
|
|
42
|
+
@depth = 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#
|
|
46
|
+
# Add a new windows
|
|
47
|
+
# @param options [Hash] Window properties
|
|
48
|
+
#
|
|
49
|
+
# @return [BBWindow] Created Window Object
|
|
50
|
+
def add_window( opts = {} )
|
|
51
|
+
w = Window.new(opts)
|
|
52
|
+
w.z = @depth * 100
|
|
53
|
+
@items[opts[:name]] = w
|
|
54
|
+
@depth += 1
|
|
55
|
+
w
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def render
|
|
59
|
+
GL.PushMatrix
|
|
60
|
+
GL.Disable(GL::LIGHTING)
|
|
61
|
+
GL.MatrixMode(GL::PROJECTION)
|
|
62
|
+
GL.PushMatrix
|
|
63
|
+
GL.LoadIdentity
|
|
64
|
+
GL.Ortho(0.0, @w, @h, 0.0, -1.0, 10.0)
|
|
65
|
+
GL.MatrixMode(GL::MODELVIEW)
|
|
66
|
+
GL.LoadIdentity
|
|
67
|
+
GL.Disable(GL::DEPTH_TEST)
|
|
68
|
+
GL.Disable(GL::CULL_FACE)
|
|
69
|
+
GL.Clear(GL::DEPTH_BUFFER_BIT)
|
|
70
|
+
@items.each do |key, item|
|
|
71
|
+
item.render
|
|
72
|
+
end
|
|
73
|
+
GL.Enable(GL::DEPTH_TEST)
|
|
74
|
+
GL.MatrixMode(GL::PROJECTION)
|
|
75
|
+
GL.PopMatrix
|
|
76
|
+
GL.MatrixMode(GL::MODELVIEW)
|
|
77
|
+
GL.Enable(GL::LIGHTING)
|
|
78
|
+
GL.PopMatrix
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def mouse_move(x, y, right_b, left_b, middle_b)
|
|
82
|
+
@items.clone.each do |name, obj|
|
|
83
|
+
obj.mouse(x, y, right_b, left_b, middle_b) if obj.respond_to?('mouse')
|
|
84
|
+
end
|
|
85
|
+
false
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
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 'ui/text'
|
|
29
|
+
|
|
30
|
+
module UI
|
|
31
|
+
# BB Ui Element Base Class
|
|
32
|
+
class UiElement < BlackBook::Base
|
|
33
|
+
attr_accessor :x, :y, :z, :w, :h, :title
|
|
34
|
+
|
|
35
|
+
def initialize( opts = {} )
|
|
36
|
+
super
|
|
37
|
+
@x = opts[:x] if opts[:x]
|
|
38
|
+
@y = opts[:y] if opts[:y]
|
|
39
|
+
@z = opts[:z] if opts[:z]
|
|
40
|
+
@w = opts[:w] if opts[:w]
|
|
41
|
+
@h = opts[:h] or 35
|
|
42
|
+
@title = opts[:title] if opts[:title]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|