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.1 by gregl, Wed Nov 19 18:01:03 1997 UTC vs.
Revision 3.10 by gregl, Fri Dec 5 09:38:55 1997 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
18  
19   #include  "x11icon.h"
20  
21 + #define CTRL(c)         ((c)-'@')
22 +
23   #define GAMMA           2.2             /* default gamma correction */
24  
25 + #define MOVPCT          10              /* percent distance to move */
26 + #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
27 +
28   #define MINWIDTH        480             /* minimum graphics window width */
29   #define MINHEIGHT       400             /* minimum graphics window height */
30  
# Line 30 | Line 35 | static char SCCSid[] = "$SunId$ SGI";
35   #define  ourscreen      DefaultScreen(ourdisplay)
36   #define  ourroot        RootWindow(ourdisplay,ourscreen)
37   #define  ourmask        (StructureNotifyMask|ExposureMask|KeyPressMask|\
38 <                        ButtonPressMask)
38 >                        ButtonPressMask|ButtonReleaseMask)
39  
40   #define  levptr(etype)  ((etype *)&currentevent)
41  
# Line 44 | Line 49 | static unsigned long  *pixval = NULL;  /* allocated pix
49   static unsigned long  ourblack=0, ourwhite=1;
50  
51   static Display  *ourdisplay = NULL;     /* our display */
47
52   static XVisualInfo  ourvinfo;           /* our visual information */
49
53   static Window  gwind = 0;               /* our graphics window */
51
54   static GC  ourgc = 0;                   /* our graphics context for drawing */
53
55   static Colormap ourmap = 0;             /* our color map */
56  
57   static double   pwidth, pheight;        /* pixel dimensions (mm) */
58  
59   static int      inpresflags;            /* input result flags */
60  
61 < static int      heightlocked = 0;       /* lock vertical motion */
61 > static int      headlocked = 0;         /* lock vertical motion */
62  
63   static int  getpixels(), xnewcolr(), freepixels(), resizewindow(),
64 <                getevent(), getkey(), fixwindow();
64 >                getevent(), getkey(), moveview(), getmove(), fixwindow();
65   static unsigned long  true_pixel();
66  
67  
# Line 90 | Line 91 | char  *id;
91          char  *gv;
92          double  gamval = GAMMA;
93          int  nplanes;
93        int  n;
94          XSetWindowAttributes    ourwinattr;
95          XWMHints  ourxwmhints;
96          XSizeHints      oursizhints;
97 +                                        /* set quadtree globals */
98 +        qtMinNodesiz = 2;
99                                          /* open display server */
100          ourdisplay = XOpenDisplay(NULL);
101          if (ourdisplay == NULL)
# Line 155 | Line 157 | char  *id;
157                                          /* map the window and get its size */
158          XMapWindow(ourdisplay, gwind);
159          dev_input();
160 +                                        /* allocate our leaf pile */
161 +        if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
162 +                        DisplayHeight(ourdisplay,ourscreen) /
163 +                        (qtMinNodesiz*qtMinNodesiz)))
164 +                error(SYSTEM, "insufficient memory for leaf storage");
165 +
166                                          /* figure out sensible view */
167          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
168                          DisplayWidth(ourdisplay, ourscreen);
# Line 166 | Line 174 | char  *id;
174          odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
175          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
176          odev.ifd = ConnectionNumber(ourdisplay);
169                                        /* allocate our leaf pile */
170        qtDepthEps = 0.02;
171        n = odev.hres < odev.vres ? odev.hres : odev.vres;
172        qtMinNodesiz = 1;
173        if (!qtAllocLeaves(n*n/(qtMinNodesiz*qtMinNodesiz)))
174                error(SYSTEM, "insufficient memory for leaf storage");
177   }
178  
179  
# Line 205 | Line 207 | int
207   dev_input()                     /* get X11 input */
208   {
209          inpresflags = 0;
210 +
211          do
212                  getevent();
213  
# Line 365 | Line 368 | getevent()                     /* get next event */
368                  getkey(levptr(XKeyPressedEvent));
369                  break;
370          case ButtonPress:
371 <                /* getmove(levptr(XButtonPressedEvent)); */
371 >                getmove(levptr(XButtonPressedEvent));
372                  break;
373          }
374   }
375  
376  
377   static
378 + ilclip(dp, wp)                  /* clip world coordinates to device */
379 + int     dp[2][2];
380 + FVECT   wp[2];
381 + {
382 +        static FVECT    vmin = {0.,0.,0.}, vmax = {1.,1.,FHUGE};
383 +        FVECT   ip[2];
384 +                                /* not exactly right, but who cares? */
385 +        viewloc(ip[0], &odev.v, wp[0]);
386 +        viewloc(ip[1], &odev.v, wp[1]);
387 +        if (!clip(ip[0], ip[1], vmin, vmax))
388 +                return(0);
389 +        dp[0][0] = ip[0][0]*odev.hres;
390 +        dp[0][1] = ip[0][1]*odev.vres;
391 +        dp[1][0] = ip[1][0]*odev.hres;
392 +        dp[1][1] = ip[1][1]*odev.vres;
393 +        return(1);
394 + }
395 +
396 +
397 + static
398 + draw3dline(wp)                  /* draw 3d line in world coordinates */
399 + FVECT   wp[2];
400 + {
401 +        int     dp[2][2];
402 +
403 +        if (!ilclip(dp, wp))
404 +                return;
405 +        XDrawLine(ourdisplay, gwind, ourgc,
406 +                        dp[0][0], odev.vres-1 - dp[0][1],
407 +                        dp[1][0], odev.vres-1 - dp[1][1]);
408 + }
409 +
410 +
411 + static
412 + draw_grids()                    /* draw holodeck section grids */
413 + {
414 +        static BYTE     gridrgb[3] = {0x0, 0xff, 0xff};
415 +        unsigned long  pixel;
416 +
417 +        if (!mapped || odev.v.type != VT_PER)
418 +                return;
419 +        if (ncolors > 0)
420 +                pixel = pixval[get_pixel(gridrgb, xnewcolr)];
421 +        else
422 +                pixel = true_pixel(gridrgb);
423 +        XSetForeground(ourdisplay, ourgc, pixel);
424 +                                        /* draw each grid line */
425 +        gridlines(draw3dline);
426 + }
427 +
428 +
429 + static
430 + moveview(dx, dy, move)          /* move our view */
431 + int     dx, dy, move;
432 + {
433 +        VIEW    nv;
434 +        double  d;
435 +        register int    i, li;
436 +                                /* start with old view */
437 +        copystruct(&nv, &odev.v);
438 +                                /* change view direction */
439 +        if (move) {
440 +                if ((li = qtFindLeaf(dx, dy)) < 0)
441 +                        return(0);      /* not on window */
442 +                for (i = 0; i < 3; i++)
443 +                        nv.vdir[i] = qtL.wp[li][i] - nv.vp[i];
444 +        } else {
445 +                if (viewray(nv.vp, nv.vdir, &odev.v,
446 +                                (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
447 +                        return(0);      /* outside view */
448 +        }
449 +                                /* move viewpoint */
450 +        if (move > 0)
451 +                for (i = 0; i < 3; i++)
452 +                        nv.vp[i] += MOVPCT/100. * nv.vdir[i];
453 +        else if (move < 0)
454 +                for (i = 0; i < 3; i++)
455 +                        nv.vp[i] -= MOVPCT/100. * nv.vdir[i];
456 +        if (move && headlocked) {
457 +                d = 0;          /* bring head back to same height */
458 +                for (i = 0; i < 3; i++)
459 +                        d += odev.v.vup[i] * (odev.v.vp[i] - nv.vp[i]);
460 +                for (i = 0; i < 3; i++)
461 +                        nv.vp[i] += d * odev.v.vup[i];
462 +        }
463 +        if (setview(&nv) != NULL)
464 +                return(0);      /* illegal view */
465 +        dev_view(&nv);
466 +        inpresflags |= DEV_NEWVIEW;
467 +        return(1);
468 + }
469 +
470 +
471 + static
472 + getmove(ebut)                           /* get view change */
473 + XButtonPressedEvent     *ebut;
474 + {
475 +        int     whichbutton = ebut->button;
476 +        int     oldnodesiz = qtMinNodesiz;
477 +        Window  rootw, childw;
478 +        int     rootx, rooty, wx, wy;
479 +        unsigned int    statemask;
480 +
481 +        qtMinNodesiz = 16;              /* for quicker update */
482 +        XNoOp(ourdisplay);
483 +
484 +        while (!XCheckMaskEvent(ourdisplay,
485 +                        ButtonReleaseMask, levptr(XEvent))) {
486 +
487 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
488 +                                &rootx, &rooty, &wx, &wy, &statemask))
489 +                        break;          /* on another screen */
490 +
491 +                if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) {
492 +                        sleep(1);
493 +                        continue;
494 +                }
495 +                XClearWindow(ourdisplay, gwind);
496 +                qtUpdate();
497 +                draw_grids();
498 +        }
499 +        if (!(inpresflags & DEV_NEWVIEW)) {     /* do final motion */
500 +                whichbutton = levptr(XButtonReleasedEvent)->button;
501 +                wx = levptr(XButtonReleasedEvent)->x;
502 +                wy = levptr(XButtonReleasedEvent)->y;
503 +                moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton));
504 +        }
505 +        dev_flush();
506 +
507 +        qtMinNodesiz = oldnodesiz;      /* restore quadtree resolution */
508 + }
509 +
510 +
511 + static
512   getkey(ekey)                            /* get input key */
513   register XKeyPressedEvent  *ekey;
514   {
# Line 383 | Line 520 | register XKeyPressedEvent  *ekey;
520                  return;
521          switch (buf[0]) {
522          case 'h':                       /* turn on height motion lock */
523 <                heightlocked = 1;
523 >                headlocked = 1;
524                  return;
525          case 'H':                       /* turn off height motion lock */
526 <                heightlocked = 0;
526 >                headlocked = 0;
527                  return;
528 +        case CTRL('S'):
529 +        case 'p':                       /* pause computation */
530 +                inpresflags |= DEV_WAIT;
531 +                return;
532 +        case 'v':                       /* spit out view */
533 +                fputs(VIEWSTR, stderr);
534 +                fprintview(&odev.v, stderr);
535 +                fputc('\n', stderr);
536 +                return;
537 +        case CTRL('Q'):
538 +        case '\n':
539 +        case '\r':                      /* resume computation */
540 +                inpresflags |= DEV_RESUME;
541 +                return;
542 +        case CTRL('R'):                 /* redraw screen */
543 +                if (ncolors > 0)
544 +                        new_ctab(ncolors);
545 +                qtRedraw(0, 0, odev.hres, odev.vres);
546 +                return;
547 +        case CTRL('L'):                 /* refresh from server */
548 +                if (inpresflags & DEV_REDRAW)
549 +                        return;
550 +                XClearWindow(ourdisplay, gwind);
551 +                draw_grids();
552 +                XFlush(ourdisplay);
553 +                qtCompost(100);                 /* unload the old tree */
554 +                if (ncolors > 0)
555 +                        new_ctab(ncolors);
556 +                inpresflags |= DEV_REDRAW;      /* resend values from server */
557 +                return;
558 +        case CTRL('D'):
559          case 'Q':
560          case 'q':                       /* quit the program */
561                  inpresflags |= DEV_SHUTDOWN;
# Line 404 | Line 572 | fixwindow(eexp)                                /* repair damage to window */
572   register XExposeEvent  *eexp;
573   {
574          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
407 eputs("Resizing window in fixwindow\n");
575                  odev.hres = eexp->width;
576                  odev.vres = eexp->height;
577                  inpresflags |= DEV_NEWSIZE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines