6 |
|
* Based on rview driver. |
7 |
|
*/ |
8 |
|
|
9 |
< |
#include "standard.h" |
9 |
> |
#include <stdlib.h> |
10 |
> |
#include <stdio.h> |
11 |
|
#include <X11/Xlib.h> |
12 |
|
#include <X11/cursorfont.h> |
13 |
|
#include <X11/Xutil.h> |
14 |
|
#include <time.h> |
15 |
+ |
|
16 |
+ |
#include "platform.h" |
17 |
+ |
#include "rtmath.h" |
18 |
+ |
#include "rterror.h" |
19 |
+ |
#include "plocate.h" |
20 |
+ |
#include "rhdisp.h" |
21 |
|
#include "rhd_qtree.h" |
22 |
< |
#include "x11icon.h" |
22 |
> |
#include "x11icon.h" |
23 |
|
|
24 |
|
#ifndef RAYQLEN |
25 |
|
#define RAYQLEN 50000 /* max. rays to queue before flush */ |
26 |
|
#endif |
27 |
|
|
21 |
– |
#ifndef FEQ |
22 |
– |
#define FEQ(a,b) ((a)-(b) <= FTINY && (a)-(b) >= -FTINY) |
23 |
– |
#endif |
24 |
– |
|
28 |
|
#define GAMMA 2.2 /* default gamma correction */ |
29 |
|
|
30 |
|
#define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) |
50 |
|
|
51 |
|
struct driver odev; /* global device driver structure */ |
52 |
|
|
53 |
+ |
TMstruct *tmGlobal; /* global tone-mapping structure */ |
54 |
+ |
|
55 |
|
char odev_args[64]; /* command arguments */ |
56 |
|
|
57 |
|
static XEvent currentevent; /* current event */ |
73 |
|
|
74 |
|
static int headlocked = 0; /* lock vertical motion */ |
75 |
|
|
71 |
– |
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), getframe(), |
72 |
– |
getevent(), getkey(), moveview(), getmove(), fixwindow(); |
73 |
– |
static unsigned long true_pixel(); |
76 |
|
|
77 |
+ |
static int mytmflags(void); |
78 |
+ |
static void xnewcolr(int ndx, int r, int g, int b); |
79 |
+ |
static int getpixels(void); |
80 |
+ |
static void freepixels(void); |
81 |
+ |
static unsigned long true_pixel(uby8 rgb[3]); |
82 |
+ |
static void getevent(void); |
83 |
+ |
static int ilclip(int dp[2][2], FVECT wp[2]); |
84 |
+ |
static void draw3dline(FVECT wp[2]); |
85 |
+ |
static void draw_grids(void); |
86 |
+ |
static int moveview(int dx, int dy, int mov, int orb); |
87 |
+ |
static void getframe(XButtonPressedEvent *ebut); |
88 |
+ |
static void waitabit(void); |
89 |
+ |
static void getmove(XButtonPressedEvent *ebut); |
90 |
+ |
static void getkey(XKeyPressedEvent *ekey); |
91 |
+ |
static void fixwindow(XExposeEvent *eexp); |
92 |
+ |
static void resizewindow(XConfigureEvent *ersz); |
93 |
|
|
94 |
+ |
|
95 |
|
static int |
96 |
< |
mytmflags() /* figure out tone mapping flags */ |
96 |
> |
mytmflags(void) /* figure out tone mapping flags */ |
97 |
|
{ |
98 |
|
extern char *progname; |
99 |
< |
register char *cp, *tail; |
99 |
> |
char *cp, *tail; |
100 |
|
/* find basic name */ |
101 |
|
for (cp = tail = progname; *cp; cp++) |
102 |
|
if (*cp == '/') |
108 |
|
if (cp-tail == 4 && !strncmp(tail, "x11h", 4)) |
109 |
|
return(TM_F_HUMAN|TM_F_NOSTDERR); |
110 |
|
error(USER, "illegal driver name"); |
111 |
+ |
return 0; /* pro forma return */ |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
< |
dev_open(id) /* initialize X11 driver */ |
116 |
< |
char *id; |
115 |
> |
void |
116 |
> |
dev_open( /* initialize X11 driver */ |
117 |
> |
char *id |
118 |
> |
) |
119 |
|
{ |
98 |
– |
extern char *getenv(); |
120 |
|
static RGBPRIMS myprims = STDPRIMS; |
121 |
|
char *ev; |
122 |
|
double gamval = GAMMA; |
163 |
|
&myprims[BLU][CIEX],&myprims[BLU][CIEY], |
164 |
|
&myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) |
165 |
|
dpri = myprims; |
166 |
< |
if (tmInit(mytmflags(), dpri, gamval) == NULL) |
166 |
> |
tmGlobal = tmInit(mytmflags(), dpri, gamval); |
167 |
> |
if (tmGlobal == NULL) |
168 |
|
error(SYSTEM, "not enough memory in dev_open"); |
169 |
|
/* open window */ |
170 |
|
ourwinattr.background_pixel = ourblack; |
186 |
|
/* set window manager hints */ |
187 |
|
ourxwmhints.flags = InputHint|IconPixmapHint; |
188 |
|
ourxwmhints.input = True; |
189 |
< |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, |
190 |
< |
gwind, x11icon_bits, x11icon_width, x11icon_height); |
189 |
> |
ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, |
190 |
> |
(char *)x11icon_bits, x11icon_width, x11icon_height); |
191 |
|
XSetWMHints(ourdisplay, gwind, &ourxwmhints); |
192 |
|
oursizhints.min_width = MINWIDTH; |
193 |
|
oursizhints.min_height = MINHEIGHT; |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
< |
dev_close() /* close our display */ |
216 |
> |
void |
217 |
> |
dev_close(void) /* close our display */ |
218 |
|
{ |
219 |
|
freepixels(); |
220 |
|
XFreeGC(ourdisplay, ourgc); |
224 |
|
XCloseDisplay(ourdisplay); |
225 |
|
ourdisplay = NULL; |
226 |
|
qtFreeLeaves(); |
227 |
< |
tmDone(NULL); |
227 |
> |
tmDone(tmGlobal); |
228 |
|
odev.v.type = 0; |
229 |
|
odev.hres = odev.vres = 0; |
230 |
|
odev.ifd = -1; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
< |
|
235 |
< |
dev_clear() /* clear our quadtree */ |
234 |
> |
void |
235 |
> |
dev_clear(void) /* clear our quadtree */ |
236 |
|
{ |
237 |
|
qtCompost(100); |
238 |
|
if (ncolors > 0) |
242 |
|
|
243 |
|
|
244 |
|
int |
245 |
< |
dev_view(nv) /* assign new driver view */ |
246 |
< |
VIEW *nv; |
245 |
> |
dev_view( /* assign new driver view */ |
246 |
> |
VIEW *nv |
247 |
> |
) |
248 |
|
{ |
249 |
|
if (nv->type == VT_PAR || /* check view legality */ |
250 |
|
nv->horiz > 160. || nv->vert > 160.) { |
260 |
|
return(0); |
261 |
|
} |
262 |
|
if (nv != &odev.v) { |
263 |
< |
if (!FEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
264 |
< |
!FEQ(nv->vert,odev.v.vert)) { |
263 |
> |
if (!FABSEQ(nv->horiz,odev.v.horiz) || /* resize window? */ |
264 |
> |
!FABSEQ(nv->vert,odev.v.vert)) { |
265 |
|
int dw = DisplayWidth(ourdisplay,ourscreen); |
266 |
|
int dh = DisplayHeight(ourdisplay,ourscreen); |
267 |
|
|
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
< |
dev_section(ofn) /* add octree for geometry rendering */ |
293 |
< |
char *ofn; |
292 |
> |
void |
293 |
> |
dev_section( /* add octree for geometry rendering */ |
294 |
> |
char *gfn, |
295 |
> |
char *pfn |
296 |
> |
) |
297 |
|
{ |
298 |
|
/* unimplemented */ |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
< |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
303 |
< |
char *cmd, *args; |
302 |
> |
void |
303 |
> |
dev_auxcom( /* process an auxiliary command */ |
304 |
> |
char *cmd, |
305 |
> |
char *args |
306 |
> |
) |
307 |
|
{ |
308 |
|
sprintf(errmsg, "%s: unknown command", cmd); |
309 |
|
error(COMMAND, errmsg); |
311 |
|
|
312 |
|
|
313 |
|
VIEW * |
314 |
< |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
315 |
< |
int n; |
316 |
< |
int hvres[2]; |
314 |
> |
dev_auxview( /* return nth auxiliary view */ |
315 |
> |
int n, |
316 |
> |
int hvres[2] |
317 |
> |
) |
318 |
|
{ |
319 |
|
if (n) |
320 |
|
return(NULL); |
324 |
|
|
325 |
|
|
326 |
|
int |
327 |
< |
dev_input() /* get X11 input */ |
327 |
> |
dev_input(void) /* get X11 input */ |
328 |
|
{ |
329 |
|
inpresflags = 0; |
330 |
|
|
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
< |
dev_paintr(rgb, xmin, ymin, xmax, ymax) /* fill a rectangle */ |
343 |
< |
BYTE rgb[3]; |
344 |
< |
int xmin, ymin, xmax, ymax; |
342 |
> |
void |
343 |
> |
dev_paintr( /* fill a rectangle */ |
344 |
> |
uby8 rgb[3], |
345 |
> |
int xmin, |
346 |
> |
int ymin, |
347 |
> |
int xmax, |
348 |
> |
int ymax |
349 |
> |
) |
350 |
|
{ |
351 |
|
unsigned long pixel; |
352 |
|
|
363 |
|
|
364 |
|
|
365 |
|
int |
366 |
< |
dev_flush() /* flush output */ |
366 |
> |
dev_flush(void) /* flush output */ |
367 |
|
{ |
368 |
|
qtUpdate(); |
369 |
|
rayqleft = RAYQLEN; |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
< |
static |
375 |
< |
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ |
376 |
< |
int ndx; |
377 |
< |
int r, g, b; |
374 |
> |
static void |
375 |
> |
xnewcolr( /* enter a color into hardware table */ |
376 |
> |
int ndx, |
377 |
> |
int r, |
378 |
> |
int g, |
379 |
> |
int b |
380 |
> |
) |
381 |
|
{ |
382 |
|
XColor xcolor; |
383 |
|
|
392 |
|
|
393 |
|
|
394 |
|
static int |
395 |
< |
getpixels() /* get the color map */ |
395 |
> |
getpixels(void) /* get the color map */ |
396 |
|
{ |
397 |
|
XColor thiscolor; |
398 |
< |
register int i, j; |
398 |
> |
int i, j; |
399 |
|
|
400 |
|
if (ncolors > 0) |
401 |
|
return(ncolors); |
443 |
|
} |
444 |
|
|
445 |
|
|
446 |
< |
static |
447 |
< |
freepixels() /* free our pixels */ |
446 |
> |
static void |
447 |
> |
freepixels(void) /* free our pixels */ |
448 |
|
{ |
449 |
|
if (ncolors == 0) |
450 |
|
return; |
459 |
|
|
460 |
|
|
461 |
|
static unsigned long |
462 |
< |
true_pixel(rgb) /* return true pixel value for color */ |
463 |
< |
register BYTE rgb[3]; |
462 |
> |
true_pixel( /* return true pixel value for color */ |
463 |
> |
uby8 rgb[3] |
464 |
> |
) |
465 |
|
{ |
466 |
< |
register unsigned long rval; |
466 |
> |
unsigned long rval; |
467 |
|
|
468 |
|
rval = ourvinfo.red_mask*rgb[RED]/255 & ourvinfo.red_mask; |
469 |
|
rval |= ourvinfo.green_mask*rgb[GRN]/255 & ourvinfo.green_mask; |
472 |
|
} |
473 |
|
|
474 |
|
|
475 |
< |
static |
476 |
< |
getevent() /* get next event */ |
475 |
> |
static void |
476 |
> |
getevent(void) /* get next event */ |
477 |
|
{ |
478 |
|
XNextEvent(ourdisplay, levptr(XEvent)); |
479 |
|
switch (levptr(XEvent)->type) { |
502 |
|
case ButtonPress: |
503 |
|
if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) |
504 |
|
getframe(levptr(XButtonPressedEvent)); |
505 |
< |
else |
506 |
< |
getmove(levptr(XButtonPressedEvent)); |
505 |
> |
else |
506 |
> |
switch (levptr(XButtonPressedEvent)->button) { |
507 |
> |
case Button4: /* wheel up */ |
508 |
> |
case Button5: /* wheel down */ |
509 |
> |
break; |
510 |
> |
default: |
511 |
> |
getmove(levptr(XButtonPressedEvent)); |
512 |
> |
break; |
513 |
> |
} |
514 |
|
break; |
515 |
|
} |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
< |
static |
520 |
< |
ilclip(dp, wp) /* clip world coordinates to device */ |
521 |
< |
int dp[2][2]; |
522 |
< |
FVECT wp[2]; |
519 |
> |
static int |
520 |
> |
ilclip( /* clip world coordinates to device */ |
521 |
> |
int dp[2][2], |
522 |
> |
FVECT wp[2] |
523 |
> |
) |
524 |
|
{ |
525 |
|
static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE}; |
526 |
|
FVECT wpc[2], ip[2]; |
555 |
|
} |
556 |
|
|
557 |
|
|
558 |
< |
static |
559 |
< |
draw3dline(wp) /* draw 3d line in world coordinates */ |
560 |
< |
FVECT wp[2]; |
558 |
> |
static void |
559 |
> |
draw3dline( /* draw 3d line in world coordinates */ |
560 |
> |
FVECT wp[2] |
561 |
> |
) |
562 |
|
{ |
563 |
|
int dp[2][2]; |
564 |
|
|
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
< |
static |
574 |
< |
draw_grids() /* draw holodeck section grids */ |
573 |
> |
static void |
574 |
> |
draw_grids(void) /* draw holodeck section grids */ |
575 |
|
{ |
576 |
< |
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
576 |
> |
static uby8 gridrgb[3] = {0x0, 0xff, 0xff}; |
577 |
|
unsigned long pixel; |
578 |
|
|
579 |
|
if (ncolors > 0) |
586 |
|
} |
587 |
|
|
588 |
|
|
589 |
< |
static |
590 |
< |
moveview(dx, dy, mov, orb) /* move our view */ |
591 |
< |
int dx, dy, mov, orb; |
589 |
> |
static int |
590 |
> |
moveview( /* move our view */ |
591 |
> |
int dx, |
592 |
> |
int dy, |
593 |
> |
int mov, |
594 |
> |
int orb |
595 |
> |
) |
596 |
|
{ |
597 |
|
VIEW nv; |
598 |
|
FVECT odir, v1; |
599 |
|
double d; |
600 |
< |
register int li; |
600 |
> |
int li; |
601 |
|
/* start with old view */ |
602 |
|
nv = odev.v; |
603 |
|
/* change view direction */ |
615 |
|
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
616 |
|
spinvector(nv.vdir, nv.vdir, nv.vup, d); |
617 |
|
} else if (orb) { /* orbit up/down */ |
618 |
< |
fcross(v1, odir, nv.vup); |
619 |
< |
if (normalize(v1) == 0.) |
618 |
> |
if (geodesic(odir, odir, nv.vup, |
619 |
> |
d=MOVDEG*PI/180.*orb, GEOD_RAD) == 0.0) |
620 |
|
return(0); |
568 |
– |
spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb); |
621 |
|
VSUM(nv.vp, qtL.wp[li], odir, -1.); |
622 |
< |
spinvector(nv.vdir, nv.vdir, v1, d); |
622 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, d, GEOD_RAD); |
623 |
|
} else if (mov) { /* move forward/backward */ |
624 |
|
d = MOVPCT/100. * mov; |
625 |
|
VSUM(nv.vp, nv.vp, odir, d); |
637 |
|
} |
638 |
|
|
639 |
|
|
640 |
< |
static |
641 |
< |
getframe(ebut) /* get focus frame */ |
642 |
< |
XButtonPressedEvent *ebut; |
640 |
> |
static void |
641 |
> |
getframe( /* get focus frame */ |
642 |
> |
XButtonPressedEvent *ebut |
643 |
> |
) |
644 |
|
{ |
645 |
|
int startx = ebut->x, starty = ebut->y; |
646 |
< |
int endx, endy; |
647 |
< |
|
646 |
> |
int endx, endy, midx, midy; |
647 |
> |
FVECT v1; |
648 |
> |
int li; |
649 |
> |
/* get mouse drag */ |
650 |
|
XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); |
651 |
|
endx = levptr(XButtonReleasedEvent)->x; |
652 |
|
endy = levptr(XButtonReleasedEvent)->y; |
653 |
< |
if (endx == startx | endy == starty) { |
654 |
< |
XBell(ourdisplay, 0); |
653 |
> |
midx = (startx + endx) >> 1; |
654 |
> |
midy = (starty + endy) >> 1; |
655 |
> |
/* set focus distance */ |
656 |
> |
if ((li = qtFindLeaf(midx, midy)) < 0) |
657 |
> |
return; /* not on window */ |
658 |
> |
VCOPY(v1, qtL.wp[li]); |
659 |
> |
odev.v.vdist = sqrt(dist2(odev.v.vp, v1)); |
660 |
> |
/* set frame for rendering */ |
661 |
> |
if ((endx == startx) | (endy == starty)) |
662 |
|
return; |
663 |
< |
} |
664 |
< |
if (endx < startx) {register int c = endx; endx = startx; startx = c;} |
603 |
< |
if (endy < starty) {register int c = endy; endy = starty; starty = c;} |
663 |
> |
if (endx < startx) {int c = endx; endx = startx; startx = c;} |
664 |
> |
if (endy < starty) {int c = endy; endy = starty; starty = c;} |
665 |
|
sprintf(odev_args, "%.3f %.3f %.3f %.3f", |
666 |
|
(startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, |
667 |
|
(endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); |
669 |
|
} |
670 |
|
|
671 |
|
|
672 |
< |
static |
673 |
< |
waitabit() /* pause a moment */ |
672 |
> |
static void |
673 |
> |
waitabit(void) /* pause a moment */ |
674 |
|
{ |
675 |
|
struct timespec ts; |
676 |
|
ts.tv_sec = 0; |
677 |
< |
ts.tv_nsec = 50000000; |
677 |
> |
ts.tv_nsec = 100000000; |
678 |
|
nanosleep(&ts, NULL); |
679 |
|
} |
680 |
|
|
681 |
|
|
682 |
< |
static |
683 |
< |
getmove(ebut) /* get view change */ |
684 |
< |
XButtonPressedEvent *ebut; |
682 |
> |
static void |
683 |
> |
getmove( /* get view change */ |
684 |
> |
XButtonPressedEvent *ebut |
685 |
> |
) |
686 |
|
{ |
687 |
|
int movdir = MOVDIR(ebut->button); |
688 |
|
int movorb = MOVORB(ebut->state); |
721 |
|
} |
722 |
|
|
723 |
|
|
724 |
< |
static |
725 |
< |
getkey(ekey) /* get input key */ |
726 |
< |
register XKeyPressedEvent *ekey; |
724 |
> |
static void |
725 |
> |
getkey( /* get input key */ |
726 |
> |
XKeyPressedEvent *ekey |
727 |
> |
) |
728 |
|
{ |
729 |
|
Window rootw, childw; |
730 |
|
int rootx, rooty, wx, wy; |
803 |
|
} |
804 |
|
|
805 |
|
|
806 |
< |
static |
807 |
< |
fixwindow(eexp) /* repair damage to window */ |
808 |
< |
register XExposeEvent *eexp; |
806 |
> |
static void |
807 |
> |
fixwindow( /* repair damage to window */ |
808 |
> |
XExposeEvent *eexp |
809 |
> |
) |
810 |
|
{ |
811 |
|
if (odev.hres == 0 || odev.vres == 0) { /* first exposure */ |
812 |
|
odev.hres = eexp->width; |
817 |
|
} |
818 |
|
|
819 |
|
|
820 |
< |
static |
821 |
< |
resizewindow(ersz) /* resize window */ |
822 |
< |
register XConfigureEvent *ersz; |
820 |
> |
static void |
821 |
> |
resizewindow( /* resize window */ |
822 |
> |
XConfigureEvent *ersz |
823 |
> |
) |
824 |
|
{ |
825 |
|
if (ersz->width == odev.hres && ersz->height == odev.vres) |
826 |
|
return; |