1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
| Option Explicit
Const MaxX = 60
Const MaxY = 40
Const MaxZ = 25
Dim Room(MaxX, MaxY, MaxZ, 4) As Single '(LxBxH,v) in dm
'waarden voor room-values (type declaratie is mooier)
Const vDruk = 0
Const vClrR = 1
Const vClrG = 2
Const vClrB = 3
Const vOpac = 4
Dim MinDruk As Single ' globaal voor het gemak
Dim MaxDruk As Single ' globaal voor het gemak
'------------------------------------------------
Private Function GetRGB(r As Single, ByRef cr As Single, ByRef cg As Single, ByRef cb As Single, ByRef co As Single) As Long
Dim p As Single
' HSL is misschien iets beter
p = 8 * Atn(1)
cr = 255 * (1 + 1.45 * Cos((0 / 3 - r + 0.35) * p)) 'de 1+2.25x bedenk ik even ter plekke
cg = 255 * (1 + 1.45 * Cos((1 / 3 - r + 0.35) * p))
cb = 255 * (1 + 1.45 * Cos((2 / 3 - r + 0.35) * p))
co = (0 + 0.55 * Sin(r * 6 * p))
If co > 0 Then co = co ^ 8
If cr < 0 Then cr = 0
If cg < 0 Then cg = 0
If cb < 0 Then cb = 0
If co < 0 Then co = 0 Else If co > 1 Then co = 1
End Function
Private Function GetClr(r As Single, ByRef opac As Single) As Long
Dim cr As Single
Dim cg As Single
Dim cb As Single
GetRGB r, cr, cg, cb, opac
GetClr = RGB(cr, cg, cb)
End Function
'------------------------------------------------
Private Sub ClearArray()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim v As Integer
' redim werkt sneller... maar array is klein genoeg
For x = 0 To MaxX
For y = 0 To MaxY
For z = 0 To MaxZ
For v = 0 To 4
Room(x, y, z, v) = 0
Next v, z, y, x
MinDruk = 10000000
MaxDruk = 0
End Sub
Private Function getPunt(px As Integer, py As Integer, pz As Integer, ByRef x As Single, ByRef y As Single, ByRef z As Single) As Boolean
Dim inRoom As Boolean
Dim persp As Single
'px= x*0.900 - y*0.307 + z*0.000
'py= x*0.111 + y*0.275 - z*1.000
'px.min= 0*0.900 -40*0.307+25*0.000 = -12.28
'px.max=60*0.900 - 0*0.307+25*0.000 = +54.00
'py.min= 0*0.111 + 0*0.275-25*1.000 = -25.00
'py.max=60*0.111 +40*0.275- 0*1.000 = +17.66
'dus:
'px= x*9.00 - y*3.07 + 125
'py= x*1.11 + y*2.75 - z*10 + 250
' Range (x1,y1)-(x2,y2) = ( 2.55, 10)-( 665, 426.6)
'pz=x+y*2.5
'pz.max=60+40*2.5=160
'even wat meer perspectief
y = (pz * 9 - px + 125) / (3.07 + 2.5 * 9)
x = pz - y * 2.5
z = (x * 1.11 + y * 2.75 + 250 - py) / 10
'Even een Empirisch Verdwijnpunt
'persp = (160 + 900 - pz) / 900#
'x = x * persp
'y = y * persp
'z = z * persp
inRoom = True
If (x < 0) Or (x >= MaxX) Then inRoom = False
If (y < 0) Or (y >= MaxY) Then inRoom = False
If (z < 0) Or (z >= MaxZ) Then inRoom = False
getPunt = inRoom
End Function
Private Function GetPuntClr(x As Single, y As Single, z As Single, ByRef cr As Single, ByRef cg As Single, ByRef cb As Single, ByRef co As Single)
' Bicubic interpolatie is mooier
Dim x0 As Single
Dim x1 As Single
Dim y0 As Single
Dim y1 As Single
Dim z0 As Single
Dim z1 As Single
If 1 = 2 Then
cr = Room(x, y, z, vClrR)
cg = Room(x, y, z, vClrG)
cb = Room(x, y, z, vClrB)
co = Room(x, y, z, vOpac)
Else ' toch maar en Tri-Cubic proberen dan :)
If Int(x) = MaxX Then x = MaxX - 0.00001
If Int(y) = MaxY Then y = MaxY - 0.00001
If Int(z) = MaxZ Then z = MaxZ - 0.00001
x1 = x - Int(x): x0 = 1 - x1
y1 = y - Int(y): y0 = 1 - y1
z1 = z - Int(z): z0 = 1 - z1
x = Int(x)
y = Int(y)
z = Int(z)
cr = _
z0 * ((Room(x, y + 0, z + 0, vClrR) * x0 + Room(x + 1, y + 0, z + 0, vClrR) * x1) * y0 _
+ (Room(x, y + 1, z + 0, vClrR) * x0 + Room(x + 1, y + 1, z + 0, vClrR) * x1) * y1) _
+ _
z1 * ((Room(x, y + 0, z + 1, vClrR) * x0 + Room(x + 1, y + 0, z + 1, vClrR) * x1) * y0 _
+ (Room(x, y + 1, z + 1, vClrR) * x0 + Room(x + 1, y + 1, z + 1, vClrR) * x1) * y1)
cg = _
z0 * ((Room(x, y + 0, z + 0, vClrG) * x0 + Room(x + 1, y + 0, z + 0, vClrG) * x1) * y0 _
+ (Room(x, y + 1, z + 0, vClrG) * x0 + Room(x + 1, y + 1, z + 0, vClrG) * x1) * y1) _
+ _
z1 * ((Room(x, y + 0, z + 1, vClrG) * x0 + Room(x + 1, y + 0, z + 1, vClrG) * x1) * y0 _
+ (Room(x, y + 1, z + 1, vClrG) * x0 + Room(x + 1, y + 1, z + 1, vClrG) * x1) * y1)
cb = _
z0 * ((Room(x, y + 0, z + 0, vClrB) * x0 + Room(x + 1, y + 0, z + 0, vClrB) * x1) * y0 _
+ (Room(x, y + 1, z + 0, vClrB) * x0 + Room(x + 1, y + 1, z + 0, vClrB) * x1) * y1) _
+ _
z1 * ((Room(x, y + 0, z + 1, vClrB) * x0 + Room(x + 1, y + 0, z + 1, vClrB) * x1) * y0 _
+ (Room(x, y + 1, z + 1, vClrB) * x0 + Room(x + 1, y + 1, z + 1, vClrB) * x1) * y1)
co = _
z0 * ((Room(x, y + 0, z + 0, vOpac) * x0 + Room(x + 1, y + 0, z + 0, vOpac) * x1) * y0 _
+ (Room(x, y + 1, z + 0, vOpac) * x0 + Room(x + 1, y + 1, z + 0, vOpac) * x1) * y1) _
+ _
z1 * ((Room(x, y + 0, z + 1, vOpac) * x0 + Room(x + 1, y + 0, z + 1, vOpac) * x1) * y0 _
+ (Room(x, y + 1, z + 1, vOpac) * x0 + Room(x + 1, y + 1, z + 1, vOpac) * x1) * y1)
End If
End Function
Private Sub ShowRoom()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim cr As Single
Dim cg As Single
Dim cb As Single
Dim co As Single
Dim Tcr As Single
Dim Tcg As Single
Dim Tcb As Single
Dim Tco As Single
Dim x As Single
Dim y As Single
Dim z As Single
Dim T As Single
T = Timer
For i = 0 To Pic.ScaleWidth - 1
If (Timer - T) > 1 Then DoEvents: T = Timer
For j = 0 To Pic.ScaleHeight - 1
Tcr = 0
Tcg = 0
Tcb = 0
Tco = 0
For k = 0 To 160 'Step 7
If getPunt(i, j, k, x, y, z) Then
GetPuntClr x, y, z, cr, cg, cb, co
If co > 0.0001 Then
Tcr = Tcr * (1 - co) + cr * co
Tcg = Tcg * (1 - co) + cg * co
Tcb = Tcb * (1 - co) + cb * co
End If
End If
Next k
Pic.PSet (i, j), RGB(Tcr, Tcg, Tcb)
Next j, i
End Sub
Private Sub SetBorders()
Dim x As Integer
Dim y As Integer
Dim z As Integer
For x = 0 To MaxX
Room(x, 0, 0, vClrR) = 255
Room(x, 0, 0, vClrG) = 255
Room(x, 0, 0, vClrB) = 255
Room(x, 0, 0, vOpac) = 1
Room(x, 0, MaxZ, vClrR) = 255
Room(x, 0, MaxZ, vClrG) = 255
Room(x, 0, MaxZ, vClrB) = 255
Room(x, 0, MaxZ, vOpac) = 1
Room(x, MaxY, MaxZ, vClrR) = 255
Room(x, MaxY, MaxZ, vClrG) = 255
Room(x, MaxY, MaxZ, vClrB) = 255
Room(x, MaxY, MaxZ, vOpac) = 1
Room(x, MaxY, 0, vClrR) = 255
Room(x, MaxY, 0, vClrG) = 255
Room(x, MaxY, 0, vClrB) = 255
Room(x, MaxY, 0, vOpac) = 1
Next x
For y = 0 To MaxY
Room(0, y, 0, vClrR) = 255
Room(0, y, 0, vClrG) = 255
Room(0, y, 0, vClrB) = 255
Room(0, y, 0, vOpac) = 1
Room(0, y, MaxZ, vClrR) = 255
Room(0, y, MaxZ, vClrG) = 255
Room(0, y, MaxZ, vClrB) = 255
Room(0, y, MaxZ, vOpac) = 1
Room(MaxX, y, MaxZ, vClrR) = 255
Room(MaxX, y, MaxZ, vClrG) = 255
Room(MaxX, y, MaxZ, vClrB) = 255
Room(MaxX, y, MaxZ, vOpac) = 1
Room(MaxX, y, 0, vClrR) = 255
Room(MaxX, y, 0, vClrG) = 255
Room(MaxX, y, 0, vClrB) = 255
Room(MaxX, y, 0, vOpac) = 1
Next y
For z = 0 To MaxZ
Room(0, 0, z, vClrR) = 255
Room(0, 0, z, vClrG) = 255
Room(0, 0, z, vClrB) = 255
Room(0, 0, z, vOpac) = 1
Room(0, MaxY, z, vClrR) = 255
Room(0, MaxY, z, vClrG) = 255
Room(0, MaxY, z, vClrB) = 255
Room(0, MaxY, z, vOpac) = 1
Room(MaxX, MaxY, z, vClrR) = 255
Room(MaxX, MaxY, z, vClrG) = 255
Room(MaxX, MaxY, z, vClrB) = 255
Room(MaxX, MaxY, z, vOpac) = 1
Room(MaxX, 0, z, vClrR) = 255
Room(MaxX, 0, z, vClrG) = 255
Room(MaxX, 0, z, vClrB) = 255
Room(MaxX, 0, z, vOpac) = 1
Next z
End Sub
Private Sub PaintSide()
Dim x As Integer
Dim y As Integer
Dim z As Integer
z = 0
For x = 0 To MaxX
For y = 0 To MaxY
Room(x, y, z, vOpac) = (1 + Room(x, y, z, vOpac) * 9) / 10
Next y, x
y = 0
For x = 0 To MaxX
For z = 0 To MaxZ
Room(x, y, z, vOpac) = (1 + Room(x, y, z, vOpac) * 9) / 10
Next z, x
x = 0
For y = 0 To MaxY
For z = 0 To MaxZ
Room(x, y, z, vOpac) = (1 + Room(x, y, z, vOpac) * 9) / 10
Next z, y
End Sub
Private Sub DoBounce(OrigX As Single, OrigY As Single, OrigZ As Single, Druk As Single)
Dim BounceCount As Integer
Dim BounceX As Integer
Dim BounceY As Integer
Dim BounceZ As Integer
Dim BounceDemping As Single
Dim Demping As Single
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim px As Integer
Dim py As Integer
Dim pz As Integer
Dim dx As Single
Dim dy As Single
Dim dz As Single
Dim r2 As Single
Dim LocalDruk As Single
BounceCount = 0 ' Reflecteer aantal
Demping = 0.4 ' Drukgolf word voor 60% geabsorbeerd
For BounceX = -BounceCount To BounceCount ' Reflectie
For BounceY = -BounceCount To BounceCount
For BounceZ = -BounceCount To BounceCount
BounceDemping = Demping ^ (Abs(BounceX) + Abs(BounceY) + Abs(BounceZ))
'Scan ruimte
For x = 0 To MaxX
px = x + BounceX * MaxX
dx = px - OrigX
For y = 0 To MaxY
py = y + BounceY * MaxY
dy = py - OrigY
For z = 0 To MaxZ
pz = z + BounceZ * MaxZ
dz = pz - OrigZ
r2 = dx * dx + dy * dy + dz * dz '+ 10
r2 = r2 ^ 0.333
LocalDruk = BounceDemping * Druk * r2
' is hier eigenlijk een richtingsvector nodig?
Room(x, y, z, vDruk) = Room(x, y, z, vDruk) + LocalDruk
If Room(x, y, z, vDruk) > MaxDruk Then
MaxDruk = Room(x, y, z, vDruk)
ElseIf Room(x, y, z, vDruk) < MinDruk Then
MinDruk = Room(x, y, z, vDruk)
End If
Next z, y, x
Next BounceZ, BounceY, BounceX
End Sub
Private Sub Druk2Color()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim cr As Single
Dim cg As Single
Dim cb As Single
Dim co As Single
For x = 0 To MaxX
For y = 0 To MaxY
For z = 0 To MaxZ
GetRGB (Room(x, y, z, vDruk) - MinDruk) / (MaxDruk - MinDruk), cr, cg, cb, co
Room(x, y, z, vClrR) = cr
Room(x, y, z, vClrG) = cg
Room(x, y, z, vClrB) = cb
Room(x, y, z, vOpac) = co
Next z, y, x
End Sub
'------------------------------------------------
Private Sub Command1_Click()
' Test routine voor kleurgebruik
Dim i As Integer
Dim w As Integer
Dim co As Single
w = Pic.ScaleWidth - 1
For i = 0 To w
'Kleuren laten zien
Pic.Line (i, 0)-(i, Pic.ScaleHeight / 2), GetClr(i / w, co)
' doorzichtigheid laten zien
co = co * 255
Pic.Line (i, Pic.ScaleHeight / 2)-(i, Pic.ScaleHeight), RGB(co, co, co)
Next
End Sub
Private Sub Command2_Click()
' Test routine voor kamer
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim p As Single
ClearArray
'Teken de wanden in een kleur
z = 0
For x = 0 To MaxX
For y = 0 To MaxY
p = (((x \ 10) + (y \ 10) + 1) Mod 2) / 4# + 0.1
Room(x, y, z, vClrR) = 255 * x / MaxX
Room(x, y, z, vClrG) = 255 * y / MaxY
Room(x, y, z, vClrB) = 255 * p
Room(x, y, z, vOpac) = 1
Next y, x
y = 0
For x = 0 To MaxX
For z = 0 To MaxZ
p = (((x \ 10) + (z \ 10) + 1) Mod 2) / 4# + 0.1
Room(x, y, z, vClrR) = 255 * x / MaxX
Room(x, y, z, vClrG) = 255 * p
Room(x, y, z, vClrB) = 255 * z / MaxZ
Room(x, y, z, vOpac) = 1
Next z, x
x = 0
For y = 0 To MaxY
For z = 0 To MaxZ
p = (((y \ 10) + (z \ 10) + 1) Mod 2) / 4# + 0.1
Room(x, y, z, vClrR) = 255 * p
Room(x, y, z, vClrG) = 255 * y / MaxY
Room(x, y, z, vClrB) = 255 * z / MaxZ
Room(x, y, z, vOpac) = 1
Next z, y
SetBorders
ShowRoom
End Sub
Private Sub Command3_Click()
ClearArray
DoBounce 20, 15, 5, 200
DoBounce 55, 5, 20, 10
Druk2Color
SetBorders
PaintSide
ShowRoom
End Sub
'------------------------------------------------
Private Sub Form_Load()
Pic.ScaleMode = 3 ' In pixels
Pic.AutoRedraw = True 'Tekening wel laten staan als er een ander window overheen valt
Command1.Caption = "KleurTest"
Command2.Caption = "Kamer"
Command3.Caption = "DrukGolf"
End Sub |