1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Program to display Radiance scene using OpenGL. |
6 |
|
*/ |
7 |
|
|
11 |
– |
#include "radogl.h" |
12 |
– |
#include "view.h" |
13 |
– |
#include "paths.h" |
8 |
|
#include <sys/types.h> |
9 |
|
#include <GL/glx.h> |
10 |
|
#ifndef NOSTEREO |
11 |
|
#include <X11/extensions/SGIStereo.h> |
12 |
|
#endif |
13 |
|
#include <ctype.h> |
14 |
+ |
#include <string.h> |
15 |
+ |
#include <time.h> |
16 |
+ |
|
17 |
+ |
#include "radogl.h" |
18 |
+ |
#include "view.h" |
19 |
+ |
#include "paths.h" |
20 |
|
#include "glradicon.h" |
21 |
+ |
#include "rtprocess.h" |
22 |
|
|
23 |
|
#ifndef MAXVIEW |
24 |
|
#define MAXVIEW 63 /* maximum number of standard views */ |
27 |
|
#define MAXSCENE 127 /* maximum number of scene files */ |
28 |
|
#endif |
29 |
|
|
30 |
< |
#define ZOOMPCT 9 /* percent to zoom at a time */ |
30 |
> |
#define ZOOMPCT 9 /* percent to zoom for +/- */ |
31 |
> |
#define WZOOMPCT 3 /* percent to zoom for mouse wheel */ |
32 |
|
|
33 |
< |
#define MOVPCT 7 /* percent distance to move /frame */ |
33 |
> |
#define MOVPCT 4 /* percent distance to move /frame */ |
34 |
|
#define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) |
35 |
< |
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
35 |
> |
#define MOVDEG (-1.5) /* degrees to orbit CW/down /frame */ |
36 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
37 |
|
|
38 |
|
#define BORWIDTH 5 /* border width */ |
76 |
|
int nscenef = 0; /* number of scene files */ |
77 |
|
char *octree; /* octree name (NULL if unnec.) */ |
78 |
|
|
79 |
< |
int rtpd[3]; /* rtrace process descriptors */ |
79 |
> |
SUBPROC rtpd = SP_INACTIVE; /* rtrace process descriptors */ |
80 |
|
|
81 |
|
int silent = 0; /* run rad silently? */ |
82 |
|
int backvis = 1; /* back faces visible? */ |
83 |
|
int stereo = 0; /* do stereo? */ |
84 |
|
|
85 |
|
#ifdef NOSTEREO |
86 |
< |
#define setstereobuf(bid) 0 |
86 |
> |
#define setstereobuf(bid) |
87 |
|
#else |
88 |
|
#define setstereobuf(bid) (glXWaitGL(), \ |
89 |
|
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
94 |
|
|
95 |
|
int no_render = 0; /* don't rerender */ |
96 |
|
|
95 |
– |
#ifdef BSD |
96 |
– |
#define strchr index |
97 |
– |
#endif |
98 |
– |
|
99 |
– |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
97 |
|
extern int nowarn; /* turn warnings off? */ |
101 |
– |
extern time_t time(); |
98 |
|
|
99 |
+ |
static void startrtrace(char *octname); |
100 |
+ |
static void runrad(int ac, char **av); |
101 |
+ |
static int findvw(char *nm); |
102 |
+ |
static int varmatch(char *s, char *vn); |
103 |
+ |
static char * scan4var(char *buf, int buflen, char *vname, FILE *fp); |
104 |
+ |
static void dev_open(char *id); |
105 |
+ |
static void dev_close(void); |
106 |
+ |
static int dev_view(VIEW *nv); |
107 |
+ |
static int dev_input(int nsecs); |
108 |
+ |
static void render(void); |
109 |
+ |
static int moveview(int dx, int dy, int mov, int orb); |
110 |
+ |
static void waitabit(void); |
111 |
+ |
static void getmove(XButtonPressedEvent *ebut); |
112 |
+ |
static int getintersect(FVECT wp, FVECT org, FVECT dir, double md); |
113 |
+ |
static void setglpersp(VIEW *vp); |
114 |
+ |
static int getkey(XKeyPressedEvent *ekey); |
115 |
+ |
static void zoomview(int pct, int dx, int dy); |
116 |
+ |
static void gotoview(int vwnum); |
117 |
+ |
static void appendview(char *nm, VIEW *vp); |
118 |
+ |
static void copylastv(char *cause); |
119 |
+ |
static void fixwindow(XExposeEvent *eexp); |
120 |
+ |
static void resizewindow(XConfigureEvent *ersz); |
121 |
|
|
122 |
< |
main(argc, argv) |
123 |
< |
int argc; |
124 |
< |
char *argv[]; |
122 |
> |
|
123 |
> |
int |
124 |
> |
main( |
125 |
> |
int argc, |
126 |
> |
char *argv[] |
127 |
> |
) |
128 |
|
{ |
129 |
|
char *viewsel = NULL; |
130 |
|
long vwintvl = 0; |
163 |
|
/* run rad and get views */ |
164 |
|
runrad(argc-i, argv+i); |
165 |
|
/* check view */ |
166 |
< |
if (viewsel != NULL) |
166 |
> |
if (viewsel != NULL) { |
167 |
|
if (viewsel[0] == '-') { |
168 |
|
char *ve = viewsel; |
169 |
|
if (!sscanview(&thisview, viewsel) || |
178 |
|
progname, viewsel); |
179 |
|
quit(1); |
180 |
|
} |
181 |
+ |
} |
182 |
|
/* open GL */ |
183 |
|
dev_open(radfile = argv[i]); |
184 |
|
/* load octree or scene files */ |
185 |
|
if (octree != NULL) { |
186 |
< |
displist = rgl_octlist(octree, NULL, NULL); |
186 |
> |
displist = rgl_octlist(octree, NULL, NULL, NULL); |
187 |
|
startrtrace(octree); |
188 |
|
} else |
189 |
< |
displist = rgl_filelist(nscenef, scene); |
189 |
> |
displist = rgl_filelist(nscenef, scene, NULL); |
190 |
|
/* set initial view */ |
191 |
|
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
192 |
|
/* input/render loop */ |
199 |
|
"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n", |
200 |
|
argv[0]); |
201 |
|
quit(1); |
202 |
+ |
return 1; /* pro forma return */ |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
< |
quit(code) /* exit gracefully */ |
207 |
< |
int code; |
206 |
> |
void |
207 |
> |
quit( /* exit gracefully */ |
208 |
> |
int code |
209 |
> |
) |
210 |
|
{ |
211 |
|
if (ourdisplay != NULL) |
212 |
|
dev_close(); |
213 |
< |
if (rtpd[2] > 0) { |
214 |
< |
if (close_process(rtpd) > 0) |
213 |
> |
/* if (rtpd.pid > 0) { */ |
214 |
> |
if (rtpd.flags & PF_RUNNING) { |
215 |
> |
if (close_process(&rtpd) > 0) |
216 |
|
wputs("bad exit status from rtrace\n"); |
217 |
< |
rtpd[2] = 0; |
217 |
> |
/* rtpd.pid = 0; */ |
218 |
|
} |
219 |
|
exit(code); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
< |
startrtrace(octname) /* start rtrace on octname */ |
224 |
< |
char *octname; |
223 |
> |
static void |
224 |
> |
startrtrace( /* start rtrace on octname */ |
225 |
> |
char *octname |
226 |
> |
) |
227 |
|
{ |
228 |
|
static char *av[12] = {"rtrace", "-h", "-fff", "-ld+", |
229 |
|
"-opL", "-x", "1"}; |
232 |
|
if (nowarn) av[ac++] = "-w-"; |
233 |
|
av[ac++] = octname; |
234 |
|
av[ac] = NULL; |
235 |
< |
if (open_process(rtpd, av) <= 0) |
235 |
> |
if (open_process(&rtpd, av) <= 0) |
236 |
|
error(SYSTEM, "cannot start rtrace process"); |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
< |
runrad(ac, av) /* run rad and load variables */ |
241 |
< |
int ac; |
242 |
< |
char **av; |
240 |
> |
static void |
241 |
> |
runrad( /* run rad and load variables */ |
242 |
> |
int ac, |
243 |
> |
char **av |
244 |
> |
) |
245 |
|
{ |
246 |
|
static char optfile[] = TEMPLATE; |
247 |
|
int nvn = 0, nvv = 0; |
248 |
|
FILE *fp; |
249 |
< |
int cval; |
220 |
< |
register char *cp; |
249 |
> |
char *cp; |
250 |
|
char radcomm[256], buf[128], nam[32]; |
251 |
|
/* set rad commmand */ |
252 |
|
strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ |
273 |
|
/* get exposure */ |
274 |
|
if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) { |
275 |
|
expval = atof(cp); |
276 |
< |
if (*cp == '-' | *cp == '+') |
276 |
> |
if ((*cp == '-') | (*cp == '+')) |
277 |
|
expval = pow(2., expval); |
278 |
|
expval *= 0.5; /* compensate for local shading */ |
279 |
|
} |
282 |
|
eyedist = atof(cp); |
283 |
|
/* look for materials */ |
284 |
|
while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { |
285 |
< |
nscenef += wordstring(scene+nscenef, cp); |
285 |
> |
nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp); |
286 |
|
buf[0] = '\0'; |
287 |
|
} |
288 |
|
/* look for octree */ |
290 |
|
octree = savqstr(cp); |
291 |
|
/* look for scene files */ |
292 |
|
while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) { |
293 |
< |
nscenef += wordstring(scene+nscenef, cp); |
293 |
> |
nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp); |
294 |
|
buf[0] = '\0'; |
295 |
|
} |
296 |
|
/* load view names */ |
305 |
|
do |
306 |
|
if (isview(buf)) { |
307 |
|
vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW)); |
308 |
< |
copystruct(vwl[nvv].v, &stdview); |
308 |
> |
*(vwl[nvv].v) = stdview; |
309 |
|
sscanview(vwl[nvv].v, buf); |
310 |
|
if ((cp = setview(vwl[nvv++].v)) != NULL) { |
311 |
|
fprintf(stderr, "%s: bad view %d - %s\n", |
327 |
|
atof(sskip2(buf+4,1)), |
328 |
|
atof(sskip2(buf+4,2))); |
329 |
|
else if (backvis && !strncmp(buf, "-bv", 3) && |
330 |
< |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
330 |
> |
(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL)) |
331 |
|
backvis = 0; |
332 |
|
fclose(fp); |
333 |
|
unlink(optfile); /* delete options file */ |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
< |
int |
338 |
< |
findvw(nm) /* find named view */ |
339 |
< |
register char *nm; |
337 |
> |
static int |
338 |
> |
findvw( /* find named view */ |
339 |
> |
char *nm |
340 |
> |
) |
341 |
|
{ |
342 |
< |
register int n; |
342 |
> |
int n; |
343 |
|
|
344 |
< |
if (*nm >= '1' & *nm <= '9' && |
344 |
> |
if ((*nm >= '1') & (*nm <= '9') && |
345 |
|
(n = atoi(nm)-1) <= MAXVIEW && vwl[n].v != NULL) |
346 |
|
return(n); |
347 |
|
for (n = 0; vwl[n].v != NULL; n++) |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
< |
int |
355 |
< |
varmatch(s, vn) /* match line to variable */ |
356 |
< |
register char *s, *vn; |
354 |
> |
static int |
355 |
> |
varmatch( /* match line to variable */ |
356 |
> |
char *s, |
357 |
> |
char *vn |
358 |
> |
) |
359 |
|
{ |
360 |
< |
register int c; |
360 |
> |
int c; |
361 |
|
|
362 |
|
for ( ; *vn && *s == *vn; s++, vn++) |
363 |
|
; |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
< |
char * |
375 |
< |
scan4var(buf, buflen, vname, fp) /* scan for variable from fp */ |
376 |
< |
char *buf; |
377 |
< |
int buflen; |
378 |
< |
char *vname; |
379 |
< |
FILE *fp; |
374 |
> |
static char * |
375 |
> |
scan4var( /* scan for variable from fp */ |
376 |
> |
char *buf, |
377 |
> |
int buflen, |
378 |
> |
char *vname, |
379 |
> |
FILE *fp |
380 |
> |
) |
381 |
|
{ |
382 |
|
int cval; |
383 |
< |
register char *cp; |
383 |
> |
char *cp; |
384 |
|
/* search out matching line */ |
385 |
|
while ((cval = varmatch(buf, vname))) { |
386 |
|
if (cval > 0) /* gone too far? */ |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
< |
dev_open(id) /* initialize GLX driver */ |
401 |
< |
char *id; |
400 |
> |
static void |
401 |
> |
dev_open( /* initialize GLX driver */ |
402 |
> |
char *id |
403 |
> |
) |
404 |
|
{ |
405 |
|
static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4, |
406 |
|
GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4, |
450 |
|
/* set window manager hints */ |
451 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
452 |
|
ourxwmhints.input = True; |
453 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
454 |
< |
gwind, glradicon_bits, glradicon_width, glradicon_height); |
453 |
> |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, |
454 |
> |
(char *)glradicon_bits, glradicon_width, glradicon_height); |
455 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
456 |
|
/* set GLX context */ |
457 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
482 |
|
no_render++; |
483 |
|
do |
484 |
|
dev_input(0); /* get resize event */ |
485 |
< |
while (hres == 0 & vres == 0); |
485 |
> |
while ((hres == 0) & (vres == 0)); |
486 |
|
no_render--; |
487 |
|
rgl_checkerr("initializing GLX"); |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
< |
dev_close() /* close our display and free resources */ |
491 |
> |
static void |
492 |
> |
dev_close(void) /* close our display and free resources */ |
493 |
|
{ |
494 |
|
glXMakeCurrent(ourdisplay, None, NULL); |
495 |
|
glXDestroyContext(ourdisplay, gctx); |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
< |
int |
504 |
< |
dev_view(nv) /* assign new driver view */ |
505 |
< |
register VIEW *nv; |
503 |
> |
static int |
504 |
> |
dev_view( /* assign new driver view */ |
505 |
> |
VIEW *nv |
506 |
> |
) |
507 |
|
{ |
508 |
|
int newhres = hres, newvres = vres; |
509 |
|
double wa, va; |
512 |
|
error(COMMAND, "illegal view type"); |
513 |
|
nv->type = VT_PER; |
514 |
|
} |
515 |
< |
if (nv->horiz > 160. | nv->vert > 160.) { |
515 |
> |
if ((nv->horiz > 160.) | (nv->vert > 160.)) { |
516 |
|
error(COMMAND, "illegal view angle"); |
517 |
|
if (nv->horiz > 160.) |
518 |
|
nv->horiz = 160.; |
519 |
|
if (nv->vert > 160.) |
520 |
|
nv->vert = 160.; |
521 |
|
} |
522 |
< |
if (hres != 0 & vres != 0) { |
522 |
> |
if ((hres != 0) & (vres != 0)) { |
523 |
|
wa = (vres*pheight)/(hres*pwidth); |
524 |
|
va = viewaspect(nv); |
525 |
|
if (va > wa+.05) { |
535 |
|
newvres = (pwidth/pheight)*va*newhres + .5; |
536 |
|
} |
537 |
|
} |
538 |
< |
if (newhres != hres | newvres != vres) { |
538 |
> |
if ((newhres != hres) | (newvres != vres)) { |
539 |
|
no_render++; |
540 |
|
XResizeWindow(ourdisplay, gwind, newhres, newvres); |
541 |
|
do |
542 |
|
dev_input(0); /* get resize event */ |
543 |
< |
while (newhres != hres | newvres != vres); |
543 |
> |
while ((newhres != hres) & (newvres != vres)); |
544 |
|
no_render--; |
545 |
|
} |
546 |
|
} |
547 |
< |
copystruct(&thisview, nv); |
547 |
> |
thisview = *nv; |
548 |
|
setglpersp(&thisview); |
549 |
|
render(); |
550 |
|
return(1); |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
< |
int |
555 |
< |
dev_input(nsecs) /* get next input event */ |
556 |
< |
int nsecs; |
554 |
> |
static int |
555 |
> |
dev_input( /* get next input event */ |
556 |
> |
int nsecs |
557 |
> |
) |
558 |
|
{ |
559 |
|
#if 0 |
560 |
|
static time_t lasttime = 0; |
585 |
|
case KeyPress: |
586 |
|
return(getkey(levptr(XKeyPressedEvent))); |
587 |
|
case ButtonPress: |
588 |
< |
getmove(levptr(XButtonPressedEvent)); |
588 |
> |
switch (levptr(XButtonPressedEvent)->button) { |
589 |
> |
case Button4: /* wheel up */ |
590 |
> |
zoomview(100+WZOOMPCT, levptr(XButtonPressedEvent)->x, |
591 |
> |
vres-1-levptr(XButtonPressedEvent)->y); |
592 |
> |
break; |
593 |
> |
case Button5: /* wheel down */ |
594 |
> |
zoomview(100-WZOOMPCT, levptr(XButtonPressedEvent)->x, |
595 |
> |
vres-1-levptr(XButtonPressedEvent)->y); |
596 |
> |
break; |
597 |
> |
default: |
598 |
> |
getmove(levptr(XButtonPressedEvent)); |
599 |
> |
break; |
600 |
> |
} |
601 |
|
break; |
602 |
|
} |
603 |
|
return(1); |
604 |
|
} |
605 |
|
|
606 |
|
|
607 |
< |
render() /* render our display list and swap buffers */ |
607 |
> |
static void |
608 |
> |
render(void) /* render our display list and swap buffers */ |
609 |
|
{ |
610 |
|
double d; |
611 |
|
|
631 |
|
} |
632 |
|
|
633 |
|
|
634 |
< |
moveview(dx, dy, mov, orb) /* move our view */ |
635 |
< |
int dx, dy, mov, orb; |
634 |
> |
static int |
635 |
> |
moveview( /* move our view */ |
636 |
> |
int dx, |
637 |
> |
int dy, |
638 |
> |
int mov, |
639 |
> |
int orb |
640 |
> |
) |
641 |
|
{ |
642 |
|
VIEW nv; |
643 |
|
FVECT odir, v1, wp; |
644 |
|
double d; |
589 |
– |
register int li; |
645 |
|
/* start with old view */ |
646 |
< |
copystruct(&nv, &thisview); |
646 |
> |
nv = thisview; |
647 |
|
/* change view direction */ |
648 |
|
if ((d = viewray(v1, odir, &thisview, |
649 |
|
(dx+.5)/hres, (dy+.5)/vres)) < -FTINY) |
659 |
|
VSUM(nv.vp, wp, odir, -1.); |
660 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
661 |
|
} else if (orb) { /* orbit up/down */ |
662 |
< |
fcross(v1, odir, nv.vup); |
663 |
< |
if (normalize(v1) == 0.) |
662 |
> |
if (geodesic(odir, odir, nv.vup, |
663 |
> |
d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) |
664 |
|
return(0); |
610 |
– |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
665 |
|
VSUM(nv.vp, wp, odir, -1.); |
666 |
< |
spinvector(nv.vdir, nv.vdir, v1, d); |
666 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); |
667 |
|
} else if (mov) { /* move forward/backward */ |
668 |
|
d = MOVPCT/100. * mov; |
669 |
|
VSUM(nv.vp, nv.vp, odir, d); |
680 |
|
} |
681 |
|
|
682 |
|
|
683 |
< |
getmove(ebut) /* get view change */ |
684 |
< |
XButtonPressedEvent *ebut; |
683 |
> |
static void |
684 |
> |
waitabit(void) /* pause a moment */ |
685 |
|
{ |
686 |
+ |
struct timespec ts; |
687 |
+ |
ts.tv_sec = 0; |
688 |
+ |
ts.tv_nsec = 50000000; |
689 |
+ |
nanosleep(&ts, NULL); |
690 |
+ |
} |
691 |
+ |
|
692 |
+ |
|
693 |
+ |
static void |
694 |
+ |
getmove( /* get view change */ |
695 |
+ |
XButtonPressedEvent *ebut |
696 |
+ |
) |
697 |
+ |
{ |
698 |
|
int movdir = MOVDIR(ebut->button); |
699 |
|
int movorb = MOVORB(ebut->state); |
700 |
|
int moved = 0; |
708 |
|
|
709 |
|
while (!XCheckMaskEvent(ourdisplay, |
710 |
|
ButtonReleaseMask, levptr(XEvent))) { |
711 |
+ |
/* pause so as not to move too fast */ |
712 |
+ |
waitabit(); |
713 |
|
|
714 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
715 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
730 |
|
} |
731 |
|
|
732 |
|
|
733 |
< |
getintersect(wp, org, dir, md) /* intersect ray with scene geometry */ |
734 |
< |
FVECT wp; /* returned world intersection point */ |
735 |
< |
FVECT org, dir; |
736 |
< |
double md; |
733 |
> |
static int |
734 |
> |
getintersect( /* intersect ray with scene geometry */ |
735 |
> |
FVECT wp, /* returned world intersection point */ |
736 |
> |
FVECT org, |
737 |
> |
FVECT dir, |
738 |
> |
double md |
739 |
> |
) |
740 |
|
{ |
741 |
|
float fbuf[6]; |
742 |
|
/* check to see if rtrace is running */ |
743 |
< |
if (rtpd[2] <= 0) |
743 |
> |
/* if (rtpd.pid <= 0) */ |
744 |
> |
if (!(rtpd.flags & PF_RUNNING)) |
745 |
|
return(0); |
746 |
|
/* assign origin */ |
747 |
|
fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2]; |
749 |
|
if (md <= FTINY) md = FHUGE; |
750 |
|
fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; |
751 |
|
/* trace that ray */ |
752 |
< |
if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) != |
753 |
< |
4*sizeof(float)) |
752 |
> |
if (process(&rtpd, fbuf, fbuf, |
753 |
> |
4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) |
754 |
|
error(INTERNAL, "error getting data back from rtrace process"); |
755 |
|
if (fbuf[3] >= .99*FHUGE) |
756 |
|
return(0); /* missed local objects */ |
759 |
|
} |
760 |
|
|
761 |
|
|
762 |
< |
setglpersp(vp) /* set perspective view in GL */ |
763 |
< |
register VIEW *vp; |
762 |
> |
static void |
763 |
> |
setglpersp( /* set perspective view in GL */ |
764 |
> |
VIEW *vp |
765 |
> |
) |
766 |
|
{ |
767 |
|
double d, xmin, xmax, ymin, ymax, zmin, zmax; |
768 |
|
|
793 |
|
} |
794 |
|
|
795 |
|
|
796 |
< |
int |
797 |
< |
getkey(ekey) /* get input key */ |
798 |
< |
register XKeyPressedEvent *ekey; |
796 |
> |
static int |
797 |
> |
getkey( /* get input key */ |
798 |
> |
XKeyPressedEvent *ekey |
799 |
> |
) |
800 |
|
{ |
801 |
|
int n; |
802 |
|
char buf[8]; |
814 |
|
case 'l': /* retrieve last (premouse) view */ |
815 |
|
if (lastview.type) { |
816 |
|
VIEW vtmp; |
817 |
< |
copystruct(&vtmp, &thisview); |
817 |
> |
vtmp = thisview; |
818 |
|
dev_view(&lastview); |
819 |
< |
copystruct(&lastview, &vtmp); |
819 |
> |
lastview = vtmp; |
820 |
|
} else |
821 |
|
XBell(ourdisplay, 0); |
822 |
|
break; |
840 |
|
case 'V': /* append view to rad file */ |
841 |
|
appendview(NULL, &thisview); |
842 |
|
break; |
843 |
+ |
case 'Q': |
844 |
|
case 'q': /* quit the program */ |
845 |
|
return(0); |
846 |
|
default: |
851 |
|
} |
852 |
|
|
853 |
|
|
854 |
< |
zoomview(pct, dx, dy) /* zoom in or out around (dx,dy) */ |
855 |
< |
int pct; |
856 |
< |
int dx, dy; |
854 |
> |
static void |
855 |
> |
zoomview( /* zoom in or out around (dx,dy) */ |
856 |
> |
int pct, |
857 |
> |
int dx, |
858 |
> |
int dy |
859 |
> |
) |
860 |
|
{ |
861 |
|
double h, v; |
783 |
– |
FVECT direc; |
862 |
|
|
863 |
< |
if (pct == 100 | pct <= 0) |
863 |
> |
if ((pct == 100) | (pct <= 0)) |
864 |
|
return; |
865 |
|
copylastv("zooming"); |
866 |
|
h = (dx+.5)/hres - 0.5; |
879 |
|
} |
880 |
|
|
881 |
|
|
882 |
< |
gotoview(vwnum) /* go to specified view number */ |
883 |
< |
int vwnum; |
882 |
> |
static void |
883 |
> |
gotoview( /* go to specified view number */ |
884 |
> |
int vwnum |
885 |
> |
) |
886 |
|
{ |
887 |
|
if (vwnum < 0) |
888 |
|
for (vwnum = currentview; vwl[vwnum+1].v != NULL; vwnum++) |
894 |
|
} |
895 |
|
|
896 |
|
|
897 |
< |
appendview(nm, vp) /* append standard view */ |
898 |
< |
char *nm; |
899 |
< |
VIEW *vp; |
897 |
> |
static void |
898 |
> |
appendview( /* append standard view */ |
899 |
> |
char *nm, |
900 |
> |
VIEW *vp |
901 |
> |
) |
902 |
|
{ |
903 |
|
FILE *fp; |
904 |
|
/* check if already in there */ |
905 |
< |
if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { |
905 |
> |
if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { |
906 |
|
error(COMMAND, "view already in standard list"); |
907 |
|
return; |
908 |
|
} |
923 |
|
if (currentview >= MAXVIEW) |
924 |
|
error(INTERNAL, "too many views in appendview"); |
925 |
|
vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW)); |
926 |
< |
copystruct(vwl[currentview].v, &thisview); |
926 |
> |
*(vwl[currentview].v) = thisview; |
927 |
|
if (nm != NULL) |
928 |
|
vwl[currentview].nam = savqstr(nm); |
929 |
|
} |
930 |
|
|
931 |
|
|
932 |
< |
copylastv(cause) /* copy last view position */ |
933 |
< |
char *cause; |
932 |
> |
static void |
933 |
> |
copylastv( /* copy last view position */ |
934 |
> |
char *cause |
935 |
> |
) |
936 |
|
{ |
937 |
|
static char *lastvc; |
938 |
|
|
939 |
|
if (cause == lastvc) |
940 |
|
return; /* only record one view per cause */ |
941 |
|
lastvc = cause; |
942 |
< |
copystruct(&lastview, &thisview); |
942 |
> |
lastview = thisview; |
943 |
|
} |
944 |
|
|
945 |
|
|
946 |
< |
fixwindow(eexp) /* repair damage to window */ |
947 |
< |
register XExposeEvent *eexp; |
946 |
> |
static void |
947 |
> |
fixwindow( /* repair damage to window */ |
948 |
> |
XExposeEvent *eexp |
949 |
> |
) |
950 |
|
{ |
951 |
< |
if (hres == 0 | vres == 0) { /* first exposure */ |
951 |
> |
if ((hres == 0) | (vres == 0)) { /* first exposure */ |
952 |
|
resizewindow((XConfigureEvent *)eexp); |
953 |
|
return; |
954 |
|
} |
959 |
|
} |
960 |
|
|
961 |
|
|
962 |
< |
resizewindow(ersz) /* resize window */ |
963 |
< |
register XConfigureEvent *ersz; |
962 |
> |
static void |
963 |
> |
resizewindow( /* resize window */ |
964 |
> |
XConfigureEvent *ersz |
965 |
> |
) |
966 |
|
{ |
967 |
|
static char resizing[] = "resizing window"; |
968 |
|
double wa, va; |