ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_x11.c
(Generate patch)

Comparing ray/src/hd/rhd_x11.c (file contents):
Revision 3.7 by gregl, Mon Nov 24 15:17:06 1997 UTC vs.
Revision 3.15 by gregl, Fri Dec 12 11:13:15 1997 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
18  
19   #include  "x11icon.h"
20  
21 < #define CTRL(c)         ((c)-'@')
21 > #ifndef FEQ
22 > #define FEQ(a,b)        ((a)-(b) <= FTINY && (a)-(b) >= -FTINY)
23 > #endif
24  
25   #define GAMMA           2.2             /* default gamma correction */
26  
27 < #define MOVPCT          10              /* percent distance to move */
27 > #define MOVPCT          7               /* percent distance to move /frame */
28   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
29 + #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
30 + #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
31  
32   #define MINWIDTH        480             /* minimum graphics window width */
33   #define MINHEIGHT       400             /* minimum graphics window height */
# Line 49 | Line 53 | static unsigned long  *pixval = NULL;  /* allocated pix
53   static unsigned long  ourblack=0, ourwhite=1;
54  
55   static Display  *ourdisplay = NULL;     /* our display */
52
56   static XVisualInfo  ourvinfo;           /* our visual information */
54
57   static Window  gwind = 0;               /* our graphics window */
56
58   static GC  ourgc = 0;                   /* our graphics context for drawing */
58
59   static Colormap ourmap = 0;             /* our color map */
60  
61   static double   pwidth, pheight;        /* pixel dimensions (mm) */
# Line 99 | Line 99 | char  *id;
99          XWMHints  ourxwmhints;
100          XSizeHints      oursizhints;
101                                          /* set quadtree globals */
102        qtDepthEps = 0.02;
102          qtMinNodesiz = 2;
103                                          /* open display server */
104          ourdisplay = XOpenDisplay(NULL);
# Line 199 | Line 198 | dev_close()                    /* close our display */
198   }
199  
200  
201 + int
202   dev_view(nv)                    /* assign new driver view */
203   VIEW    *nv;
204   {
205 <        if (nv != &odev.v)
205 >        if (nv->type == VT_PAR ||               /* check view legality */
206 >                nv->horiz > 160. || nv->vert > 160.) {
207 >                error(COMMAND, "illegal view type/angle");
208 >                nv->type = VT_PER;
209 >                nv->horiz = odev.v.horiz;
210 >                nv->vert = odev.v.vert;
211 >                return(0);
212 >        }
213 >        if (nv->vfore > FTINY) {
214 >                error(COMMAND, "cannot handle fore clipping");
215 >                nv->vfore = 0.;
216 >                return(0);
217 >        }
218 >        if (nv != &odev.v) {
219 >                if (!FEQ(nv->horiz,odev.v.horiz) ||     /* resize window? */
220 >                                !FEQ(nv->vert,odev.v.vert)) {
221 >                        int     dw = DisplayWidth(ourdisplay,ourscreen);
222 >                        int     dh = DisplayHeight(ourdisplay,ourscreen);
223 >
224 >                        dw -= 25;       /* for window frame */
225 >                        dh -= 100;
226 >                        odev.hres = 2.*VIEWDIST/pwidth *
227 >                                        tan(PI/180./2.*nv->horiz);
228 >                        odev.vres = 2.*VIEWDIST/pheight *
229 >                                        tan(PI/180./2.*nv->vert);
230 >                        if (odev.hres > dw) {
231 >                                odev.vres = dw * odev.vres / odev.hres;
232 >                                odev.hres = dw;
233 >                        }
234 >                        if (odev.vres > dh) {
235 >                                odev.hres = dh * odev.hres / odev.vres;
236 >                                odev.vres = dh;
237 >                        }
238 >                        XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres);
239 >                }
240                  copystruct(&odev.v, nv);
241 +        }
242          qtReplant();
243 +        return(1);
244   }
245  
246  
# Line 380 | Line 416 | getevent()                     /* get next event */
416  
417  
418   static
419 < moveview(dx, dy, move)          /* move our view */
420 < int     dx, dy, move;
419 > ilclip(dp, wp)                  /* clip world coordinates to device */
420 > int     dp[2][2];
421 > FVECT   wp[2];
422   {
423 +        static FVECT    vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE};
424 +        FVECT   ip[2];
425 +                                /* not exactly right, but who cares? */
426 +        viewloc(ip[0], &odev.v, wp[0]);
427 +        viewloc(ip[1], &odev.v, wp[1]);
428 +        if (!clip(ip[0], ip[1], vmin, vmax))
429 +                return(0);
430 +        dp[0][0] = ip[0][0]*odev.hres;
431 +        dp[0][1] = ip[0][1]*odev.vres;
432 +        dp[1][0] = ip[1][0]*odev.hres;
433 +        dp[1][1] = ip[1][1]*odev.vres;
434 +        return(1);
435 + }
436 +
437 +
438 + static
439 + draw3dline(wp)                  /* draw 3d line in world coordinates */
440 + FVECT   wp[2];
441 + {
442 +        int     dp[2][2];
443 +
444 +        if (!ilclip(dp, wp))
445 +                return;
446 +        XDrawLine(ourdisplay, gwind, ourgc,
447 +                        dp[0][0], odev.vres-1 - dp[0][1],
448 +                        dp[1][0], odev.vres-1 - dp[1][1]);
449 + }
450 +
451 +
452 + static
453 + draw_grids()                    /* draw holodeck section grids */
454 + {
455 +        static BYTE     gridrgb[3] = {0x0, 0xff, 0xff};
456 +        unsigned long  pixel;
457 +
458 +        if (!mapped || odev.v.type != VT_PER)
459 +                return;
460 +        if (ncolors > 0)
461 +                pixel = pixval[get_pixel(gridrgb, xnewcolr)];
462 +        else
463 +                pixel = true_pixel(gridrgb);
464 +        XSetForeground(ourdisplay, ourgc, pixel);
465 +                                        /* draw each grid line */
466 +        gridlines(draw3dline);
467 + }
468 +
469 +
470 + static
471 + moveview(dx, dy, mov, orb)      /* move our view */
472 + int     dx, dy, mov, orb;
473 + {
474          VIEW    nv;
475 +        FVECT   v1;
476          double  d;
477 <        register int    i, li;
477 >        register int    li;
478                                  /* start with old view */
479          copystruct(&nv, &odev.v);
480                                  /* change view direction */
481 <        if (move) {
481 >        if (mov | orb) {
482                  if ((li = qtFindLeaf(dx, dy)) < 0)
483                          return(0);      /* not on window */
484 <                for (i = 0; i < 3; i++)
396 <                        nv.vdir[i] = qtL.wp[li][i] - nv.vp[i];
484 >                VSUM(nv.vdir, qtL.wp[li], nv.vp, -1.);
485          } else {
486                  if (viewray(nv.vp, nv.vdir, &odev.v,
487                                  (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
488                          return(0);      /* outside view */
489          }
490 <                                /* move viewpoint */
491 <        if (move > 0)
492 <                for (i = 0; i < 3; i++)
493 <                        nv.vp[i] += MOVPCT/100. * nv.vdir[i];
494 <        else if (move < 0)
495 <                for (i = 0; i < 3; i++)
496 <                        nv.vp[i] -= MOVPCT/100. * nv.vdir[i];
497 <        if (move && headlocked) {
498 <                d = 0;          /* bring head back to same height */
499 <                for (i = 0; i < 3; i++)
500 <                        d += odev.v.vup[i] * (odev.v.vp[i] - nv.vp[i]);
501 <                for (i = 0; i < 3; i++)
414 <                        nv.vp[i] += d * odev.v.vup[i];
490 >        if (orb && mov) {               /* orbit left/right */
491 >                spinvector(nv.vdir, nv.vdir, nv.vup, MOVDEG*PI/180.*mov);
492 >                VSUM(nv.vp, qtL.wp[li], nv.vdir, -1.);
493 >        } else if (orb) {               /* orbit up/down */
494 >                fcross(v1, nv.vdir, nv.vup);
495 >                if (normalize(v1) == 0.)
496 >                        return(0);
497 >                spinvector(nv.vdir, nv.vdir, v1, MOVDEG*PI/180.*orb);
498 >                VSUM(nv.vp, qtL.wp[li], nv.vdir, -1.);
499 >        } else if (mov) {               /* move forward/backward */
500 >                d = MOVPCT/100. * mov;
501 >                VSUM(nv.vp, nv.vp, nv.vdir, d);
502          }
503 +        if (!mov ^ !orb && headlocked) {        /* restore head height */
504 +                VSUM(v1, odev.v.vp, nv.vp, -1.);
505 +                d = DOT(v1, odev.v.vup);
506 +                VSUM(nv.vp, nv.vp, odev.v.vup, d);
507 +        }
508          if (setview(&nv) != NULL)
509                  return(0);      /* illegal view */
510          dev_view(&nv);
511 <        inpresflags |= DEV_NEWVIEW;
511 >        inpresflags |= DFL(DC_SETVIEW);
512          return(1);
513   }
514  
# Line 425 | Line 517 | static
517   getmove(ebut)                           /* get view change */
518   XButtonPressedEvent     *ebut;
519   {
520 <        int     whichbutton = ebut->button;
520 >        int     movdir = MOVDIR(ebut->button);
521 >        int     movorb = MOVORB(ebut->state);
522          int     oldnodesiz = qtMinNodesiz;
523          Window  rootw, childw;
524          int     rootx, rooty, wx, wy;
525          unsigned int    statemask;
526  
527          qtMinNodesiz = 16;              /* for quicker update */
528 +        XNoOp(ourdisplay);
529  
530 <        do {
530 >        while (!XCheckMaskEvent(ourdisplay,
531 >                        ButtonReleaseMask, levptr(XEvent))) {
532 >
533                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
534                                  &rootx, &rooty, &wx, &wy, &statemask))
535                          break;          /* on another screen */
536  
537 <                if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)))
537 >                if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
538                          sleep(1);
539 <                else
540 <                        qtUpdate();
541 <
542 <        } while (!XCheckMaskEvent(ourdisplay,
543 <                        ButtonReleaseMask, levptr(XEvent)));
544 <
545 <        if (!(inpresflags & DEV_NEWVIEW)) {     /* do final motion */
546 <                whichbutton = levptr(XButtonReleasedEvent)->button;
539 >                        continue;
540 >                }
541 >                XClearWindow(ourdisplay, gwind);
542 >                qtUpdate();
543 >                draw_grids();
544 >        }
545 >        if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
546 >                movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
547                  wx = levptr(XButtonReleasedEvent)->x;
548                  wy = levptr(XButtonReleasedEvent)->y;
549 <                moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton));
549 >                moveview(wx, odev.vres-1-wy, movdir, movorb);
550          }
551 +        dev_flush();
552  
553          qtMinNodesiz = oldnodesiz;      /* restore quadtree resolution */
554   }
# Line 474 | Line 571 | register XKeyPressedEvent  *ekey;
571          case 'H':                       /* turn off height motion lock */
572                  headlocked = 0;
573                  return;
574 <        case CTRL('S'):
574 >        case 'l':                       /* retrieve last view */
575 >                inpresflags |= DFL(DC_LASTVIEW);
576 >                return;
577          case 'p':                       /* pause computation */
578 <                inpresflags |= DEV_WAIT;
578 >                inpresflags |= DFL(DC_PAUSE);
579                  return;
580          case 'v':                       /* spit out view */
581 <                fputs(VIEWSTR, stderr);
483 <                fprintview(&odev.v, stderr);
484 <                fputc('\n', stderr);
581 >                inpresflags |= DFL(DC_GETVIEW);
582                  return;
486        case CTRL('Q'):
583          case '\n':
584          case '\r':                      /* resume computation */
585 <                inpresflags |= DEV_RESUME;
585 >                inpresflags |= DFL(DC_RESUME);
586                  return;
587          case CTRL('R'):                 /* redraw screen */
588                  if (ncolors > 0)
# Line 494 | Line 590 | register XKeyPressedEvent  *ekey;
590                  qtRedraw(0, 0, odev.hres, odev.vres);
591                  return;
592          case CTRL('L'):                 /* refresh from server */
593 +                if (inpresflags & DFL(DC_REDRAW))
594 +                        return;
595                  XClearWindow(ourdisplay, gwind);
596 +                draw_grids();
597 +                XFlush(ourdisplay);
598                  qtCompost(100);                 /* unload the old tree */
599                  if (ncolors > 0)
600                          new_ctab(ncolors);
601 <                inpresflags |= DEV_REDRAW;      /* resend values from server */
601 >                inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
602                  return;
603 <        case CTRL('D'):
604 <        case 'Q':
603 >        case 'K':                       /* kill rtrace process(es) */
604 >                inpresflags |= DFL(DC_KILL);
605 >                break;
606 >        case 'R':                       /* restart rtrace */
607 >                inpresflags |= DFL(DC_RESTART);
608 >                break;
609 >        case 'C':                       /* clobber holodeck */
610 >                inpresflags |= DFL(DC_CLOBBER);
611 >                break;
612          case 'q':                       /* quit the program */
613 <                inpresflags |= DEV_SHUTDOWN;
613 >                inpresflags |= DFL(DC_QUIT);
614                  return;
615          default:
616                  XBell(ourdisplay, 0);
# Line 519 | Line 626 | register XExposeEvent  *eexp;
626          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
627                  odev.hres = eexp->width;
628                  odev.vres = eexp->height;
522                inpresflags |= DEV_NEWSIZE;
629          }
630          qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height,
631                          eexp->x + eexp->width, odev.vres - eexp->y);
# Line 533 | Line 639 | register XConfigureEvent  *ersz;
639          if (ersz->width == odev.hres && ersz->height == odev.vres)
640                  return;
641  
536        if (odev.hres != 0 && odev.vres != 0) {
537                odev.v.horiz = 2.*180./PI * atan(
538                        tan(PI/180./2.*odev.v.horiz) * ersz->width/odev.hres );
539                odev.v.vert = 2.*180./PI * atan(
540                        tan(PI/180./2.*odev.v.vert) * ersz->height/odev.vres );
541                inpresflags |= DEV_NEWVIEW;
542        }
642          odev.hres = ersz->width;
643          odev.vres = ersz->height;
644  
645 <        inpresflags |= DEV_NEWSIZE;
645 >        odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
646 >        odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
647 >
648 >        inpresflags |= DFL(DC_SETVIEW);
649   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines