roomviewer.s 29/01/1997 1 %donald

advertisement
roomviewer.s
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
29/01/1997
%donald
viewport view
#
The following definitions define a room ...
#
... and some objects inside the room.
#
# The room is rectangle in shape.
int
point
line
width, length
NW, NE, SW, SE
N1, N2, S, E, W
# the dimension of room
# the 4 corners of room
# the 4 walls of room
# North wall composites of 2 walls & a
door
### Every room has a door ###
# declare the door
openshape door
within door {
point
line
int
boolean
...
hinge, lock
door
width
open
#
#
#
#
a door has a hinge, and a lock
the door itself
the size of the door
use it as a flag, telling whether
# ... the door has opened
door = [hinge, lock]
lock = hinge + (if open then {0, -width} else {width, 0})
}
within door {
hinge = ~/NW + {15, -10}
hinge
open = true
width = 200
}
# set the coordinate of the
# the door has opened
# the size of the door
N1 = [NW, {door/hinge.1, NW.2}]
N2 = [{door/hinge.1+door/width, NW.2}, NE]
S = [SW, SE]
W = [NW, SW]
E = [NE, SE]
SW
SE
NE
NW
=
=
=
=
{100, 100}
SW + {width, 0}
SW + {width, length}
SW + {0, length}
width, length = 800, 800
# The other 3 corners are relative
# to South-West corner.
#
# 800*800 pts
######################################################################
#####
openshape table
# There is a table inside the room.
within table {
int
point
line
N
S
W
E
=
=
=
=
[NW,
[SW,
[NW,
[NE,
width, length
NW, NE, SW, SE
N, S, E, W
# the dimension of table
# the 4 corners of table
# the 4 sides of table
NE]
SE]
SW]
SE]
SE = SW + {width, 0}
NE = SW + {width, length}
NW = SW + {0, length}
# the other 3 corners are
# relative to SW corner
#
##### table/lamp #####
openshape lamp
within lamp {
point
int
# There is a lamp on the table
centre
size
# center of the table
# size of the lamp
1
roomviewer.s
29/01/1997
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
int
circle
half
base
# half of size
size = 50
half = size div 2
centre = (~/SW + ~/NE) div 2
table
# at the centre of
line
# L1-L8 forms an octagon.
L1, L2, L3, L4, L5, L6, L7, L8
L1 =
L2 =
L3 =
L4 =
L5 =
L6 =
L7 =
L8 =
base
[centre + {size, -half}, centre + {size, half}]
[L1.2, centre + {half, size}]
[L2.2, centre + {-half, size}]
[L3.2, centre + {-size, half}]
[L4.2, centre + {-size, -half}]
[L5.2, centre + {-half, -size}]
[L6.2, centre + {half, -size}]
[L7.2, L1.1]
= circle(centre, size * 1.25)
}
}
within table {
# let the size of table be 300*300 pts.
width, length = 300, 300
# place the SW of table at the center of the room.
SW = (~/SW + ~/NE) div 2
}
######################################################################
#####
point
plug
point
plug1, plug2
# there are 2 plugs.
plug1 = (S.1+S.2) div 2
# middle of South wall
plug2 = (E.1+E.2) div 2
# middle of East wall
line
cable
# cable connects the table/lamp and
the plug
int
cablelength
cable = [plug, table/lamp/centre]
plug = plug1
# let cable connects to plug1
cablelength = 600
#
# Now set the line style of cable be dotted line.
#
Because many Donald commands hasn't implemented,
#
I just directly access Eden using the non-standard `?'
command.
? A_cable = "linestyle=dashed,dash=13";
######################################################################
#####
openshape desk
within desk {
int
point
line
N
S
W
E
=
=
=
=
[NW,
[SW,
[NW,
[NE,
# there is a desk in the room
width, length
NW, NE, SW, SE
N, S, E, W
# the size of the desk
# the 4 corners of the desk
# the 4 edges of the desk
NE]
SE]
SW]
SE]
width, length = 250, 350
# initially the desk is placed at (100,100) of the
room.
SW = ~/SW + {15, 15}
SE = SW + {width, 0}
# the other 3 corners are ...
2
roomviewer.s
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
29/01/1997
NW = SW + {0, length}
NE = NW + {width, 0}
##### desk/drawer #####
openshape drawer
194
195
196
197
198
199
200
201
202
203
204
# the desk has a drawer
within drawer {
int
k
int
point
line
# k -#
#
#
width, length
NW, NE, SW, SE
N, S, W, E
a parameter describes
the condition of drawer
1 --> closed
larger k --> more open
# the size of drawer
# the 4 corners of the drawer
# the 4 edges of the drawer
# the size of the drawer is always a ratio to
...
# ... the desk.
width = ~/length div 3
length = ~/width - ~/width div k
k = 2
# initially, the draw is half
open
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
# ... relative to SW corner
#
NW
SW
SE
NE
N
S
W
E
=
=
=
=
=
=
=
=
~/NE
NW - {0, width}
SW + {length, 0}
NW + {length, 0}
[NW,
[SW,
[NW,
[NE,
# NW is always at desk's NE
# the other 3 corners are ...
# ... relative to NW
#
NE]
SE]
SW]
SE]
}
}
boolean doorHitTable, cableIsShort
doorHitTable = includes(circle(door/hinge, door/width),table/NW)
cableIsShort = dist(cable.1, cable.2) > cablelength
%scout
display scr, basicScreen;
window don1, don2;
window monDoor, monCable;
point monDoorPos, monCablePos;
string monDoorStr, monCableStr;
integer _doorHitTable, _cableIsShort, _door_open;
integer _plug, _plug1;
point p1, q1, p2, q2;
integer zoomSize;
point zoomPos;
point tblMenuRef, miscMenuRef, zoomMenuRef;
point plugButtonPos, doorButtonPos;
string plugMenu, doorMenu;
window plugButton, doorButton;
point tblMenuHeaderPos, tblUpPos, tblDownPos, tblLeftPos, tblRightPos;
string tblMenuHeader, tblUpMenu, tblDownMenu, tblLeftMenu,
tblRightMenu;
window tblHeader, tblUp, tblDown, tblLeft, tblRight;
point zoomMenuHeaderPos, zoomUpPos, zoomDownPos, zoomLeftPos,
zoomRightPos;
string zoomMenuHeader, zoomUpMenu, zoomDownMenu, zoomLeftMenu,
zoomRightMenu;
window zoomHeader, zoomUp, zoomDown, zoomLeft, zoomRight;
p1 = {25, 100};
q1 = {225, 300};
don1 = {
box:
[p1, q1],
pict:
"view",
type:
DONALD,
3
roomviewer.s
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
29/01/1997
border: 1
sensitive: ON
};
zoomPos = {500, 500};
zoomSize = 500;
p2 = {275, 100};
q2 = {475, 300};
don2 = {
box:
[p2, q2],
pict:
"view",
type:
DONALD,
xmin:
zoomPos.1
ymin:
zoomPos.2
xmax:
zoomPos.1
ymax:
zoomPos.2
border: 1
sensitive: ON
};
+
+
zoomSize/2,
zoomSize/2,
zoomSize/2,
zoomSize/2,
monDoor = {
frame: ([monDoorPos, 1, strlen(monDoorStr)]),
string: monDoorStr
};
monDoorStr = if _doorHitTable then "Table obstructs door" else ""
endif;
monDoorPos = {25, 50};
monCable = {
frame: ([monCablePos, 1, strlen(monCableStr)]),
string: monCableStr
};
monCableStr = if _cableIsShort then "Cable is not long enough" else ""
endif;
monCablePos = {25, 70};
tblMenuRef = {100, 400};
miscMenuRef = {250, 400};
zoomMenuRef = {400, 400};
plugButtonPos = miscMenuRef - {strlen(plugMenu).c / 2, 1.r};
plugButton = {
frame: ([plugButtonPos, 1, strlen(plugMenu)]),
string: plugMenu,
border: 1
sensitive: ON
};
plugMenu = if _plug == _plug1 then "9:Use Plug 2" else "9:Use Plug 1"
endif;
doorButtonPos = miscMenuRef + {-strlen(doorMenu).c / 2, 1.r};
doorButton = {
frame: ([doorButtonPos, 1, strlen(doorMenu)]),
string: doorMenu,
border: 1
sensitive: ON
};
doorMenu = if _door_open then "10:Close Door" else "10:Open Door"
endif;
tblMenuHeader = "Table Position";
tblMenuHeaderPos = tblMenuRef - {(strlen(tblMenuHeader)/2).c, 4.r};
tblHeader = {
frame: ([tblMenuHeaderPos, 1, strlen(tblMenuHeader)]),
string: tblMenuHeader
};
tblUpPos = tblMenuRef - {(strlen(tblUpMenu)/2).c, 2.r};
tblUp = {
frame: ([tblUpPos, 1, strlen(tblUpMenu)]),
string: tblUpMenu,
border: 1
sensitive: ON
};
4
roomviewer.s
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
29/01/1997
tblUpMenu = "1:Up";
tblDownPos = tblMenuRef + {-(strlen(tblDownMenu)/2).c, 2.r};
tblDown = {
frame: ([tblDownPos, 1, strlen(tblDownMenu)]),
string: tblDownMenu,
border: 1
sensitive: ON
};
tblDownMenu = "2:Down";
tblLeftPos = tblMenuRef - {(strlen(tblLeftMenu) + 1).c, 0};
tblLeft = {
frame: ([tblLeftPos, 1, strlen(tblLeftMenu)]),
string: tblLeftMenu,
border: 1
sensitive: ON
};
tblLeftMenu = "3:Left";
tblRightPos = tblMenuRef + {1.c, 0};
tblRight = {
frame: ([tblRightPos, 1, strlen(tblRightMenu)]),
string: tblRightMenu,
border: 1
sensitive: ON
};
tblRightMenu = "4:Right";
zoomMenuHeader = "Zoom Position";
zoomMenuHeaderPos = zoomMenuRef - {(strlen(zoomMenuHeader)/2).c, 4.r};
zoomHeader = {
frame: ([zoomMenuHeaderPos, 1, strlen(zoomMenuHeader)]),
string: zoomMenuHeader
};
zoomUpPos = zoomMenuRef - {(strlen(zoomUpMenu)/2).c, 2.r};
zoomUp = {
frame: ([zoomUpPos, 1, strlen(zoomUpMenu)]),
string: zoomUpMenu,
border: 1
sensitive: ON
};
zoomUpMenu = "5:Up";
zoomDownPos = zoomMenuRef + {-(strlen(zoomDownMenu)/2).c, 2.r};
zoomDown = {
frame: ([zoomDownPos, 1, strlen(zoomDownMenu)]),
string: zoomDownMenu,
border: 1
sensitive: ON
};
zoomDownMenu = "6:Down";
zoomLeftPos = zoomMenuRef - {(strlen(zoomLeftMenu) + 1).c, 0};
zoomLeft = {
frame: ([zoomLeftPos, 1, strlen(zoomLeftMenu)]),
string: zoomLeftMenu,
border: 1
sensitive: ON
};
zoomLeftMenu = "7:Left";
zoomRightPos = zoomMenuRef + {1.c, 0};
zoomRight = {
frame: ([zoomRightPos, 1, strlen(zoomRightMenu)]),
string: zoomRightMenu,
border: 1
sensitive: ON
};
zoomRightMenu = "8:Right";
basicScreen = < tblHeader / tblUp / tblDown / tblLeft / tblRight /
5
roomviewer.s
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
29/01/1997
zoomHeader / zoomUp / zoomDown / zoomLeft / zoomRight /
plugButton / doorButton /
don1 / don2 >;
scr = if _doorHitTable then
append(basicScreen, 1, monDoor)
else
basicScreen
endif;
#screen = < monDoor / monCable /
#
tblHeader / tblUp / tblDown / tblLeft / tblRight /
#
zoomHeader / zoomUp / zoomDown / zoomLeft / zoomRight /
#
plugButton / doorButton /
#
don1 / don2 >;
screen = if _cableIsShort then
append(scr, 1, monCable)
else
scr
endif;
%eden
proc handle_user_input : input
{
switch (input) {
case 1: _table_SW = vector_add(_table_SW, cart(0, 100));
break;
case 2: _table_SW = vector_sub(_table_SW, cart(0, 100));
break;
case 3: _table_SW = vector_sub(_table_SW, cart(100, 0));
break;
case 4: _table_SW = vector_add(_table_SW, cart(100, 0));
break;
case 5: zoomPos = pt_add(zoomPos, [0, 100]);
break;
case 6: zoomPos = pt_subtract(zoomPos, [0, 100]);
break;
case 7: zoomPos = pt_subtract(zoomPos, [100, 0]);
break;
case 8: zoomPos = pt_add(zoomPos, [100, 0]);
break;
case 9: if (_plug == _plug1) {
_plug is _plug2;
} else {
_plug is _plug1;
}
break;
case 10: _door_open = !_door_open;
break;
}
}
proc plugButton_to_input : plugButton_mouse_1 {
if (plugButton_mouse_1[2] == 4) input = 9;
}
proc doorButton_to_input : doorButton_mouse_1 {
if (doorButton_mouse_1[2] == 4) input = 10;
}
proc tblUp_to_input : tblUp_mouse_1 {
if (tblUp_mouse_1[2] == 4) input = 1;
}
proc tblDown_to_input : tblDown_mouse_1 {
if (tblDown_mouse_1[2] == 4) input = 2;
}
proc tblLeft_to_input : tblLeft_mouse_1 {
if (tblLeft_mouse_1[2] == 4) input = 3;
}
6
roomviewer.s
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
29/01/1997
proc tblRight_to_input : tblRight_mouse_1 {
if (tblRight_mouse_1[2] == 4) input = 4;
}
proc zoomUp_to_input : zoomUp_mouse_1 {
if (zoomUp_mouse_1[2] == 4) input = 5;
}
proc zoomDown_to_input : zoomDown_mouse_1 {
if (zoomDown_mouse_1[2] == 4) input = 6;
}
proc zoomLeft_to_input : zoomLeft_mouse_1 {
if (zoomLeft_mouse_1[2] == 4) input = 7;
}
proc zoomRight_to_input : zoomRight_mouse_1 {
if (zoomRight_mouse_1[2] == 4) input = 8;
}
proc don1_to_tableSW : don1_mouse {
auto mx, my;
mx = don1_mouse[4];
my = don1_mouse[5];
if (don1_mouse[2] == 4) {
if (_table_SW[2] < mx && mx < _table_NE[2] &&
_table_SW[3] < my && my < _table_NE[3]) move_table = 1;
old_table_SW = _table_SW;
old_mouse_pos = [mx, my];
}
if (don1_mouse[2] == 5) {
if (move_table == 1) {
_table_SW = cart(old_table_SW[2] + mx - old_mouse_pos[1],
old_table_SW[3] + my - old_mouse_pos[2]);
move_table = 0;
}
}
}
proc don2_to_tableSW : don2_mouse {
auto mx, my, xmin, xmax, ymin, ymax, m, c, cpi;
if (don2_mouse[2] == 4) {
mx = don2_mouse[4];
my = don2_mouse[5];
xmin = dotint(don2, 6);
ymin = dotint(don2, 7);
xmax = dotint(don2, 8);
ymax = dotint(don2, 9);
m = (ymax - ymin) / (xmax - xmin);
c = ymin - m * xmin;
cpi = ymax + m * xmin;
if ((my - m * mx) > c)
input = ((my + m * mx) > cpi) ? 5 : 7;
else
input = ((my + m * mx) > cpi) ? 8 : 6;
}
}
7
Download