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 */ |
70 |
|
double eyedist = 1; /* interocular distance */ |
71 |
|
VIEW lastview; /* last recorded view */ |
72 |
|
|
72 |
– |
char *progname; /* global argv[0] */ |
73 |
|
char *radfile; /* rad input file */ |
74 |
|
char *scene[MAXSCENE+1]; /* material and scene file list */ |
75 |
|
int nscenef = 0; /* number of scene files */ |
76 |
|
char *octree; /* octree name (NULL if unnec.) */ |
77 |
|
|
78 |
< |
SUBPROC rtpd; /* rtrace process descriptors */ |
78 |
> |
SUBPROC rtpd = SP_INACTIVE; /* rtrace process descriptors */ |
79 |
|
|
80 |
|
int silent = 0; /* run rad silently? */ |
81 |
|
int backvis = 1; /* back faces visible? */ |
97 |
|
|
98 |
|
static void startrtrace(char *octname); |
99 |
|
static void runrad(int ac, char **av); |
100 |
< |
static int findvw(register char *nm); |
101 |
< |
static int varmatch(register char *s, register char *vn); |
100 |
> |
static int findvw(char *nm); |
101 |
> |
static int varmatch(char *s, char *vn); |
102 |
|
static char * scan4var(char *buf, int buflen, char *vname, FILE *fp); |
103 |
|
static void dev_open(char *id); |
104 |
|
static void dev_close(void); |
105 |
< |
static int dev_view(register VIEW *nv); |
105 |
> |
static int dev_view(VIEW *nv); |
106 |
|
static int dev_input(int nsecs); |
107 |
|
static void render(void); |
108 |
|
static int moveview(int dx, int dy, int mov, int orb); |
109 |
|
static void waitabit(void); |
110 |
|
static void getmove(XButtonPressedEvent *ebut); |
111 |
|
static int getintersect(FVECT wp, FVECT org, FVECT dir, double md); |
112 |
< |
static void setglpersp(register VIEW *vp); |
113 |
< |
static int getkey(register XKeyPressedEvent *ekey); |
112 |
> |
static void setglpersp(VIEW *vp); |
113 |
> |
static int getkey(XKeyPressedEvent *ekey); |
114 |
|
static void zoomview(int pct, int dx, int dy); |
115 |
|
static void gotoview(int vwnum); |
116 |
|
static void appendview(char *nm, VIEW *vp); |
117 |
|
static void copylastv(char *cause); |
118 |
< |
static void fixwindow(register XExposeEvent *eexp); |
119 |
< |
static void resizewindow(register XConfigureEvent *ersz); |
118 |
> |
static void fixwindow(XExposeEvent *eexp); |
119 |
> |
static void resizewindow(XConfigureEvent *ersz); |
120 |
|
|
121 |
|
|
122 |
|
int |
128 |
|
char *viewsel = NULL; |
129 |
|
long vwintvl = 0; |
130 |
|
int i; |
131 |
< |
|
132 |
< |
progname = argv[0]; |
131 |
> |
/* set global progname */ |
132 |
> |
fixargv0(argv[0]); |
133 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
134 |
|
switch (argv[i][1]) { |
135 |
|
case 'v': |
210 |
|
if (ourdisplay != NULL) |
211 |
|
dev_close(); |
212 |
|
/* if (rtpd.pid > 0) { */ |
213 |
< |
if (rtpd.running) { |
213 |
> |
if (rtpd.flags & PF_RUNNING) { |
214 |
|
if (close_process(&rtpd) > 0) |
215 |
|
wputs("bad exit status from rtrace\n"); |
216 |
|
/* rtpd.pid = 0; */ |
245 |
|
static char optfile[] = TEMPLATE; |
246 |
|
int nvn = 0, nvv = 0; |
247 |
|
FILE *fp; |
248 |
< |
register char *cp; |
248 |
> |
char *cp; |
249 |
|
char radcomm[256], buf[128], nam[32]; |
250 |
|
/* set rad commmand */ |
251 |
|
strcpy(radcomm, "rad -w -v 0 "); /* look out below! */ |
281 |
|
eyedist = atof(cp); |
282 |
|
/* look for materials */ |
283 |
|
while ((cp = scan4var(buf, sizeof(buf), "materials", fp)) != NULL) { |
284 |
< |
nscenef += wordstring(scene+nscenef, cp); |
284 |
> |
nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp); |
285 |
|
buf[0] = '\0'; |
286 |
|
} |
287 |
|
/* look for octree */ |
289 |
|
octree = savqstr(cp); |
290 |
|
/* look for scene files */ |
291 |
|
while ((cp = scan4var(buf, sizeof(buf), "scene", fp)) != NULL) { |
292 |
< |
nscenef += wordstring(scene+nscenef, cp); |
292 |
> |
nscenef += wordstring(scene+nscenef, MAXSCENE-nscenef, cp); |
293 |
|
buf[0] = '\0'; |
294 |
|
} |
295 |
|
/* load view names */ |
335 |
|
|
336 |
|
static int |
337 |
|
findvw( /* find named view */ |
338 |
< |
register char *nm |
338 |
> |
char *nm |
339 |
|
) |
340 |
|
{ |
341 |
< |
register int n; |
341 |
> |
int n; |
342 |
|
|
343 |
|
if ((*nm >= '1') & (*nm <= '9') && |
344 |
|
(n = atoi(nm)-1) <= MAXVIEW && vwl[n].v != NULL) |
352 |
|
|
353 |
|
static int |
354 |
|
varmatch( /* match line to variable */ |
355 |
< |
register char *s, |
356 |
< |
register char *vn |
355 |
> |
char *s, |
356 |
> |
char *vn |
357 |
|
) |
358 |
|
{ |
359 |
< |
register int c; |
359 |
> |
int c; |
360 |
|
|
361 |
|
for ( ; *vn && *s == *vn; s++, vn++) |
362 |
|
; |
379 |
|
) |
380 |
|
{ |
381 |
|
int cval; |
382 |
< |
register char *cp; |
382 |
> |
char *cp; |
383 |
|
/* search out matching line */ |
384 |
|
while ((cval = varmatch(buf, vname))) { |
385 |
|
if (cval > 0) /* gone too far? */ |
449 |
|
/* set window manager hints */ |
450 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
451 |
|
ourxwmhints.input = True; |
452 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
453 |
< |
gwind, glradicon_bits, glradicon_width, glradicon_height); |
452 |
> |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, |
453 |
> |
(char *)glradicon_bits, glradicon_width, glradicon_height); |
454 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
455 |
|
/* set GLX context */ |
456 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
501 |
|
|
502 |
|
static int |
503 |
|
dev_view( /* assign new driver view */ |
504 |
< |
register VIEW *nv |
504 |
> |
VIEW *nv |
505 |
|
) |
506 |
|
{ |
507 |
|
int newhres = hres, newvres = vres; |
539 |
|
XResizeWindow(ourdisplay, gwind, newhres, newvres); |
540 |
|
do |
541 |
|
dev_input(0); /* get resize event */ |
542 |
< |
while ((newhres != hres) | (newvres != vres)); |
542 |
> |
while ((newhres != hres) & (newvres != vres)); |
543 |
|
no_render--; |
544 |
|
} |
545 |
|
} |
584 |
|
case KeyPress: |
585 |
|
return(getkey(levptr(XKeyPressedEvent))); |
586 |
|
case ButtonPress: |
587 |
< |
getmove(levptr(XButtonPressedEvent)); |
587 |
> |
switch (levptr(XButtonPressedEvent)->button) { |
588 |
> |
case Button4: /* wheel up */ |
589 |
> |
zoomview(100+WZOOMPCT, levptr(XButtonPressedEvent)->x, |
590 |
> |
vres-1-levptr(XButtonPressedEvent)->y); |
591 |
> |
break; |
592 |
> |
case Button5: /* wheel down */ |
593 |
> |
zoomview(100-WZOOMPCT, levptr(XButtonPressedEvent)->x, |
594 |
> |
vres-1-levptr(XButtonPressedEvent)->y); |
595 |
> |
break; |
596 |
> |
default: |
597 |
> |
getmove(levptr(XButtonPressedEvent)); |
598 |
> |
break; |
599 |
> |
} |
600 |
|
break; |
601 |
|
} |
602 |
|
return(1); |
658 |
|
VSUM(nv.vp, wp, odir, -1.); |
659 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
660 |
|
} else if (orb) { /* orbit up/down */ |
661 |
< |
fcross(v1, odir, nv.vup); |
662 |
< |
if (normalize(v1) == 0.) |
661 |
> |
if (geodesic(odir, odir, nv.vup, |
662 |
> |
d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) |
663 |
|
return(0); |
652 |
– |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
664 |
|
VSUM(nv.vp, wp, odir, -1.); |
665 |
< |
spinvector(nv.vdir, nv.vdir, v1, d); |
665 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); |
666 |
|
} else if (mov) { /* move forward/backward */ |
667 |
|
d = MOVPCT/100. * mov; |
668 |
|
VSUM(nv.vp, nv.vp, odir, d); |
684 |
|
{ |
685 |
|
struct timespec ts; |
686 |
|
ts.tv_sec = 0; |
687 |
< |
ts.tv_nsec = 5000000; |
687 |
> |
ts.tv_nsec = 50000000; |
688 |
|
nanosleep(&ts, NULL); |
689 |
|
} |
690 |
|
|
740 |
|
float fbuf[6]; |
741 |
|
/* check to see if rtrace is running */ |
742 |
|
/* if (rtpd.pid <= 0) */ |
743 |
< |
if (!rtpd.running) |
743 |
> |
if (!(rtpd.flags & PF_RUNNING)) |
744 |
|
return(0); |
745 |
|
/* assign origin */ |
746 |
|
fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2]; |
748 |
|
if (md <= FTINY) md = FHUGE; |
749 |
|
fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; |
750 |
|
/* trace that ray */ |
751 |
< |
if (process(&rtpd, (char *)fbuf, (char *)fbuf, |
751 |
> |
if (process(&rtpd, fbuf, fbuf, |
752 |
|
4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) |
753 |
|
error(INTERNAL, "error getting data back from rtrace process"); |
754 |
|
if (fbuf[3] >= .99*FHUGE) |
760 |
|
|
761 |
|
static void |
762 |
|
setglpersp( /* set perspective view in GL */ |
763 |
< |
register VIEW *vp |
763 |
> |
VIEW *vp |
764 |
|
) |
765 |
|
{ |
766 |
|
double d, xmin, xmax, ymin, ymax, zmin, zmax; |
794 |
|
|
795 |
|
static int |
796 |
|
getkey( /* get input key */ |
797 |
< |
register XKeyPressedEvent *ekey |
797 |
> |
XKeyPressedEvent *ekey |
798 |
|
) |
799 |
|
{ |
800 |
|
int n; |
839 |
|
case 'V': /* append view to rad file */ |
840 |
|
appendview(NULL, &thisview); |
841 |
|
break; |
842 |
+ |
case 'Q': |
843 |
|
case 'q': /* quit the program */ |
844 |
|
return(0); |
845 |
|
default: |
944 |
|
|
945 |
|
static void |
946 |
|
fixwindow( /* repair damage to window */ |
947 |
< |
register XExposeEvent *eexp |
947 |
> |
XExposeEvent *eexp |
948 |
|
) |
949 |
|
{ |
950 |
|
if ((hres == 0) | (vres == 0)) { /* first exposure */ |
960 |
|
|
961 |
|
static void |
962 |
|
resizewindow( /* resize window */ |
963 |
< |
register XConfigureEvent *ersz |
963 |
> |
XConfigureEvent *ersz |
964 |
|
) |
965 |
|
{ |
966 |
|
static char resizing[] = "resizing window"; |