sgl 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +234 -0
- data/Manifest.txt +94 -0
- data/Rakefile +16 -5
- data/examples/cocoa1-basic.rb +14 -0
- data/examples/cocoa10-transparent.rb +26 -0
- data/examples/cocoa11-application.rb +13 -0
- data/examples/cocoa2-draw.rb +23 -0
- data/examples/cocoa3-affine.rb +29 -0
- data/examples/cocoa4-font.rb +24 -0
- data/examples/cocoa5-image.rb +22 -0
- data/examples/cocoa6-sound.rb +24 -0
- data/examples/cocoa7-movie.rb +40 -0
- data/examples/cocoa8-movieoverlay.rb +42 -0
- data/examples/cocoa9-streaming.rb +40 -0
- data/examples/opengl1-basic.rb +14 -0
- data/examples/opengl11-application.rb +13 -0
- data/examples/opengl2-draw.rb +23 -0
- data/examples/opengl3-affine.rb +29 -0
- data/examples/sample1.rb +11 -0
- data/examples/sample10.rb +16 -0
- data/examples/sample11.rb +22 -0
- data/examples/sample11a.rb +33 -0
- data/examples/sample12.rb +30 -0
- data/examples/sample12a.rb +35 -0
- data/examples/sample13.rb +116 -0
- data/examples/sample15.rb +24 -0
- data/examples/sample16.rb +31 -0
- data/examples/sample16a.rb +35 -0
- data/examples/sample6.rb +18 -0
- data/examples/sample7.rb +16 -0
- data/examples/sample9.rb +20 -0
- data/examples/sgl-sound1.rb +6 -0
- data/examples/sgl-sound2.rb +19 -0
- data/examples/sine.ogg +0 -0
- data/examples/testgl.rb +169 -0
- data/lib/sgl/bass-api.rb +202 -0
- data/lib/sgl/bass-sample.rb +106 -0
- data/lib/sgl/bass.rb +46 -0
- data/lib/sgl/cocoa-app.rb +43 -0
- data/lib/sgl/cocoa-color.rb +65 -0
- data/lib/sgl/cocoa-draw.rb +72 -0
- data/lib/sgl/cocoa-event.rb +229 -0
- data/lib/sgl/cocoa-media.rb +144 -0
- data/lib/sgl/cocoa-notuse.rb +493 -0
- data/lib/sgl/cocoa-window.rb +203 -0
- data/lib/sgl/cocoa.rb +8 -0
- data/lib/sgl/notuse-objs.rb +358 -0
- data/lib/sgl/opengl-app.rb +38 -0
- data/lib/sgl/opengl-color.rb +44 -0
- data/lib/sgl/opengl-draw.rb +260 -0
- data/lib/sgl/opengl-event.rb +325 -0
- data/lib/sgl/opengl-modules.rb +22 -0
- data/lib/sgl/opengl-window.rb +224 -0
- data/lib/sgl/opengl.rb +7 -0
- data/lib/sgl/sgl-basic.rb +61 -0
- data/lib/sgl/sgl-button.rb +135 -0
- data/lib/sgl/sgl-client.rb +21 -0
- data/lib/sgl/sgl-color.rb +82 -0
- data/lib/sgl/sgl-connect.rb +9 -0
- data/lib/sgl/sgl-objlib.rb +0 -0
- data/lib/sgl/sgl-objs.rb +0 -0
- data/lib/sgl/sgl-server.rb +58 -0
- data/lib/sgl/sgl-sound.rb +24 -0
- data/lib/sgl/sgl-spring.rb +216 -0
- data/lib/sgl/sgl-timer.rb +72 -0
- data/lib/sgl/sgl.rb +5 -0
- data/lib/sgl/version.rb +2 -2
- data/scripts/makemanifest.rb +20 -0
- data/test/test_bass.rb +27 -0
- data/test/test_cocoa_app.rb +5 -5
- data/test/test_helper.rb +9 -1
- data/test/test_module_ruby16.rb +22 -21
- data/test/test_opengl_app.rb +4 -5
- data/test/test_opengl_basic.rb +3 -4
- data/test/test_opengl_fullscreen.rb +4 -6
- data/test/test_opengl_novice.rb +3 -6
- data/test/test_sgl.rb +4 -27
- data/test/test_sound.rb +15 -0
- data/website/challenge1.html +91 -0
- data/website/challenge1.txt +30 -0
- data/website/challenge2.html +144 -0
- data/website/challenge2.txt +73 -0
- data/website/challenge3.html +63 -0
- data/website/challenge3.txt +15 -0
- data/website/cocoa.html +88 -0
- data/website/cocoa.txt +35 -0
- data/website/description.html +138 -0
- data/website/description.txt +90 -0
- data/website/exercise1.html +264 -0
- data/website/exercise1.txt +192 -0
- data/website/exercise2.html +683 -0
- data/website/exercise2.txt +597 -0
- data/website/exhibition.html +84 -0
- data/website/exhibition.txt +24 -0
- data/website/howto.html +134 -0
- data/website/howto.txt +56 -0
- data/website/index.html +17 -9
- data/website/index.txt +13 -4
- data/website/sound.html +141 -0
- data/website/sound.txt +87 -0
- data/website/stylesheets/grade.png +0 -0
- data/website/stylesheets/screen.css +21 -20
- metadata +109 -3
@@ -0,0 +1,358 @@
|
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
class ObjLib
|
5
|
+
START_CATEGORY = 1
|
6
|
+
START_NUMBER = 1
|
7
|
+
|
8
|
+
def initialize(c, n)
|
9
|
+
@cat = (c != nil) ? c.to_i : START_CATEGORY
|
10
|
+
@num = (n != nil) ? n.to_i : START_NUMBER
|
11
|
+
|
12
|
+
lines = [HexagonLines.new, PerpendicularLines.new, TangentLines.new, HomingLines.new, RandomFallLines.new,
|
13
|
+
NeonLines.new, RandomCageLines.new, TangeKenzoLines.new, BanShigeruLines.new, CircleLines.new]
|
14
|
+
|
15
|
+
colors = [LayeredCubes.new, ColorCircles.new, ColorfulGrids.new, RotateGrids.new, ColorSquares.new,
|
16
|
+
VerticalFields.new, MovingRects.new, TilingSquares.new, PackedCircles.new, GradationFields.new]
|
17
|
+
|
18
|
+
plants = [Ivies.new, TreeFields.new, Ivies.new, Ivies2.new, Ivies3.new]
|
19
|
+
|
20
|
+
gradations = [MeGrads.new, MeGrads.new]
|
21
|
+
|
22
|
+
#loops = [LoopGrids.new]
|
23
|
+
|
24
|
+
@lib = [[], lines, colors, plants, gradations]
|
25
|
+
|
26
|
+
@lx, @ly = nil, nil #��O��potision���Ƃ��Ă���
|
27
|
+
h, s, v = @lib[@cat][@num].background_color
|
28
|
+
@h = NumSpring.new(h, h, 10, 0.7)
|
29
|
+
@s = NumSpring.new(s, s, 10, 0.7)
|
30
|
+
@v = NumSpring.new(v, v, 10, 0.7)
|
31
|
+
Circle.make_list
|
32
|
+
|
33
|
+
change_stage(@cat, @num)
|
34
|
+
end
|
35
|
+
|
36
|
+
def onKeyDown(key)
|
37
|
+
if SDL::Key::K0 <= key && key <= SDL::Key::K9
|
38
|
+
key -= SDL::Key::K0
|
39
|
+
return if @lib[@cat][key] == nil
|
40
|
+
change_stage(@cat, key)
|
41
|
+
elsif SDL::Key::F1 <= key && key <= SDL::Key::F10
|
42
|
+
key -= (SDL::Key::F1-1)
|
43
|
+
return if @lib[key] == nil
|
44
|
+
return if @lib[key][1] == nil
|
45
|
+
change_stage(key, 1)
|
46
|
+
elsif key == SDL::Key::SPACE
|
47
|
+
fadeout
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def onMouseDown(x, y)
|
52
|
+
@lib[@cat][@num].onMouseDown(x, y)
|
53
|
+
end
|
54
|
+
|
55
|
+
def onMouseUp(x, y)
|
56
|
+
@lib[@cat][@num].onMouseUp(x, y)
|
57
|
+
end
|
58
|
+
|
59
|
+
def change_stage(cat, num)
|
60
|
+
ocat, onum = @cat, @num
|
61
|
+
olib = @lib[@cat][@num]
|
62
|
+
olib.end_process()
|
63
|
+
@cat, @num = cat, num
|
64
|
+
lib = @lib[@cat][@num]
|
65
|
+
lib.start_process()
|
66
|
+
change_background_color
|
67
|
+
#category���ς��āA����lines����Ȃ���ΑS��fadeout
|
68
|
+
fadeout if ocat != @cat || @cat != 1
|
69
|
+
#fadeout if ocat != @cat || @cat != 1
|
70
|
+
#change_setup if @cat != 1
|
71
|
+
end
|
72
|
+
|
73
|
+
def change_background_color
|
74
|
+
h, s, v = @lib[@cat][@num].background_color
|
75
|
+
@h.moving = @s.moving = @v.moving = true
|
76
|
+
@h.target,@s.target,@v.target = h,s,v
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_background_color
|
80
|
+
@h.move; @s.move; @v.move
|
81
|
+
backgroundHSV @h.x, @s.x, @v.x
|
82
|
+
end
|
83
|
+
|
84
|
+
def fadeout
|
85
|
+
@lib.each {|cat|
|
86
|
+
cat.each {|movement|
|
87
|
+
movement.fadeout
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def display
|
93
|
+
mouse(mouseX, mouseY)
|
94
|
+
render()
|
95
|
+
end
|
96
|
+
|
97
|
+
def mouse(x, y)
|
98
|
+
@lib[@cat][@num].add(x, y, @lx, @ly) unless @lx == nil || @ly == nil
|
99
|
+
@lx,@ly = x,y #remember last potision
|
100
|
+
end
|
101
|
+
|
102
|
+
def render
|
103
|
+
set_background_color
|
104
|
+
@lib.each_index {|c|
|
105
|
+
cat = @lib[c]
|
106
|
+
cat.each_index {|n|
|
107
|
+
lib = @lib[c][n]
|
108
|
+
next if lib == nil
|
109
|
+
next if ! lib.running
|
110
|
+
lib.move
|
111
|
+
lib.render
|
112
|
+
}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# ����Obj��100�ۗL����N���X
|
118
|
+
class Objs
|
119
|
+
MAX = 100
|
120
|
+
def initialize(orgclass, max = MAX)
|
121
|
+
@orgclass, @max = orgclass, max
|
122
|
+
@a = []
|
123
|
+
@max.times {|i|
|
124
|
+
@a[i] = @orgclass.dup
|
125
|
+
@a[i].index = i
|
126
|
+
@a[i].enable = false
|
127
|
+
}
|
128
|
+
@cur = 0
|
129
|
+
@running = false
|
130
|
+
@background_color = [66,100,20] # R0,G0,B20�A����
|
131
|
+
@top = height/2
|
132
|
+
@bottom = -@top
|
133
|
+
@right = width/2
|
134
|
+
@left = -@right
|
135
|
+
end
|
136
|
+
|
137
|
+
attr_reader :background_color
|
138
|
+
attr_reader :a, :running, :max, :cur
|
139
|
+
|
140
|
+
def start_process
|
141
|
+
useDepth(false)
|
142
|
+
useCulling(false)
|
143
|
+
useFov(45)
|
144
|
+
@running = true
|
145
|
+
end
|
146
|
+
|
147
|
+
def end_process
|
148
|
+
fadeout
|
149
|
+
@running = false
|
150
|
+
end
|
151
|
+
|
152
|
+
def onMouseDown(x, y)
|
153
|
+
end
|
154
|
+
|
155
|
+
def onMouseUp(x, y)
|
156
|
+
end
|
157
|
+
|
158
|
+
def add(x, y, lx, ly)
|
159
|
+
len = V2.length(x - lx, y - ly)
|
160
|
+
if @a[@cur].enable == true
|
161
|
+
@a[@cur].end_process
|
162
|
+
end
|
163
|
+
@a[@cur].init(self, x, y, lx, ly)
|
164
|
+
@a[@cur].start_process()
|
165
|
+
@a[@cur].enable = false if len < 3
|
166
|
+
@cur += 1
|
167
|
+
@cur = 0 if @max <= @cur
|
168
|
+
@running = true
|
169
|
+
#p [@cur, x, y, lx, ly]
|
170
|
+
end
|
171
|
+
|
172
|
+
def fadeout
|
173
|
+
@a.each {|m|
|
174
|
+
m.fadeout
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
def move
|
179
|
+
index = @cur
|
180
|
+
@a.each_index {
|
181
|
+
m = @a[index]
|
182
|
+
m.move if m.enable
|
183
|
+
index += 1
|
184
|
+
index = 0 if @max <= index
|
185
|
+
}
|
186
|
+
end
|
187
|
+
|
188
|
+
def render
|
189
|
+
r = false
|
190
|
+
index = @cur
|
191
|
+
@a.each_index {
|
192
|
+
m = @a[index]
|
193
|
+
if m.enable
|
194
|
+
m.render
|
195
|
+
r = true
|
196
|
+
end
|
197
|
+
index += 1
|
198
|
+
index = 0 if @max <= index
|
199
|
+
}
|
200
|
+
@running = r
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
class Obj
|
205
|
+
START_FADEOUT = 20
|
206
|
+
|
207
|
+
def initialize
|
208
|
+
@dx1,@dy1,@dx2,@dy2 = 0,0,0,0
|
209
|
+
@ttl = 0
|
210
|
+
@start_fadeout = START_FADEOUT
|
211
|
+
@enable = true
|
212
|
+
@index = 0
|
213
|
+
@top = height/2
|
214
|
+
@bottom = -@top
|
215
|
+
@right = width/2
|
216
|
+
@left = -@right
|
217
|
+
end
|
218
|
+
|
219
|
+
def init(lib, x1, y1, x2, y2)
|
220
|
+
@lib,@x1,@y1,@x2,@y2 = lib, x1, y1, x2, y2
|
221
|
+
@dx1,@dy1,@dx2,@dy2 = x1, y1, x2, y2 # �����l
|
222
|
+
@cx = (x1+x2)/2
|
223
|
+
@cy = (y1+y2)/2
|
224
|
+
@dcx,@dcy = @cx,@cy
|
225
|
+
@enable = true
|
226
|
+
@ttl = @lib.max
|
227
|
+
@sound = ObjSound.new('wav/start.wav')
|
228
|
+
end
|
229
|
+
|
230
|
+
def start_process
|
231
|
+
end
|
232
|
+
|
233
|
+
def end_process
|
234
|
+
end
|
235
|
+
|
236
|
+
attr_reader :x1, :y1, :dx1, :dy1
|
237
|
+
attr_accessor :enable, :index
|
238
|
+
|
239
|
+
def inspect() sprintf("[%d,%d-%d,%d]",@x1,@y1,@x2,@y2) end
|
240
|
+
|
241
|
+
def length() V2.length(@x1-@x2, @y1-@y2) end
|
242
|
+
|
243
|
+
def move() end
|
244
|
+
|
245
|
+
def fadeout
|
246
|
+
@ttl = @start_fadeout if @start_fadeout < @ttl
|
247
|
+
end
|
248
|
+
|
249
|
+
def render
|
250
|
+
if @ttl <= 0
|
251
|
+
@enable = false
|
252
|
+
return
|
253
|
+
end
|
254
|
+
@ttl -= 1
|
255
|
+
alpha = 100
|
256
|
+
alpha = @ttl * 100 / @start_fadeout if @ttl < @start_fadeout
|
257
|
+
renderObj(alpha)
|
258
|
+
end
|
259
|
+
|
260
|
+
def renderObj(alpha)
|
261
|
+
end
|
262
|
+
|
263
|
+
def playXY(alpha)
|
264
|
+
end
|
265
|
+
|
266
|
+
def colorline(x1, y1, x2, y2, h, s, v, sa, ea)
|
267
|
+
beginObj(LINES)
|
268
|
+
colorHSV h, s, v, sa
|
269
|
+
vertex x1, y1
|
270
|
+
colorHSV h, s, v, ea
|
271
|
+
vertex x2, y2
|
272
|
+
endObj
|
273
|
+
end
|
274
|
+
|
275
|
+
def randVector(r)
|
276
|
+
rad = deg2rad(rand(360)) #360�x�̂ǂ����������͗����ł���ƁB
|
277
|
+
c = Math.cos(rad) * r
|
278
|
+
s = Math.sin(rad) * r
|
279
|
+
[c, s]
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
class ObjSound
|
284
|
+
def initialize(file, base=60, span=4)
|
285
|
+
@filename = file
|
286
|
+
@samp = loadSound(file) #@samp = Sample.new(file)
|
287
|
+
@samp.base = base
|
288
|
+
@count = 0
|
289
|
+
@span = span
|
290
|
+
end
|
291
|
+
|
292
|
+
def inspect
|
293
|
+
"#{@filename} #{@samp.base} #{@span}"
|
294
|
+
end
|
295
|
+
|
296
|
+
def play(note, volume, pan)
|
297
|
+
@count += 1
|
298
|
+
if @span < @count
|
299
|
+
@count = 0
|
300
|
+
#p [self, note, volume, pan]
|
301
|
+
@samp.playNote(note, volume, pan)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
# �O�Տ�
|
307
|
+
class TrailFields < Objs
|
308
|
+
def initialize(orgclass, max=MAX)
|
309
|
+
super(orgclass, max)
|
310
|
+
@a = []
|
311
|
+
@cur_trail = nil
|
312
|
+
onMouseDown(0, 0)
|
313
|
+
end
|
314
|
+
|
315
|
+
attr_reader :a
|
316
|
+
|
317
|
+
def onMouseDown(x, y)
|
318
|
+
@cur_trail = @orgclass.dup
|
319
|
+
@cur_trail.init(self, x, y, x, y)
|
320
|
+
@a << @cur_trail
|
321
|
+
@a.shift if @max < @a.length
|
322
|
+
end
|
323
|
+
|
324
|
+
def onMouseUp(x, y)
|
325
|
+
@cur_trail.start_trail_process
|
326
|
+
end
|
327
|
+
|
328
|
+
def add(x, y, lx, ly)
|
329
|
+
len = V2.length(x - lx, y - ly)
|
330
|
+
if len != 0
|
331
|
+
@cur_trail.add_trail(x, y, lx, ly, len)
|
332
|
+
else
|
333
|
+
onMouseUp(x, y)
|
334
|
+
onMouseDown(x, y)
|
335
|
+
end
|
336
|
+
@running = true
|
337
|
+
end
|
338
|
+
|
339
|
+
def move
|
340
|
+
@a.each {|m|
|
341
|
+
m.move if m.enable
|
342
|
+
}
|
343
|
+
end
|
344
|
+
|
345
|
+
def render
|
346
|
+
r = false
|
347
|
+
@a.each {|m|
|
348
|
+
if m.enable
|
349
|
+
m.render
|
350
|
+
r = true
|
351
|
+
end
|
352
|
+
}
|
353
|
+
@running = r
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
class TrailField < Obj
|
358
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
require "sdl"
|
5
|
+
require "opengl"
|
6
|
+
require "sgl/sgl-color"
|
7
|
+
require "sgl/opengl-window"
|
8
|
+
require "sgl/opengl-color"
|
9
|
+
require "sgl/opengl-event"
|
10
|
+
require "sgl/opengl-draw"
|
11
|
+
require "sgl/sgl-sound"
|
12
|
+
|
13
|
+
module SGL
|
14
|
+
class Application
|
15
|
+
def initialize
|
16
|
+
Thread.abort_on_exception = true
|
17
|
+
@options = default_options
|
18
|
+
initialize_window # opengl-window.rb
|
19
|
+
initialize_color # sgl-color.rb
|
20
|
+
initialize_event # opengl-event.rb
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_options
|
24
|
+
{
|
25
|
+
:fullscreen=>nil,
|
26
|
+
:fov=>45,
|
27
|
+
:cursor=>nil,
|
28
|
+
:depth=>false,
|
29
|
+
:culling=>false,
|
30
|
+
:smooth=>false,
|
31
|
+
:delaytime=>1.0/60,
|
32
|
+
:framerate=>nil,
|
33
|
+
:runtime=>nil,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
private :default_options
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +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
|
@@ -0,0 +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
|