1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
10 |
|
*/ |
11 |
|
|
12 |
|
#include "standard.h" |
13 |
– |
#include "rhd_qtree.h" |
14 |
– |
|
13 |
|
#include <X11/Xlib.h> |
14 |
|
#include <X11/cursorfont.h> |
15 |
|
#include <X11/Xutil.h> |
16 |
< |
|
16 |
> |
#include "rhd_qtree.h" |
17 |
|
#include "x11icon.h" |
18 |
|
|
19 |
|
#ifndef RAYQLEN |
26 |
|
|
27 |
|
#define GAMMA 2.2 /* default gamma correction */ |
28 |
|
|
29 |
+ |
#define FRAMESTATE(s) (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) |
30 |
+ |
|
31 |
|
#define MOVPCT 7 /* percent distance to move /frame */ |
32 |
|
#define MOVDIR(b) ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1) |
33 |
|
#define MOVDEG (-5) /* degrees to orbit CW/down /frame */ |
49 |
|
|
50 |
|
struct driver odev; /* global device driver structure */ |
51 |
|
|
52 |
+ |
char odev_args[64]; /* command arguments */ |
53 |
+ |
|
54 |
|
static XEvent currentevent; /* current event */ |
55 |
|
|
56 |
|
static int ncolors = 0; /* color table size */ |
70 |
|
|
71 |
|
static int headlocked = 0; /* lock vertical motion */ |
72 |
|
|
73 |
< |
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), |
73 |
> |
static int getpixels(), xnewcolr(), freepixels(), resizewindow(), getframe(), |
74 |
|
getevent(), getkey(), moveview(), getmove(), fixwindow(); |
75 |
|
static unsigned long true_pixel(); |
76 |
|
|
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
+ |
dev_section(ofn) /* add octree for geometry rendering */ |
271 |
+ |
char *ofn; |
272 |
+ |
{ |
273 |
+ |
/* unimplemented */ |
274 |
+ |
} |
275 |
+ |
|
276 |
+ |
|
277 |
+ |
dev_auxcom(cmd, args) /* process an auxiliary command */ |
278 |
+ |
char *cmd, *args; |
279 |
+ |
{ |
280 |
+ |
sprintf(errmsg, "%s: unknown command", cmd); |
281 |
+ |
error(COMMAND, errmsg); |
282 |
+ |
} |
283 |
+ |
|
284 |
+ |
|
285 |
+ |
VIEW * |
286 |
+ |
dev_auxview(n, hvres) /* return nth auxiliary view */ |
287 |
+ |
int n; |
288 |
+ |
int hvres[2]; |
289 |
+ |
{ |
290 |
+ |
if (n) |
291 |
+ |
return(NULL); |
292 |
+ |
hvres[0] = odev.hres; hvres[1] = odev.vres; |
293 |
+ |
return(&odev.v); |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
|
297 |
|
int |
298 |
|
dev_input() /* get X11 input */ |
299 |
|
{ |
302 |
|
do |
303 |
|
getevent(); |
304 |
|
|
305 |
< |
while (XQLength(ourdisplay) > 0); |
305 |
> |
while (XPending(ourdisplay) > 0); |
306 |
|
|
307 |
+ |
odev.inpready = 0; |
308 |
+ |
|
309 |
|
return(inpresflags); |
310 |
|
} |
311 |
|
|
333 |
|
{ |
334 |
|
qtUpdate(); |
335 |
|
rayqleft = RAYQLEN; |
336 |
< |
return(XPending(ourdisplay)); |
336 |
> |
return(odev.inpready = XPending(ourdisplay)); |
337 |
|
} |
338 |
|
|
339 |
|
|
462 |
|
getkey(levptr(XKeyPressedEvent)); |
463 |
|
break; |
464 |
|
case ButtonPress: |
465 |
< |
getmove(levptr(XButtonPressedEvent)); |
465 |
> |
if (FRAMESTATE(levptr(XButtonPressedEvent)->state)) |
466 |
> |
getframe(levptr(XButtonPressedEvent)); |
467 |
> |
else |
468 |
> |
getmove(levptr(XButtonPressedEvent)); |
469 |
|
break; |
470 |
|
} |
471 |
|
} |
476 |
|
int dp[2][2]; |
477 |
|
FVECT wp[2]; |
478 |
|
{ |
479 |
< |
static FVECT vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE}; |
480 |
< |
FVECT ip[2]; |
481 |
< |
/* not exactly right, but who cares? */ |
482 |
< |
viewloc(ip[0], &odev.v, wp[0]); |
483 |
< |
viewloc(ip[1], &odev.v, wp[1]); |
479 |
> |
static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE}; |
480 |
> |
FVECT wpc[2], ip[2]; |
481 |
> |
double d, d0, d1; |
482 |
> |
/* check for points behind view */ |
483 |
> |
d = DOT(odev.v.vp, odev.v.vdir); |
484 |
> |
d0 = DOT(wp[0], odev.v.vdir) - d; |
485 |
> |
d1 = DOT(wp[1], odev.v.vdir) - d; |
486 |
> |
/* work on copy of world points */ |
487 |
> |
if (d0 <= d1) { |
488 |
> |
VCOPY(wpc[0], wp[0]); VCOPY(wpc[1], wp[1]); |
489 |
> |
} else { |
490 |
> |
d = d0; d0 = d1; d1 = d; |
491 |
> |
VCOPY(wpc[1], wp[0]); VCOPY(wpc[0], wp[1]); |
492 |
> |
} |
493 |
> |
if (d0 <= FTINY) { |
494 |
> |
if (d1 <= FTINY) return(0); |
495 |
> |
VSUB(wpc[0], wpc[0], wpc[1]); |
496 |
> |
d = .99*d1/(d1-d0); |
497 |
> |
VSUM(wpc[0], wpc[1], wpc[0], d); |
498 |
> |
} |
499 |
> |
/* get view coordinates and clip to window */ |
500 |
> |
viewloc(ip[0], &odev.v, wpc[0]); |
501 |
> |
viewloc(ip[1], &odev.v, wpc[1]); |
502 |
|
if (!clip(ip[0], ip[1], vmin, vmax)) |
503 |
|
return(0); |
504 |
|
dp[0][0] = ip[0][0]*odev.hres; |
529 |
|
static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; |
530 |
|
unsigned long pixel; |
531 |
|
|
480 |
– |
if (!mapped) |
481 |
– |
return; |
532 |
|
if (ncolors > 0) |
533 |
|
pixel = pixval[get_pixel(gridrgb, xnewcolr)]; |
534 |
|
else |
588 |
|
|
589 |
|
|
590 |
|
static |
591 |
+ |
getframe(ebut) /* get focus frame */ |
592 |
+ |
XButtonPressedEvent *ebut; |
593 |
+ |
{ |
594 |
+ |
int startx = ebut->x, starty = ebut->y; |
595 |
+ |
int endx, endy; |
596 |
+ |
|
597 |
+ |
XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); |
598 |
+ |
endx = levptr(XButtonReleasedEvent)->x; |
599 |
+ |
endy = levptr(XButtonReleasedEvent)->y; |
600 |
+ |
if (endx == startx | endy == starty) { |
601 |
+ |
XBell(ourdisplay, 0); |
602 |
+ |
return; |
603 |
+ |
} |
604 |
+ |
if (endx < startx) {register int c = endx; endx = startx; startx = c;} |
605 |
+ |
if (endy < starty) {register int c = endy; endy = starty; starty = c;} |
606 |
+ |
sprintf(odev_args, "%.3f %.3f %.3f %.3f", |
607 |
+ |
(startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres, |
608 |
+ |
(endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres); |
609 |
+ |
inpresflags |= DFL(DC_FOCUS); |
610 |
+ |
} |
611 |
+ |
|
612 |
+ |
|
613 |
+ |
static |
614 |
|
getmove(ebut) /* get view change */ |
615 |
|
XButtonPressedEvent *ebut; |
616 |
|
{ |
655 |
|
getkey(ekey) /* get input key */ |
656 |
|
register XKeyPressedEvent *ekey; |
657 |
|
{ |
658 |
+ |
Window rootw, childw; |
659 |
+ |
int rootx, rooty, wx, wy; |
660 |
+ |
unsigned int statemask; |
661 |
|
int n; |
662 |
|
char buf[8]; |
663 |
|
|
673 |
|
return; |
674 |
|
case 'l': /* retrieve last view */ |
675 |
|
inpresflags |= DFL(DC_LASTVIEW); |
676 |
+ |
return; |
677 |
+ |
case 'f': /* frame view position */ |
678 |
+ |
if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw, |
679 |
+ |
&rootx, &rooty, &wx, &wy, &statemask)) |
680 |
+ |
return; /* on another screen */ |
681 |
+ |
sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres, |
682 |
+ |
1.-(wy+.5)/odev.vres); |
683 |
+ |
inpresflags |= DFL(DC_FOCUS); |
684 |
+ |
return; |
685 |
+ |
case 'F': /* unfocus */ |
686 |
+ |
odev_args[0] = '\0'; |
687 |
+ |
inpresflags |= DFL(DC_FOCUS); |
688 |
|
return; |
689 |
|
case 'p': /* pause computation */ |
690 |
|
inpresflags |= DFL(DC_PAUSE); |