| 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 */ |
| 75 |
|
int nscenef = 0; /* number of scene files */ |
| 76 |
|
char *octree; /* octree name (NULL if unnec.) */ |
| 77 |
|
|
| 78 |
< |
int rtpd[3]; /* rtrace process descriptors */ |
| 78 |
> |
SUBPROC rtpd; /* rtrace process descriptors */ |
| 79 |
|
|
| 80 |
|
int silent = 0; /* run rad silently? */ |
| 81 |
|
int backvis = 1; /* back faces visible? */ |
| 93 |
|
|
| 94 |
|
int no_render = 0; /* don't rerender */ |
| 95 |
|
|
| 96 |
< |
#ifdef BSD |
| 96 |
< |
#define strchr index |
| 97 |
< |
#endif |
| 98 |
< |
|
| 99 |
< |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
| 96 |
> |
extern char *fgetline(), *atos(), *scan4var(); |
| 97 |
|
extern int nowarn; /* turn warnings off? */ |
| 101 |
– |
extern time_t time(); |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
main(argc, argv) |
| 138 |
|
/* run rad and get views */ |
| 139 |
|
runrad(argc-i, argv+i); |
| 140 |
|
/* check view */ |
| 141 |
< |
if (viewsel != NULL) |
| 141 |
> |
if (viewsel != NULL) { |
| 142 |
|
if (viewsel[0] == '-') { |
| 143 |
|
char *ve = viewsel; |
| 144 |
|
if (!sscanview(&thisview, viewsel) || |
| 153 |
|
progname, viewsel); |
| 154 |
|
quit(1); |
| 155 |
|
} |
| 156 |
+ |
} |
| 157 |
|
/* open GL */ |
| 158 |
|
dev_open(radfile = argv[i]); |
| 159 |
|
/* load octree or scene files */ |
| 160 |
|
if (octree != NULL) { |
| 161 |
< |
displist = rgl_octlist(octree, NULL, NULL); |
| 161 |
> |
displist = rgl_octlist(octree, NULL, NULL, NULL); |
| 162 |
|
startrtrace(octree); |
| 163 |
|
} else |
| 164 |
< |
displist = rgl_filelist(nscenef, scene); |
| 164 |
> |
displist = rgl_filelist(nscenef, scene, NULL); |
| 165 |
|
/* set initial view */ |
| 166 |
|
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
| 167 |
|
/* input/render loop */ |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
+ |
void |
| 181 |
|
quit(code) /* exit gracefully */ |
| 182 |
|
int code; |
| 183 |
|
{ |
| 184 |
|
if (ourdisplay != NULL) |
| 185 |
|
dev_close(); |
| 186 |
< |
if (rtpd[2] > 0) { |
| 187 |
< |
if (close_process(rtpd) > 0) |
| 186 |
> |
/* if (rtpd.pid > 0) { */ |
| 187 |
> |
if (rtpd.running) { |
| 188 |
> |
if (close_process(&rtpd) > 0) |
| 189 |
|
wputs("bad exit status from rtrace\n"); |
| 190 |
< |
rtpd[2] = 0; |
| 190 |
> |
/* rtpd.pid = 0; */ |
| 191 |
|
} |
| 192 |
|
exit(code); |
| 193 |
|
} |
| 203 |
|
if (nowarn) av[ac++] = "-w-"; |
| 204 |
|
av[ac++] = octname; |
| 205 |
|
av[ac] = NULL; |
| 206 |
< |
if (open_process(rtpd, av) <= 0) |
| 206 |
> |
if (open_process(&rtpd, av) <= 0) |
| 207 |
|
error(SYSTEM, "cannot start rtrace process"); |
| 208 |
|
} |
| 209 |
|
|
| 275 |
|
do |
| 276 |
|
if (isview(buf)) { |
| 277 |
|
vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW)); |
| 278 |
< |
copystruct(vwl[nvv].v, &stdview); |
| 278 |
> |
*(vwl[nvv].v) = stdview; |
| 279 |
|
sscanview(vwl[nvv].v, buf); |
| 280 |
|
if ((cp = setview(vwl[nvv++].v)) != NULL) { |
| 281 |
|
fprintf(stderr, "%s: bad view %d - %s\n", |
| 506 |
|
no_render--; |
| 507 |
|
} |
| 508 |
|
} |
| 509 |
< |
copystruct(&thisview, nv); |
| 509 |
> |
thisview = *nv; |
| 510 |
|
setglpersp(&thisview); |
| 511 |
|
render(); |
| 512 |
|
return(1); |
| 585 |
|
VIEW nv; |
| 586 |
|
FVECT odir, v1, wp; |
| 587 |
|
double d; |
| 589 |
– |
register int li; |
| 588 |
|
/* start with old view */ |
| 589 |
< |
copystruct(&nv, &thisview); |
| 589 |
> |
nv = thisview; |
| 590 |
|
/* change view direction */ |
| 591 |
|
if ((d = viewray(v1, odir, &thisview, |
| 592 |
|
(dx+.5)/hres, (dy+.5)/vres)) < -FTINY) |
| 624 |
|
} |
| 625 |
|
|
| 626 |
|
|
| 627 |
+ |
static |
| 628 |
+ |
waitabit() /* pause a moment */ |
| 629 |
+ |
{ |
| 630 |
+ |
struct timespec ts; |
| 631 |
+ |
ts.tv_sec = 0; |
| 632 |
+ |
ts.tv_nsec = 5000000; |
| 633 |
+ |
nanosleep(&ts, NULL); |
| 634 |
+ |
} |
| 635 |
+ |
|
| 636 |
+ |
|
| 637 |
|
getmove(ebut) /* get view change */ |
| 638 |
|
XButtonPressedEvent *ebut; |
| 639 |
|
{ |
| 650 |
|
|
| 651 |
|
while (!XCheckMaskEvent(ourdisplay, |
| 652 |
|
ButtonReleaseMask, levptr(XEvent))) { |
| 653 |
+ |
/* pause so as not to move too fast */ |
| 654 |
+ |
waitabit(); |
| 655 |
|
|
| 656 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
| 657 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
| 679 |
|
{ |
| 680 |
|
float fbuf[6]; |
| 681 |
|
/* check to see if rtrace is running */ |
| 682 |
< |
if (rtpd[2] <= 0) |
| 682 |
> |
/* if (rtpd.pid <= 0) */ |
| 683 |
> |
if (!rtpd.running) |
| 684 |
|
return(0); |
| 685 |
|
/* assign origin */ |
| 686 |
|
fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2]; |
| 688 |
|
if (md <= FTINY) md = FHUGE; |
| 689 |
|
fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; |
| 690 |
|
/* trace that ray */ |
| 691 |
< |
if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) != |
| 692 |
< |
4*sizeof(float)) |
| 691 |
> |
if (process(&rtpd, (char *)fbuf, (char *)fbuf, |
| 692 |
> |
4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) |
| 693 |
|
error(INTERNAL, "error getting data back from rtrace process"); |
| 694 |
|
if (fbuf[3] >= .99*FHUGE) |
| 695 |
|
return(0); /* missed local objects */ |
| 750 |
|
case 'l': /* retrieve last (premouse) view */ |
| 751 |
|
if (lastview.type) { |
| 752 |
|
VIEW vtmp; |
| 753 |
< |
copystruct(&vtmp, &thisview); |
| 753 |
> |
vtmp = thisview; |
| 754 |
|
dev_view(&lastview); |
| 755 |
< |
copystruct(&lastview, &vtmp); |
| 755 |
> |
lastview = vtmp; |
| 756 |
|
} else |
| 757 |
|
XBell(ourdisplay, 0); |
| 758 |
|
break; |
| 831 |
|
{ |
| 832 |
|
FILE *fp; |
| 833 |
|
/* check if already in there */ |
| 834 |
< |
if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { |
| 834 |
> |
if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { |
| 835 |
|
error(COMMAND, "view already in standard list"); |
| 836 |
|
return; |
| 837 |
|
} |
| 852 |
|
if (currentview >= MAXVIEW) |
| 853 |
|
error(INTERNAL, "too many views in appendview"); |
| 854 |
|
vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW)); |
| 855 |
< |
copystruct(vwl[currentview].v, &thisview); |
| 855 |
> |
*(vwl[currentview].v) = thisview; |
| 856 |
|
if (nm != NULL) |
| 857 |
|
vwl[currentview].nam = savqstr(nm); |
| 858 |
|
} |
| 866 |
|
if (cause == lastvc) |
| 867 |
|
return; /* only record one view per cause */ |
| 868 |
|
lastvc = cause; |
| 869 |
< |
copystruct(&lastview, &thisview); |
| 869 |
> |
lastview = thisview; |
| 870 |
|
} |
| 871 |
|
|
| 872 |
|
|