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 */ |
34 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
35 |
|
#define MOVORB(s) ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0) |
36 |
|
|
36 |
– |
#define MINWIDTH 480 /* minimum graphics window width */ |
37 |
– |
#define MINHEIGHT 400 /* minimum graphics window height */ |
38 |
– |
|
37 |
|
#define BORWIDTH 5 /* border width */ |
38 |
|
|
39 |
|
#define ourscreen DefaultScreen(ourdisplay) |
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? */ |
82 |
|
int stereo = 0; /* do stereo? */ |
83 |
|
|
84 |
|
#ifdef NOSTEREO |
85 |
< |
#define setstereobuf(bid) 0 |
85 |
> |
#define setstereobuf(bid) |
86 |
|
#else |
87 |
|
#define setstereobuf(bid) (glXWaitGL(), \ |
88 |
|
XSGISetStereoBuffer(ourdisplay, gwind, bid), \ |
91 |
|
|
92 |
|
int displist; /* our scene display list */ |
93 |
|
|
94 |
< |
int in_dev_view = 0; /* currently in dev_view() */ |
94 |
> |
int no_render = 0; /* don't rerender */ |
95 |
|
|
98 |
– |
#ifdef BSD |
99 |
– |
#define strchr index |
100 |
– |
#endif |
101 |
– |
|
102 |
– |
extern char *strchr(), *fgets(), *fgetline(), *atos(), *scan4var(); |
96 |
|
extern int nowarn; /* turn warnings off? */ |
104 |
– |
extern time_t time(); |
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); |
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); |
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); |
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); |
120 |
|
|
121 |
< |
main(argc, argv) |
122 |
< |
int argc; |
123 |
< |
char *argv[]; |
121 |
> |
|
122 |
> |
int |
123 |
> |
main( |
124 |
> |
int argc, |
125 |
> |
char *argv[] |
126 |
> |
) |
127 |
|
{ |
128 |
|
char *viewsel = NULL; |
129 |
|
long vwintvl = 0; |
162 |
|
/* run rad and get views */ |
163 |
|
runrad(argc-i, argv+i); |
164 |
|
/* check view */ |
165 |
< |
if (viewsel != NULL) |
165 |
> |
if (viewsel != NULL) { |
166 |
|
if (viewsel[0] == '-') { |
167 |
|
char *ve = viewsel; |
168 |
|
if (!sscanview(&thisview, viewsel) || |
177 |
|
progname, viewsel); |
178 |
|
quit(1); |
179 |
|
} |
180 |
+ |
} |
181 |
|
/* open GL */ |
182 |
|
dev_open(radfile = argv[i]); |
183 |
|
/* load octree or scene files */ |
184 |
|
if (octree != NULL) { |
185 |
< |
displist = rgl_octlist(octree, NULL, NULL); |
185 |
> |
displist = rgl_octlist(octree, NULL, NULL, NULL); |
186 |
|
startrtrace(octree); |
187 |
|
} else |
188 |
< |
displist = rgl_filelist(nscenef, scene); |
188 |
> |
displist = rgl_filelist(nscenef, scene, NULL); |
189 |
|
/* set initial view */ |
190 |
|
dev_view(currentview < 0 ? &thisview : vwl[currentview].v); |
191 |
|
/* input/render loop */ |
194 |
|
/* all done */ |
195 |
|
quit(0); |
196 |
|
userr: |
197 |
< |
fprintf(stderr, "Usage: %s [-w][-b][-v view] rfile [VAR=value]..\n", |
197 |
> |
fprintf(stderr, |
198 |
> |
"Usage: %s [-w][-s][-b][-S][-v view] rfile [VAR=value]..\n", |
199 |
|
argv[0]); |
200 |
|
quit(1); |
201 |
+ |
return 1; /* pro forma return */ |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
quit(code) /* exit gracefully */ |
206 |
< |
int code; |
205 |
> |
void |
206 |
> |
quit( /* exit gracefully */ |
207 |
> |
int code |
208 |
> |
) |
209 |
|
{ |
210 |
|
if (ourdisplay != NULL) |
211 |
|
dev_close(); |
212 |
< |
if (rtpd[2] > 0) { |
213 |
< |
if (close_process(rtpd) > 0) |
212 |
> |
/* if (rtpd.pid > 0) { */ |
213 |
> |
if (rtpd.running) { |
214 |
> |
if (close_process(&rtpd) > 0) |
215 |
|
wputs("bad exit status from rtrace\n"); |
216 |
< |
rtpd[2] = 0; |
216 |
> |
/* rtpd.pid = 0; */ |
217 |
|
} |
218 |
|
exit(code); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
< |
startrtrace(octname) /* start rtrace on octname */ |
223 |
< |
char *octname; |
222 |
> |
static void |
223 |
> |
startrtrace( /* start rtrace on octname */ |
224 |
> |
char *octname |
225 |
> |
) |
226 |
|
{ |
227 |
|
static char *av[12] = {"rtrace", "-h", "-fff", "-ld+", |
228 |
|
"-opL", "-x", "1"}; |
231 |
|
if (nowarn) av[ac++] = "-w-"; |
232 |
|
av[ac++] = octname; |
233 |
|
av[ac] = NULL; |
234 |
< |
if (open_process(rtpd, av) <= 0) |
234 |
> |
if (open_process(&rtpd, av) <= 0) |
235 |
|
error(SYSTEM, "cannot start rtrace process"); |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
< |
runrad(ac, av) /* run rad and load variables */ |
240 |
< |
int ac; |
241 |
< |
char **av; |
239 |
> |
static void |
240 |
> |
runrad( /* run rad and load variables */ |
241 |
> |
int ac, |
242 |
> |
char **av |
243 |
> |
) |
244 |
|
{ |
245 |
|
static char optfile[] = TEMPLATE; |
246 |
|
int nvn = 0, nvv = 0; |
247 |
|
FILE *fp; |
221 |
– |
int cval; |
248 |
|
register char *cp; |
249 |
|
char radcomm[256], buf[128], nam[32]; |
250 |
|
/* set rad commmand */ |
272 |
|
/* get exposure */ |
273 |
|
if ((cp = scan4var(buf, sizeof(buf), "EXPOSURE", fp)) != NULL) { |
274 |
|
expval = atof(cp); |
275 |
< |
if (*cp == '-' | *cp == '+') |
275 |
> |
if ((*cp == '-') | (*cp == '+')) |
276 |
|
expval = pow(2., expval); |
277 |
|
expval *= 0.5; /* compensate for local shading */ |
278 |
|
} |
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 */ |
304 |
|
do |
305 |
|
if (isview(buf)) { |
306 |
|
vwl[nvv].v = (VIEW *)bmalloc(sizeof(VIEW)); |
307 |
< |
copystruct(vwl[nvv].v, &stdview); |
307 |
> |
*(vwl[nvv].v) = stdview; |
308 |
|
sscanview(vwl[nvv].v, buf); |
309 |
|
if ((cp = setview(vwl[nvv++].v)) != NULL) { |
310 |
|
fprintf(stderr, "%s: bad view %d - %s\n", |
326 |
|
atof(sskip2(buf+4,1)), |
327 |
|
atof(sskip2(buf+4,2))); |
328 |
|
else if (backvis && !strncmp(buf, "-bv", 3) && |
329 |
< |
(!buf[3] || strchr(" 0-FfNn", buf[3]) != NULL)) |
329 |
> |
(!buf[3] || strchr("0-FfNn \n",buf[3])!=NULL)) |
330 |
|
backvis = 0; |
331 |
|
fclose(fp); |
332 |
|
unlink(optfile); /* delete options file */ |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
int |
337 |
< |
findvw(nm) /* find named view */ |
338 |
< |
register char *nm; |
336 |
> |
static int |
337 |
> |
findvw( /* find named view */ |
338 |
> |
register char *nm |
339 |
> |
) |
340 |
|
{ |
341 |
|
register int n; |
342 |
|
|
343 |
< |
if (*nm >= '1' & *nm <= '9' && |
343 |
> |
if ((*nm >= '1') & (*nm <= '9') && |
344 |
|
(n = atoi(nm)-1) <= MAXVIEW && vwl[n].v != NULL) |
345 |
|
return(n); |
346 |
|
for (n = 0; vwl[n].v != NULL; n++) |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
< |
int |
354 |
< |
varmatch(s, vn) /* match line to variable */ |
355 |
< |
register char *s, *vn; |
353 |
> |
static int |
354 |
> |
varmatch( /* match line to variable */ |
355 |
> |
register char *s, |
356 |
> |
register char *vn |
357 |
> |
) |
358 |
|
{ |
359 |
|
register int c; |
360 |
|
|
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
< |
char * |
374 |
< |
scan4var(buf, buflen, vname, fp) /* scan for variable from fp */ |
375 |
< |
char *buf; |
376 |
< |
int buflen; |
377 |
< |
char *vname; |
378 |
< |
FILE *fp; |
373 |
> |
static char * |
374 |
> |
scan4var( /* scan for variable from fp */ |
375 |
> |
char *buf, |
376 |
> |
int buflen, |
377 |
> |
char *vname, |
378 |
> |
FILE *fp |
379 |
> |
) |
380 |
|
{ |
381 |
|
int cval; |
382 |
|
register char *cp; |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
< |
dev_open(id) /* initialize GLX driver */ |
400 |
< |
char *id; |
399 |
> |
static void |
400 |
> |
dev_open( /* initialize GLX driver */ |
401 |
> |
char *id |
402 |
> |
) |
403 |
|
{ |
404 |
|
static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4, |
405 |
|
GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4, |
406 |
|
GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None}; |
407 |
|
XSetWindowAttributes ourwinattr; |
408 |
|
XWMHints ourxwmhints; |
377 |
– |
XSizeHints oursizhints; |
409 |
|
/* open display server */ |
410 |
|
ourdisplay = XOpenDisplay(NULL); |
411 |
|
if (ourdisplay == NULL) |
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); |
424 |
– |
oursizhints.min_width = MINWIDTH; |
425 |
– |
oursizhints.min_height = stereo ? MINHEIGHT/2 : MINHEIGHT; |
426 |
– |
oursizhints.flags = PMinSize; |
427 |
– |
XSetNormalHints(ourdisplay, gwind, &oursizhints); |
455 |
|
/* set GLX context */ |
456 |
|
glXMakeCurrent(ourdisplay, gwind, gctx); |
457 |
|
glEnable(GL_DEPTH_TEST); |
458 |
|
glDepthFunc(GL_LESS); |
459 |
|
glShadeModel(GL_SMOOTH); |
460 |
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
461 |
< |
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
461 |
> |
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
462 |
|
glEnable(GL_LIGHTING); |
463 |
+ |
glFrontFace(GL_CCW); |
464 |
+ |
glCullFace(GL_BACK); |
465 |
|
if (backvis) |
466 |
|
glDisable(GL_CULL_FACE); |
467 |
< |
else { |
439 |
< |
glFrontFace(GL_CCW); |
440 |
< |
glCullFace(GL_BACK); |
467 |
> |
else |
468 |
|
glEnable(GL_CULL_FACE); |
442 |
– |
} |
469 |
|
glDrawBuffer(GL_BACK); |
470 |
|
/* figure out sensible view */ |
471 |
|
pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / |
478 |
|
} |
479 |
|
/* map the window */ |
480 |
|
XMapWindow(ourdisplay, gwind); |
481 |
+ |
no_render++; |
482 |
|
do |
483 |
|
dev_input(0); /* get resize event */ |
484 |
< |
while (hres == 0 & vres == 0); |
484 |
> |
while ((hres == 0) & (vres == 0)); |
485 |
> |
no_render--; |
486 |
|
rgl_checkerr("initializing GLX"); |
487 |
|
} |
488 |
|
|
489 |
|
|
490 |
< |
dev_close() /* close our display and free resources */ |
490 |
> |
static void |
491 |
> |
dev_close(void) /* close our display and free resources */ |
492 |
|
{ |
493 |
|
glXMakeCurrent(ourdisplay, None, NULL); |
494 |
|
glXDestroyContext(ourdisplay, gctx); |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
< |
int |
503 |
< |
dev_view(nv) /* assign new driver view */ |
504 |
< |
register VIEW *nv; |
502 |
> |
static int |
503 |
> |
dev_view( /* assign new driver view */ |
504 |
> |
register VIEW *nv |
505 |
> |
) |
506 |
|
{ |
507 |
|
int newhres = hres, newvres = vres; |
508 |
|
double wa, va; |
511 |
|
error(COMMAND, "illegal view type"); |
512 |
|
nv->type = VT_PER; |
513 |
|
} |
514 |
< |
if (nv->horiz > 160. | nv->vert > 160.) { |
514 |
> |
if ((nv->horiz > 160.) | (nv->vert > 160.)) { |
515 |
|
error(COMMAND, "illegal view angle"); |
516 |
|
if (nv->horiz > 160.) |
517 |
|
nv->horiz = 160.; |
518 |
|
if (nv->vert > 160.) |
519 |
|
nv->vert = 160.; |
520 |
|
} |
521 |
< |
if (hres != 0 & vres != 0) { |
521 |
> |
if ((hres != 0) & (vres != 0)) { |
522 |
|
wa = (vres*pheight)/(hres*pwidth); |
523 |
|
va = viewaspect(nv); |
524 |
|
if (va > wa+.05) { |
534 |
|
newvres = (pwidth/pheight)*va*newhres + .5; |
535 |
|
} |
536 |
|
} |
537 |
< |
if (newhres != hres | newvres != vres) { |
538 |
< |
in_dev_view++; |
537 |
> |
if ((newhres != hres) | (newvres != vres)) { |
538 |
> |
no_render++; |
539 |
|
XResizeWindow(ourdisplay, gwind, newhres, newvres); |
540 |
|
do |
541 |
|
dev_input(0); /* get resize event */ |
542 |
< |
while (newhres != hres | newvres != vres); |
543 |
< |
in_dev_view--; |
542 |
> |
while ((newhres != hres) | (newvres != vres)); |
543 |
> |
no_render--; |
544 |
|
} |
545 |
|
} |
546 |
< |
copystruct(&thisview, nv); |
546 |
> |
thisview = *nv; |
547 |
|
setglpersp(&thisview); |
548 |
|
render(); |
549 |
|
return(1); |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
< |
int |
554 |
< |
dev_input(nsecs) /* get next input event */ |
555 |
< |
int nsecs; |
553 |
> |
static int |
554 |
> |
dev_input( /* get next input event */ |
555 |
> |
int nsecs |
556 |
> |
) |
557 |
|
{ |
558 |
|
#if 0 |
559 |
|
static time_t lasttime = 0; |
591 |
|
} |
592 |
|
|
593 |
|
|
594 |
< |
render() /* render our display list and swap buffers */ |
594 |
> |
static void |
595 |
> |
render(void) /* render our display list and swap buffers */ |
596 |
|
{ |
597 |
|
double d; |
598 |
|
|
599 |
< |
if (!mapped) |
599 |
> |
if (!mapped | no_render) |
600 |
|
return; |
601 |
|
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
602 |
|
glCallList(displist); |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
< |
moveview(dx, dy, mov, orb) /* move our view */ |
622 |
< |
int dx, dy, mov, orb; |
621 |
> |
static int |
622 |
> |
moveview( /* move our view */ |
623 |
> |
int dx, |
624 |
> |
int dy, |
625 |
> |
int mov, |
626 |
> |
int orb |
627 |
> |
) |
628 |
|
{ |
629 |
|
VIEW nv; |
630 |
|
FVECT odir, v1, wp; |
631 |
|
double d; |
595 |
– |
register int li; |
632 |
|
/* start with old view */ |
633 |
< |
copystruct(&nv, &thisview); |
633 |
> |
nv = thisview; |
634 |
|
/* change view direction */ |
635 |
|
if ((d = viewray(v1, odir, &thisview, |
636 |
|
(dx+.5)/hres, (dy+.5)/vres)) < -FTINY) |
646 |
|
VSUM(nv.vp, wp, odir, -1.); |
647 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
648 |
|
} else if (orb) { /* orbit up/down */ |
649 |
< |
fcross(v1, odir, nv.vup); |
650 |
< |
if (normalize(v1) == 0.) |
649 |
> |
if (geodesic(odir, odir, nv.vup, |
650 |
> |
d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) |
651 |
|
return(0); |
616 |
– |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
652 |
|
VSUM(nv.vp, wp, odir, -1.); |
653 |
< |
spinvector(nv.vdir, nv.vdir, v1, d); |
653 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); |
654 |
|
} else if (mov) { /* move forward/backward */ |
655 |
|
d = MOVPCT/100. * mov; |
656 |
|
VSUM(nv.vp, nv.vp, odir, d); |
667 |
|
} |
668 |
|
|
669 |
|
|
670 |
< |
getmove(ebut) /* get view change */ |
671 |
< |
XButtonPressedEvent *ebut; |
670 |
> |
static void |
671 |
> |
waitabit(void) /* pause a moment */ |
672 |
|
{ |
673 |
+ |
struct timespec ts; |
674 |
+ |
ts.tv_sec = 0; |
675 |
+ |
ts.tv_nsec = 50000000; |
676 |
+ |
nanosleep(&ts, NULL); |
677 |
+ |
} |
678 |
+ |
|
679 |
+ |
|
680 |
+ |
static void |
681 |
+ |
getmove( /* get view change */ |
682 |
+ |
XButtonPressedEvent *ebut |
683 |
+ |
) |
684 |
+ |
{ |
685 |
|
int movdir = MOVDIR(ebut->button); |
686 |
|
int movorb = MOVORB(ebut->state); |
687 |
|
int moved = 0; |
695 |
|
|
696 |
|
while (!XCheckMaskEvent(ourdisplay, |
697 |
|
ButtonReleaseMask, levptr(XEvent))) { |
698 |
+ |
/* pause so as not to move too fast */ |
699 |
+ |
waitabit(); |
700 |
|
|
701 |
|
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
702 |
|
&rootx, &rooty, &wx, &wy, &statemask)) |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
< |
getintersect(wp, org, dir, md) /* intersect ray with scene geometry */ |
721 |
< |
FVECT wp; /* returned world intersection point */ |
722 |
< |
FVECT org, dir; |
723 |
< |
double md; |
720 |
> |
static int |
721 |
> |
getintersect( /* intersect ray with scene geometry */ |
722 |
> |
FVECT wp, /* returned world intersection point */ |
723 |
> |
FVECT org, |
724 |
> |
FVECT dir, |
725 |
> |
double md |
726 |
> |
) |
727 |
|
{ |
728 |
|
float fbuf[6]; |
729 |
|
/* check to see if rtrace is running */ |
730 |
< |
if (rtpd[2] <= 0) |
730 |
> |
/* if (rtpd.pid <= 0) */ |
731 |
> |
if (!rtpd.running) |
732 |
|
return(0); |
733 |
|
/* assign origin */ |
734 |
|
fbuf[0] = org[0]; fbuf[1] = org[1]; fbuf[2] = org[2]; |
736 |
|
if (md <= FTINY) md = FHUGE; |
737 |
|
fbuf[3] = dir[0]*md; fbuf[4] = dir[1]*md; fbuf[5] = dir[2]*md; |
738 |
|
/* trace that ray */ |
739 |
< |
if (process(rtpd, fbuf, fbuf, 4*sizeof(float), 6*sizeof(float)) != |
740 |
< |
4*sizeof(float)) |
739 |
> |
if (process(&rtpd, (char *)fbuf, (char *)fbuf, |
740 |
> |
4*sizeof(float), 6*sizeof(float)) != 4*sizeof(float)) |
741 |
|
error(INTERNAL, "error getting data back from rtrace process"); |
742 |
|
if (fbuf[3] >= .99*FHUGE) |
743 |
|
return(0); /* missed local objects */ |
746 |
|
} |
747 |
|
|
748 |
|
|
749 |
< |
setglpersp(vp) /* set perspective view in GL */ |
750 |
< |
register VIEW *vp; |
749 |
> |
static void |
750 |
> |
setglpersp( /* set perspective view in GL */ |
751 |
> |
register VIEW *vp |
752 |
> |
) |
753 |
|
{ |
754 |
|
double d, xmin, xmax, ymin, ymax, zmin, zmax; |
755 |
|
|
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
< |
int |
784 |
< |
getkey(ekey) /* get input key */ |
785 |
< |
register XKeyPressedEvent *ekey; |
783 |
> |
static int |
784 |
> |
getkey( /* get input key */ |
785 |
> |
register XKeyPressedEvent *ekey |
786 |
> |
) |
787 |
|
{ |
788 |
|
int n; |
789 |
|
char buf[8]; |
801 |
|
case 'l': /* retrieve last (premouse) view */ |
802 |
|
if (lastview.type) { |
803 |
|
VIEW vtmp; |
804 |
< |
copystruct(&vtmp, &thisview); |
804 |
> |
vtmp = thisview; |
805 |
|
dev_view(&lastview); |
806 |
< |
copystruct(&lastview, &vtmp); |
806 |
> |
lastview = vtmp; |
807 |
|
} else |
808 |
|
XBell(ourdisplay, 0); |
809 |
|
break; |
837 |
|
} |
838 |
|
|
839 |
|
|
840 |
< |
zoomview(pct, dx, dy) /* zoom in or out around (dx,dy) */ |
841 |
< |
int pct; |
842 |
< |
int dx, dy; |
840 |
> |
static void |
841 |
> |
zoomview( /* zoom in or out around (dx,dy) */ |
842 |
> |
int pct, |
843 |
> |
int dx, |
844 |
> |
int dy |
845 |
> |
) |
846 |
|
{ |
847 |
|
double h, v; |
789 |
– |
FVECT direc; |
848 |
|
|
849 |
< |
if (pct == 100 | pct <= 0) |
849 |
> |
if ((pct == 100) | (pct <= 0)) |
850 |
|
return; |
851 |
|
copylastv("zooming"); |
852 |
|
h = (dx+.5)/hres - 0.5; |
865 |
|
} |
866 |
|
|
867 |
|
|
868 |
< |
gotoview(vwnum) /* go to specified view number */ |
869 |
< |
int vwnum; |
868 |
> |
static void |
869 |
> |
gotoview( /* go to specified view number */ |
870 |
> |
int vwnum |
871 |
> |
) |
872 |
|
{ |
873 |
|
if (vwnum < 0) |
874 |
|
for (vwnum = currentview; vwl[vwnum+1].v != NULL; vwnum++) |
875 |
|
; |
876 |
|
else if (vwnum >= MAXVIEW || vwl[vwnum].v == NULL) |
877 |
|
vwnum = 0; |
818 |
– |
if (vwnum == currentview) |
819 |
– |
return; |
878 |
|
copylastv("standard view"); |
879 |
|
dev_view(vwl[currentview=vwnum].v); |
880 |
|
} |
881 |
|
|
882 |
|
|
883 |
< |
appendview(nm, vp) /* append standard view */ |
884 |
< |
char *nm; |
885 |
< |
VIEW *vp; |
883 |
> |
static void |
884 |
> |
appendview( /* append standard view */ |
885 |
> |
char *nm, |
886 |
> |
VIEW *vp |
887 |
> |
) |
888 |
|
{ |
889 |
|
FILE *fp; |
890 |
|
/* check if already in there */ |
891 |
< |
if (!bcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { |
891 |
> |
if (!memcmp(&thisview, vwl[currentview].v, sizeof(VIEW))) { |
892 |
|
error(COMMAND, "view already in standard list"); |
893 |
|
return; |
894 |
|
} |
909 |
|
if (currentview >= MAXVIEW) |
910 |
|
error(INTERNAL, "too many views in appendview"); |
911 |
|
vwl[currentview].v = (VIEW *)bmalloc(sizeof(VIEW)); |
912 |
< |
copystruct(vwl[currentview].v, &thisview); |
912 |
> |
*(vwl[currentview].v) = thisview; |
913 |
|
if (nm != NULL) |
914 |
|
vwl[currentview].nam = savqstr(nm); |
915 |
|
} |
916 |
|
|
917 |
|
|
918 |
< |
copylastv(cause) /* copy last view position */ |
919 |
< |
char *cause; |
918 |
> |
static void |
919 |
> |
copylastv( /* copy last view position */ |
920 |
> |
char *cause |
921 |
> |
) |
922 |
|
{ |
923 |
|
static char *lastvc; |
924 |
|
|
925 |
|
if (cause == lastvc) |
926 |
|
return; /* only record one view per cause */ |
927 |
|
lastvc = cause; |
928 |
< |
copystruct(&lastview, &thisview); |
928 |
> |
lastview = thisview; |
929 |
|
} |
930 |
|
|
931 |
|
|
932 |
< |
fixwindow(eexp) /* repair damage to window */ |
933 |
< |
register XExposeEvent *eexp; |
932 |
> |
static void |
933 |
> |
fixwindow( /* repair damage to window */ |
934 |
> |
register XExposeEvent *eexp |
935 |
> |
) |
936 |
|
{ |
937 |
< |
if (hres == 0 | vres == 0) { /* first exposure */ |
937 |
> |
if ((hres == 0) | (vres == 0)) { /* first exposure */ |
938 |
|
resizewindow((XConfigureEvent *)eexp); |
939 |
|
return; |
940 |
|
} |
945 |
|
} |
946 |
|
|
947 |
|
|
948 |
< |
resizewindow(ersz) /* resize window */ |
949 |
< |
register XConfigureEvent *ersz; |
948 |
> |
static void |
949 |
> |
resizewindow( /* resize window */ |
950 |
> |
register XConfigureEvent *ersz |
951 |
> |
) |
952 |
|
{ |
953 |
|
static char resizing[] = "resizing window"; |
954 |
|
double wa, va; |
956 |
|
glViewport(0, 0, hres=ersz->width, vres=ersz->height); |
957 |
|
if (hres > maxhres) maxhres = hres; |
958 |
|
if (vres > maxvres) maxvres = vres; |
959 |
< |
if (in_dev_view) |
959 |
> |
if (no_render) |
960 |
|
return; |
961 |
|
wa = (vres*pheight)/(hres*pwidth); |
962 |
|
va = viewaspect(&thisview); |