sgl 0.4.0 → 1.0.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.
- data/ChangeLog +254 -234
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/Rakefile +27 -7
- data/examples/cocoa1-basic.rb +14 -14
- data/examples/cocoa10-transparent.rb +26 -26
- data/examples/cocoa11-application.rb +13 -13
- data/examples/cocoa2-draw.rb +23 -23
- data/examples/cocoa3-affine.rb +29 -29
- data/examples/cocoa4-font.rb +24 -24
- data/examples/cocoa5-image.rb +22 -22
- data/examples/cocoa6-sound.rb +24 -24
- data/examples/cocoa7-movie.rb +40 -40
- data/examples/cocoa8-movieoverlay.rb +42 -42
- data/examples/cocoa9-streaming.rb +40 -40
- data/examples/opengl1-basic.rb +14 -14
- data/examples/opengl11-application.rb +13 -13
- data/examples/opengl2-draw.rb +23 -23
- data/examples/opengl3-affine.rb +29 -29
- data/examples/sample1.rb +11 -11
- data/examples/sample10.rb +16 -16
- data/examples/sample11.rb +22 -22
- data/examples/sample11a.rb +33 -33
- data/examples/sample12.rb +30 -30
- data/examples/sample12a.rb +35 -35
- data/examples/sample13.rb +116 -116
- data/examples/sample15.rb +24 -24
- data/examples/sample16.rb +31 -31
- data/examples/sample16a.rb +35 -35
- data/examples/sample6.rb +18 -18
- data/examples/sample7.rb +16 -16
- data/examples/sample9.rb +20 -20
- data/examples/testgl.rb +169 -169
- data/lib/sgl/bass.rb +46 -46
- data/lib/sgl/cocoa-app.rb +43 -43
- data/lib/sgl/cocoa-color.rb +65 -65
- data/lib/sgl/cocoa-draw.rb +72 -72
- data/lib/sgl/cocoa-event.rb +229 -229
- data/lib/sgl/cocoa-media.rb +144 -144
- data/lib/sgl/cocoa-notuse.rb +493 -493
- data/lib/sgl/cocoa-window.rb +203 -203
- data/lib/sgl/cocoa.rb +8 -8
- data/lib/sgl/opengl-app.rb +38 -38
- data/lib/sgl/opengl-color.rb +44 -44
- data/lib/sgl/opengl-draw.rb +260 -260
- data/lib/sgl/opengl-event.rb +325 -325
- data/lib/sgl/opengl-modules.rb +22 -22
- data/lib/sgl/opengl-window.rb +224 -224
- data/lib/sgl/opengl.rb +7 -7
- data/lib/sgl/sgl-button.rb +135 -135
- data/lib/sgl/sgl-client.rb +21 -21
- data/lib/sgl/sgl-color.rb +68 -82
- data/lib/sgl/sgl-connect.rb +9 -9
- data/lib/sgl/sgl-server.rb +58 -58
- data/lib/sgl/sgl-spring.rb +216 -216
- data/lib/sgl/version.rb +2 -2
- data/scripts/lib-txt2html.rb +130 -0
- data/scripts/txt2html +2 -63
- data/spec/sgl_spec.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -0
- data/test/test_cocoa_app.rb +291 -291
- data/test/test_module_ruby16.rb +30 -30
- data/test/test_opengl_app.rb +147 -147
- data/test/test_opengl_basic.rb +22 -22
- data/test/test_opengl_fullscreen.rb +23 -23
- data/test/test_opengl_novice.rb +35 -35
- data/website/challenge1.html +91 -91
- data/website/challenge1.txt +3 -3
- data/website/challenge2.html +143 -144
- data/website/challenge2.txt +13 -14
- data/website/challenge3.html +66 -63
- data/website/challenge3.txt +7 -7
- data/website/cocoa.html +85 -88
- data/website/cocoa.txt +2 -4
- data/website/description.html +138 -138
- data/website/description.txt +1 -1
- data/website/exercise1.html +262 -264
- data/website/exercise1.txt +58 -53
- data/website/exercise2.html +241 -683
- data/website/exercise2.txt +11 -427
- data/website/exercise3.html +206 -0
- data/website/exercise3.txt +155 -0
- data/website/exercise4.html +198 -0
- data/website/exercise4.txt +151 -0
- data/website/exercise5.html +162 -0
- data/website/exercise5.txt +113 -0
- data/website/exhibition.html +84 -84
- data/website/howto.html +146 -134
- data/website/howto.txt +9 -0
- data/website/index.html +178 -178
- data/website/index.txt +20 -19
- data/website/sound.html +141 -141
- metadata +16 -3
data/lib/sgl/opengl-color.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
|
4
|
-
module SGL
|
5
|
-
def background(*a) $__a__.background(*a) end
|
6
|
-
def backgroundHSV(*a) $__a__.backgroundHSV(*a) end
|
7
|
-
def color(*a) $__a__.color(*a) end
|
8
|
-
def colorHSV(*a) $__a__.colorHSV(*a) end
|
9
|
-
|
10
|
-
class Application
|
11
|
-
def initialize_color
|
12
|
-
@bg_color = @cur_color = nil
|
13
|
-
@rgb = ColorTranslatorRGB.new(100, 100, 100, 100)
|
14
|
-
@hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
|
15
|
-
end
|
16
|
-
private :initialize_color
|
17
|
-
|
18
|
-
attr_reader :cur_color # for test
|
19
|
-
|
20
|
-
def background(x, y = nil, z = nil, a = nil)
|
21
|
-
GL.ClearColor(*@rgb.norm(x, y, z, a))
|
22
|
-
clear
|
23
|
-
end
|
24
|
-
|
25
|
-
def backgroundHSV(x, y = nil, z = nil, a = nil)
|
26
|
-
GL.ClearColor(*@hsv.norm(x, y, z, a))
|
27
|
-
clear
|
28
|
-
end
|
29
|
-
|
30
|
-
def clear
|
31
|
-
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)
|
32
|
-
end
|
33
|
-
private :clear
|
34
|
-
|
35
|
-
def color(x, y = nil, z = nil, a = nil)
|
36
|
-
@cur_color = [x, y, z, a]
|
37
|
-
GL.Color(*@rgb.norm(x, y, z, a))
|
38
|
-
end
|
39
|
-
|
40
|
-
def colorHSV(x, y = nil, z = nil, a = nil)
|
41
|
-
GL.Color(*@hsv.norm(x, y, z, a))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
module SGL
|
5
|
+
def background(*a) $__a__.background(*a) end
|
6
|
+
def backgroundHSV(*a) $__a__.backgroundHSV(*a) end
|
7
|
+
def color(*a) $__a__.color(*a) end
|
8
|
+
def colorHSV(*a) $__a__.colorHSV(*a) end
|
9
|
+
|
10
|
+
class Application
|
11
|
+
def initialize_color
|
12
|
+
@bg_color = @cur_color = nil
|
13
|
+
@rgb = ColorTranslatorRGB.new(100, 100, 100, 100)
|
14
|
+
@hsv = ColorTranslatorHSV.new(100, 100, 100, 100)
|
15
|
+
end
|
16
|
+
private :initialize_color
|
17
|
+
|
18
|
+
attr_reader :cur_color # for test
|
19
|
+
|
20
|
+
def background(x, y = nil, z = nil, a = nil)
|
21
|
+
GL.ClearColor(*@rgb.norm(x, y, z, a))
|
22
|
+
clear
|
23
|
+
end
|
24
|
+
|
25
|
+
def backgroundHSV(x, y = nil, z = nil, a = nil)
|
26
|
+
GL.ClearColor(*@hsv.norm(x, y, z, a))
|
27
|
+
clear
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear
|
31
|
+
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)
|
32
|
+
end
|
33
|
+
private :clear
|
34
|
+
|
35
|
+
def color(x, y = nil, z = nil, a = nil)
|
36
|
+
@cur_color = [x, y, z, a]
|
37
|
+
GL.Color(*@rgb.norm(x, y, z, a))
|
38
|
+
end
|
39
|
+
|
40
|
+
def colorHSV(x, y = nil, z = nil, a = nil)
|
41
|
+
GL.Color(*@hsv.norm(x, y, z, a))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/sgl/opengl-draw.rb
CHANGED
@@ -1,260 +1,260 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
|
4
|
-
module SGL
|
5
|
-
LINES = GL::LINES
|
6
|
-
POINTS = GL::POINTS
|
7
|
-
LINE_STRIP = GL::LINE_STRIP
|
8
|
-
LINE_LOOP = GL::LINE_LOOP
|
9
|
-
TRIANGLES = GL::TRIANGLES
|
10
|
-
TRIANGLE_STRIP = GL::TRIANGLE_STRIP
|
11
|
-
TRIANGLE_FAN = GL::TRIANGLE_FAN
|
12
|
-
QUADS = GL::QUADS
|
13
|
-
QUAD_STRIP = GL::QUAD_STRIP
|
14
|
-
POLYGON = GL::POLYGON
|
15
|
-
|
16
|
-
# draw
|
17
|
-
def beginObj(*a) $__a__.beginObj(*a) end
|
18
|
-
def endObj(*a) $__a__.endObj(*a) end
|
19
|
-
def push(*a) $__a__.push(*a) end
|
20
|
-
def pop(*a) $__a__.pop(*a) end
|
21
|
-
def vertex(*a) $__a__.vertex(*a) end
|
22
|
-
def normal(*a) $__a__.normal(*a) end
|
23
|
-
def translate(*a) $__a__.translate(*a) end
|
24
|
-
def rotateX(*a) $__a__.rotateX(*a) end
|
25
|
-
def rotateY(*a) $__a__.rotateY(*a) end
|
26
|
-
def rotateZ(*a) $__a__.rotateZ(*a) end
|
27
|
-
def scale(*a) $__a__.scale(*a) end
|
28
|
-
def point(*a) $__a__.point(*a) end
|
29
|
-
def lineWidth(*a) $__a__.lineWidth(*a) end
|
30
|
-
def line(*a) $__a__.line(*a) end
|
31
|
-
def rect(*a) $__a__.rect(*a) end
|
32
|
-
def triangle(*a) $__a__.triangle(*a) end
|
33
|
-
def circle(*a) $__a__.circle(*a) end
|
34
|
-
def box(*a) $__a__.box(*a) end
|
35
|
-
def cube(*a) $__a__.cube(*a) end
|
36
|
-
|
37
|
-
class Application
|
38
|
-
LINES = GL::LINES
|
39
|
-
POINTS = GL::POINTS
|
40
|
-
LINE_STRIP = GL::LINE_STRIP
|
41
|
-
LINE_LOOP = GL::LINE_LOOP
|
42
|
-
TRIANGLES = GL::TRIANGLES
|
43
|
-
TRIANGLE_STRIP = GL::TRIANGLE_STRIP
|
44
|
-
TRIANGLE_FAN = GL::TRIANGLE_FAN
|
45
|
-
QUADS = GL::QUADS
|
46
|
-
QUAD_STRIP = GL::QUAD_STRIP
|
47
|
-
POLYGON = GL::POLYGON
|
48
|
-
|
49
|
-
# draw primitive
|
50
|
-
def beginObj(mode = POLYGON)
|
51
|
-
GL.Begin(mode)
|
52
|
-
end
|
53
|
-
|
54
|
-
def endObj
|
55
|
-
GL.End
|
56
|
-
end
|
57
|
-
|
58
|
-
def push
|
59
|
-
GL.PushMatrix
|
60
|
-
end
|
61
|
-
|
62
|
-
def pop
|
63
|
-
GL.PopMatrix
|
64
|
-
end
|
65
|
-
|
66
|
-
def vertex(a, b = nil, c = nil, d = nil)
|
67
|
-
GL.Vertex(a, b, c, d) if d
|
68
|
-
GL.Vertex(a, b, c) if c
|
69
|
-
GL.Vertex(a, b)
|
70
|
-
end
|
71
|
-
|
72
|
-
def normal(a, b = nil, c = nil)
|
73
|
-
GL.Normal(a, b, c)
|
74
|
-
end
|
75
|
-
|
76
|
-
# matrix manipulation
|
77
|
-
def translate(a, b, c = 0)
|
78
|
-
GL.Translate(a, b, c)
|
79
|
-
end
|
80
|
-
|
81
|
-
def rotateX(a)
|
82
|
-
GL.Rotate(a, 1, 0, 0)
|
83
|
-
end
|
84
|
-
|
85
|
-
def rotateY(a)
|
86
|
-
GL.Rotate(a, 0, 1, 0)
|
87
|
-
end
|
88
|
-
|
89
|
-
def rotateZ(a)
|
90
|
-
GL.Rotate(a, 0, 0, 1)
|
91
|
-
end
|
92
|
-
|
93
|
-
def scale(a)
|
94
|
-
GL.Scale(a, a, a)
|
95
|
-
end
|
96
|
-
|
97
|
-
# simple draw
|
98
|
-
def point(a, b, c = nil)
|
99
|
-
GL.Begin(GL::POINTS)
|
100
|
-
if c
|
101
|
-
GL.Vertex(a, b, c)
|
102
|
-
else
|
103
|
-
GL.Vertex(a, b)
|
104
|
-
end
|
105
|
-
GL.End
|
106
|
-
end
|
107
|
-
|
108
|
-
def lineWidth(w)
|
109
|
-
GL.LineWidth(w)
|
110
|
-
end
|
111
|
-
|
112
|
-
def line(a, b, c, d, e = nil, f = nil)
|
113
|
-
GL.Begin(GL::LINES)
|
114
|
-
if e && f
|
115
|
-
GL.Vertex(a, b, c) # 3D
|
116
|
-
GL.Vertex(d, e, f)
|
117
|
-
else
|
118
|
-
GL.Vertex(a, b) # 2D
|
119
|
-
GL.Vertex(c, d)
|
120
|
-
end
|
121
|
-
GL.End
|
122
|
-
end
|
123
|
-
|
124
|
-
def rect(a, b, c, d)
|
125
|
-
GL.Rect(a, b, c, d)
|
126
|
-
end
|
127
|
-
|
128
|
-
def triangle(a, b, c, d, e, f)
|
129
|
-
GL.Begin(GL::TRIANGLES)
|
130
|
-
GL.Vertex(a, b)
|
131
|
-
GL.Vertex(c, d)
|
132
|
-
GL.Vertex(e, f)
|
133
|
-
GL.End
|
134
|
-
end
|
135
|
-
|
136
|
-
def circleUnit(style = LINE_LOOP, div = nil)
|
137
|
-
div = 32 if div.nil?
|
138
|
-
e = 2 * Math::PI / div
|
139
|
-
GL.Begin(style)
|
140
|
-
div.times {|i|
|
141
|
-
rad = i * e
|
142
|
-
x = Math.cos(rad)
|
143
|
-
y = Math.sin(rad)
|
144
|
-
GL.Vertex(x, y)
|
145
|
-
}
|
146
|
-
GL.End
|
147
|
-
end
|
148
|
-
private :circleUnit
|
149
|
-
|
150
|
-
def circle(x, y, r, style = LINE_LOOP, div = nil)
|
151
|
-
GL.PushMatrix
|
152
|
-
GL.Translate(x, y, 0)
|
153
|
-
GL.Scale(r, r, r)
|
154
|
-
circleUnit(style, div)
|
155
|
-
GL.PopMatrix
|
156
|
-
end
|
157
|
-
|
158
|
-
def box(x1, y1, z1, x2, y2, z2)
|
159
|
-
box = [
|
160
|
-
[x1, y1, z1], # 0 back left bottom
|
161
|
-
[x2, y1, z1], # 1 back right bottom
|
162
|
-
[x2, y2, z1], # 2 back right top
|
163
|
-
[x1, y2, z1], # 3 back left top
|
164
|
-
[x1, y1, z2], # 4 front left bottom
|
165
|
-
[x2, y1, z2], # 5 front right bottom
|
166
|
-
[x2, y2, z2], # 6 front right top
|
167
|
-
[x1, y2, z2] # 7 front left top
|
168
|
-
]
|
169
|
-
GL.Begin(GL::QUADS)
|
170
|
-
GL.Vertex(box[1]) # back
|
171
|
-
GL.Vertex(box[0])
|
172
|
-
GL.Vertex(box[3])
|
173
|
-
GL.Vertex(box[2])
|
174
|
-
GL.Vertex(box[0]) # left
|
175
|
-
GL.Vertex(box[4])
|
176
|
-
GL.Vertex(box[7])
|
177
|
-
GL.Vertex(box[3])
|
178
|
-
GL.Vertex(box[4]) # front
|
179
|
-
GL.Vertex(box[5])
|
180
|
-
GL.Vertex(box[6])
|
181
|
-
GL.Vertex(box[7])
|
182
|
-
GL.Vertex(box[5]) # right
|
183
|
-
GL.Vertex(box[1])
|
184
|
-
GL.Vertex(box[2])
|
185
|
-
GL.Vertex(box[6])
|
186
|
-
GL.Vertex(box[7]) # top
|
187
|
-
GL.Vertex(box[6])
|
188
|
-
GL.Vertex(box[2])
|
189
|
-
GL.Vertex(box[3])
|
190
|
-
GL.Vertex(box[0]) # bottom
|
191
|
-
GL.Vertex(box[1])
|
192
|
-
GL.Vertex(box[5])
|
193
|
-
GL.Vertex(box[4])
|
194
|
-
GL.End
|
195
|
-
end
|
196
|
-
|
197
|
-
def cube(x, y, z, s)
|
198
|
-
s = s / 2
|
199
|
-
box(x - s, y - s, z - s, x + s, y + s, z + s)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
# This class is not used for now.
|
204
|
-
class FasterCircle
|
205
|
-
# circle
|
206
|
-
def self.circleUnit(style=LINE_LOOP, div=nil)
|
207
|
-
div = 32 if div == nil
|
208
|
-
e = 2 * Math::PI / div
|
209
|
-
beginObj(style)
|
210
|
-
div.times {|i|
|
211
|
-
rad = i * e
|
212
|
-
x = Math.cos(rad)
|
213
|
-
y = Math.sin(rad)
|
214
|
-
vertex(x, y)
|
215
|
-
}
|
216
|
-
endObj()
|
217
|
-
end
|
218
|
-
|
219
|
-
def self.make_list
|
220
|
-
GL.NewList(1, GL::COMPILE)
|
221
|
-
self.circleUnit(LINE_LOOP, 32)
|
222
|
-
GL.EndList()
|
223
|
-
GL.NewList(2, GL::COMPILE)
|
224
|
-
self.circleUnit(POLYGON, 32)
|
225
|
-
GL.EndList()
|
226
|
-
GL.NewList(3, GL::COMPILE)
|
227
|
-
self.circleUnit(LINE_LOOP, 6)
|
228
|
-
GL.EndList()
|
229
|
-
GL.NewList(4, GL::COMPILE)
|
230
|
-
self.circleUnit(POLYGON, 6)
|
231
|
-
GL.EndList()
|
232
|
-
end
|
233
|
-
|
234
|
-
def self.circleUnitList(style=LINE_LOOP, div=nil)
|
235
|
-
if div == 32
|
236
|
-
if style == LINE_LOOP
|
237
|
-
GL.CallList(1)
|
238
|
-
elsif style == POLYGON
|
239
|
-
GL.CallList(2)
|
240
|
-
end
|
241
|
-
elsif div == 6
|
242
|
-
if style == LINE_LOOP
|
243
|
-
GL.CallList(3)
|
244
|
-
elsif style == POLYGON
|
245
|
-
GL.CallList(4)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
def self.circle(x, y, r, style=LINE_LOOP, div=nil)
|
251
|
-
push()
|
252
|
-
translate(x, y)
|
253
|
-
scale(r)
|
254
|
-
#circleUnit(style, div)
|
255
|
-
self.circleUnitList(style, div)
|
256
|
-
pop()
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
end
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
module SGL
|
5
|
+
LINES = GL::LINES
|
6
|
+
POINTS = GL::POINTS
|
7
|
+
LINE_STRIP = GL::LINE_STRIP
|
8
|
+
LINE_LOOP = GL::LINE_LOOP
|
9
|
+
TRIANGLES = GL::TRIANGLES
|
10
|
+
TRIANGLE_STRIP = GL::TRIANGLE_STRIP
|
11
|
+
TRIANGLE_FAN = GL::TRIANGLE_FAN
|
12
|
+
QUADS = GL::QUADS
|
13
|
+
QUAD_STRIP = GL::QUAD_STRIP
|
14
|
+
POLYGON = GL::POLYGON
|
15
|
+
|
16
|
+
# draw
|
17
|
+
def beginObj(*a) $__a__.beginObj(*a) end
|
18
|
+
def endObj(*a) $__a__.endObj(*a) end
|
19
|
+
def push(*a) $__a__.push(*a) end
|
20
|
+
def pop(*a) $__a__.pop(*a) end
|
21
|
+
def vertex(*a) $__a__.vertex(*a) end
|
22
|
+
def normal(*a) $__a__.normal(*a) end
|
23
|
+
def translate(*a) $__a__.translate(*a) end
|
24
|
+
def rotateX(*a) $__a__.rotateX(*a) end
|
25
|
+
def rotateY(*a) $__a__.rotateY(*a) end
|
26
|
+
def rotateZ(*a) $__a__.rotateZ(*a) end
|
27
|
+
def scale(*a) $__a__.scale(*a) end
|
28
|
+
def point(*a) $__a__.point(*a) end
|
29
|
+
def lineWidth(*a) $__a__.lineWidth(*a) end
|
30
|
+
def line(*a) $__a__.line(*a) end
|
31
|
+
def rect(*a) $__a__.rect(*a) end
|
32
|
+
def triangle(*a) $__a__.triangle(*a) end
|
33
|
+
def circle(*a) $__a__.circle(*a) end
|
34
|
+
def box(*a) $__a__.box(*a) end
|
35
|
+
def cube(*a) $__a__.cube(*a) end
|
36
|
+
|
37
|
+
class Application
|
38
|
+
LINES = GL::LINES
|
39
|
+
POINTS = GL::POINTS
|
40
|
+
LINE_STRIP = GL::LINE_STRIP
|
41
|
+
LINE_LOOP = GL::LINE_LOOP
|
42
|
+
TRIANGLES = GL::TRIANGLES
|
43
|
+
TRIANGLE_STRIP = GL::TRIANGLE_STRIP
|
44
|
+
TRIANGLE_FAN = GL::TRIANGLE_FAN
|
45
|
+
QUADS = GL::QUADS
|
46
|
+
QUAD_STRIP = GL::QUAD_STRIP
|
47
|
+
POLYGON = GL::POLYGON
|
48
|
+
|
49
|
+
# draw primitive
|
50
|
+
def beginObj(mode = POLYGON)
|
51
|
+
GL.Begin(mode)
|
52
|
+
end
|
53
|
+
|
54
|
+
def endObj
|
55
|
+
GL.End
|
56
|
+
end
|
57
|
+
|
58
|
+
def push
|
59
|
+
GL.PushMatrix
|
60
|
+
end
|
61
|
+
|
62
|
+
def pop
|
63
|
+
GL.PopMatrix
|
64
|
+
end
|
65
|
+
|
66
|
+
def vertex(a, b = nil, c = nil, d = nil)
|
67
|
+
GL.Vertex(a, b, c, d) if d
|
68
|
+
GL.Vertex(a, b, c) if c
|
69
|
+
GL.Vertex(a, b)
|
70
|
+
end
|
71
|
+
|
72
|
+
def normal(a, b = nil, c = nil)
|
73
|
+
GL.Normal(a, b, c)
|
74
|
+
end
|
75
|
+
|
76
|
+
# matrix manipulation
|
77
|
+
def translate(a, b, c = 0)
|
78
|
+
GL.Translate(a, b, c)
|
79
|
+
end
|
80
|
+
|
81
|
+
def rotateX(a)
|
82
|
+
GL.Rotate(a, 1, 0, 0)
|
83
|
+
end
|
84
|
+
|
85
|
+
def rotateY(a)
|
86
|
+
GL.Rotate(a, 0, 1, 0)
|
87
|
+
end
|
88
|
+
|
89
|
+
def rotateZ(a)
|
90
|
+
GL.Rotate(a, 0, 0, 1)
|
91
|
+
end
|
92
|
+
|
93
|
+
def scale(a)
|
94
|
+
GL.Scale(a, a, a)
|
95
|
+
end
|
96
|
+
|
97
|
+
# simple draw
|
98
|
+
def point(a, b, c = nil)
|
99
|
+
GL.Begin(GL::POINTS)
|
100
|
+
if c
|
101
|
+
GL.Vertex(a, b, c)
|
102
|
+
else
|
103
|
+
GL.Vertex(a, b)
|
104
|
+
end
|
105
|
+
GL.End
|
106
|
+
end
|
107
|
+
|
108
|
+
def lineWidth(w)
|
109
|
+
GL.LineWidth(w)
|
110
|
+
end
|
111
|
+
|
112
|
+
def line(a, b, c, d, e = nil, f = nil)
|
113
|
+
GL.Begin(GL::LINES)
|
114
|
+
if e && f
|
115
|
+
GL.Vertex(a, b, c) # 3D
|
116
|
+
GL.Vertex(d, e, f)
|
117
|
+
else
|
118
|
+
GL.Vertex(a, b) # 2D
|
119
|
+
GL.Vertex(c, d)
|
120
|
+
end
|
121
|
+
GL.End
|
122
|
+
end
|
123
|
+
|
124
|
+
def rect(a, b, c, d)
|
125
|
+
GL.Rect(a, b, c, d)
|
126
|
+
end
|
127
|
+
|
128
|
+
def triangle(a, b, c, d, e, f)
|
129
|
+
GL.Begin(GL::TRIANGLES)
|
130
|
+
GL.Vertex(a, b)
|
131
|
+
GL.Vertex(c, d)
|
132
|
+
GL.Vertex(e, f)
|
133
|
+
GL.End
|
134
|
+
end
|
135
|
+
|
136
|
+
def circleUnit(style = LINE_LOOP, div = nil)
|
137
|
+
div = 32 if div.nil?
|
138
|
+
e = 2 * Math::PI / div
|
139
|
+
GL.Begin(style)
|
140
|
+
div.times {|i|
|
141
|
+
rad = i * e
|
142
|
+
x = Math.cos(rad)
|
143
|
+
y = Math.sin(rad)
|
144
|
+
GL.Vertex(x, y)
|
145
|
+
}
|
146
|
+
GL.End
|
147
|
+
end
|
148
|
+
private :circleUnit
|
149
|
+
|
150
|
+
def circle(x, y, r, style = LINE_LOOP, div = nil)
|
151
|
+
GL.PushMatrix
|
152
|
+
GL.Translate(x, y, 0)
|
153
|
+
GL.Scale(r, r, r)
|
154
|
+
circleUnit(style, div)
|
155
|
+
GL.PopMatrix
|
156
|
+
end
|
157
|
+
|
158
|
+
def box(x1, y1, z1, x2, y2, z2)
|
159
|
+
box = [
|
160
|
+
[x1, y1, z1], # 0 back left bottom
|
161
|
+
[x2, y1, z1], # 1 back right bottom
|
162
|
+
[x2, y2, z1], # 2 back right top
|
163
|
+
[x1, y2, z1], # 3 back left top
|
164
|
+
[x1, y1, z2], # 4 front left bottom
|
165
|
+
[x2, y1, z2], # 5 front right bottom
|
166
|
+
[x2, y2, z2], # 6 front right top
|
167
|
+
[x1, y2, z2] # 7 front left top
|
168
|
+
]
|
169
|
+
GL.Begin(GL::QUADS)
|
170
|
+
GL.Vertex(box[1]) # back
|
171
|
+
GL.Vertex(box[0])
|
172
|
+
GL.Vertex(box[3])
|
173
|
+
GL.Vertex(box[2])
|
174
|
+
GL.Vertex(box[0]) # left
|
175
|
+
GL.Vertex(box[4])
|
176
|
+
GL.Vertex(box[7])
|
177
|
+
GL.Vertex(box[3])
|
178
|
+
GL.Vertex(box[4]) # front
|
179
|
+
GL.Vertex(box[5])
|
180
|
+
GL.Vertex(box[6])
|
181
|
+
GL.Vertex(box[7])
|
182
|
+
GL.Vertex(box[5]) # right
|
183
|
+
GL.Vertex(box[1])
|
184
|
+
GL.Vertex(box[2])
|
185
|
+
GL.Vertex(box[6])
|
186
|
+
GL.Vertex(box[7]) # top
|
187
|
+
GL.Vertex(box[6])
|
188
|
+
GL.Vertex(box[2])
|
189
|
+
GL.Vertex(box[3])
|
190
|
+
GL.Vertex(box[0]) # bottom
|
191
|
+
GL.Vertex(box[1])
|
192
|
+
GL.Vertex(box[5])
|
193
|
+
GL.Vertex(box[4])
|
194
|
+
GL.End
|
195
|
+
end
|
196
|
+
|
197
|
+
def cube(x, y, z, s)
|
198
|
+
s = s / 2
|
199
|
+
box(x - s, y - s, z - s, x + s, y + s, z + s)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# This class is not used for now.
|
204
|
+
class FasterCircle
|
205
|
+
# circle
|
206
|
+
def self.circleUnit(style=LINE_LOOP, div=nil)
|
207
|
+
div = 32 if div == nil
|
208
|
+
e = 2 * Math::PI / div
|
209
|
+
beginObj(style)
|
210
|
+
div.times {|i|
|
211
|
+
rad = i * e
|
212
|
+
x = Math.cos(rad)
|
213
|
+
y = Math.sin(rad)
|
214
|
+
vertex(x, y)
|
215
|
+
}
|
216
|
+
endObj()
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.make_list
|
220
|
+
GL.NewList(1, GL::COMPILE)
|
221
|
+
self.circleUnit(LINE_LOOP, 32)
|
222
|
+
GL.EndList()
|
223
|
+
GL.NewList(2, GL::COMPILE)
|
224
|
+
self.circleUnit(POLYGON, 32)
|
225
|
+
GL.EndList()
|
226
|
+
GL.NewList(3, GL::COMPILE)
|
227
|
+
self.circleUnit(LINE_LOOP, 6)
|
228
|
+
GL.EndList()
|
229
|
+
GL.NewList(4, GL::COMPILE)
|
230
|
+
self.circleUnit(POLYGON, 6)
|
231
|
+
GL.EndList()
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.circleUnitList(style=LINE_LOOP, div=nil)
|
235
|
+
if div == 32
|
236
|
+
if style == LINE_LOOP
|
237
|
+
GL.CallList(1)
|
238
|
+
elsif style == POLYGON
|
239
|
+
GL.CallList(2)
|
240
|
+
end
|
241
|
+
elsif div == 6
|
242
|
+
if style == LINE_LOOP
|
243
|
+
GL.CallList(3)
|
244
|
+
elsif style == POLYGON
|
245
|
+
GL.CallList(4)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def self.circle(x, y, r, style=LINE_LOOP, div=nil)
|
251
|
+
push()
|
252
|
+
translate(x, y)
|
253
|
+
scale(r)
|
254
|
+
#circleUnit(style, div)
|
255
|
+
self.circleUnitList(style, div)
|
256
|
+
pop()
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|