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.5 by gregl, Fri Nov 21 15:11:43 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 57 | Line 62 | static double  pwidth, pheight;        /* pixel dimensions (mm
62  
63   static int      inpresflags;            /* input result flags */
64  
65 < static int      heightlocked = 0;       /* lock vertical motion */
65 > static int      headlocked = 0;         /* lock vertical motion */
66  
67   static int  getpixels(), xnewcolr(), freepixels(), resizewindow(),
68 <                getevent(), getkey(), fixwindow();
68 >                getevent(), getkey(), moveview(), getmove(), fixwindow();
69   static unsigned long  true_pixel();
70  
71  
# Line 90 | Line 95 | char  *id;
95          char  *gv;
96          double  gamval = GAMMA;
97          int  nplanes;
93        int  n;
98          XSetWindowAttributes    ourwinattr;
99          XWMHints  ourxwmhints;
100          XSizeHints      oursizhints;
101 +                                        /* set quadtree globals */
102 +        qtDepthEps = 0.02;
103 +        qtMinNodesiz = 2;
104                                          /* open display server */
105          ourdisplay = XOpenDisplay(NULL);
106          if (ourdisplay == NULL)
# Line 155 | Line 162 | char  *id;
162                                          /* map the window and get its size */
163          XMapWindow(ourdisplay, gwind);
164          dev_input();
165 +                                        /* allocate our leaf pile */
166 +        if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) *
167 +                        DisplayHeight(ourdisplay,ourscreen) /
168 +                        (qtMinNodesiz*qtMinNodesiz)))
169 +                error(SYSTEM, "insufficient memory for leaf storage");
170 +
171                                          /* figure out sensible view */
172          pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) /
173                          DisplayWidth(ourdisplay, ourscreen);
# Line 166 | Line 179 | char  *id;
179          odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
180          odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
181          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");
182   }
183  
184  
# Line 205 | Line 212 | int
212   dev_input()                     /* get X11 input */
213   {
214          inpresflags = 0;
215 +
216          do
217                  getevent();
218  
# Line 365 | Line 373 | getevent()                     /* get next event */
373                  getkey(levptr(XKeyPressedEvent));
374                  break;
375          case ButtonPress:
376 <                /* getmove(levptr(XButtonPressedEvent)); */
376 >                getmove(levptr(XButtonPressedEvent));
377                  break;
378          }
379   }
380  
381  
382   static
383 + moveview(dx, dy, move)          /* move our view */
384 + int     dx, dy, move;
385 + {
386 +        VIEW    nv;
387 +        double  d;
388 +        register int    i, li;
389 +                                /* start with old view */
390 +        copystruct(&nv, &odev.v);
391 +                                /* change view direction */
392 +        if (move) {
393 +                if ((li = qtFindLeaf(dx, dy)) < 0)
394 +                        return(0);      /* not on window */
395 +                for (i = 0; i < 3; i++)
396 +                        nv.vdir[i] = qtL.wp[li][i] - nv.vp[i];
397 +        } else {
398 +                if (viewray(nv.vp, nv.vdir, &odev.v,
399 +                                (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
400 +                        return(0);      /* outside view */
401 +        }
402 +                                /* move viewpoint */
403 +        if (move > 0)
404 +                for (i = 0; i < 3; i++)
405 +                        nv.vp[i] += MOVPCT/100. * nv.vdir[i];
406 +        else if (move < 0)
407 +                for (i = 0; i < 3; i++)
408 +                        nv.vp[i] -= MOVPCT/100. * nv.vdir[i];
409 +        if (move && headlocked) {
410 +                d = 0;          /* bring head back to same height */
411 +                for (i = 0; i < 3; i++)
412 +                        d += odev.v.vup[i] * (odev.v.vp[i] - nv.vp[i]);
413 +                for (i = 0; i < 3; i++)
414 +                        nv.vp[i] += d * odev.v.vup[i];
415 +        }
416 +        if (setview(&nv) != NULL)
417 +                return(0);      /* illegal view */
418 +        dev_view(&nv);
419 +        inpresflags |= DEV_NEWVIEW;
420 +        return(1);
421 + }
422 +
423 +
424 + static
425 + getmove(ebut)                           /* get view change */
426 + XButtonPressedEvent     *ebut;
427 + {
428 +        int     whichbutton = ebut->button;
429 +        int     oldnodesiz = qtMinNodesiz;
430 +        Window  rootw, childw;
431 +        int     rootx, rooty, wx, wy;
432 +        unsigned int    statemask;
433 +
434 +        qtMinNodesiz = 16;              /* for quicker update */
435 +        qtCompost(50);
436 +
437 +        do {
438 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
439 +                                &rootx, &rooty, &wx, &wy, &statemask))
440 +                        break;          /* on another screen */
441 +
442 +                if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)))
443 +                        sleep(1);
444 +                else
445 +                        qtUpdate();
446 +
447 +        } while (!XCheckMaskEvent(ourdisplay,
448 +                        ButtonReleaseMask, levptr(XEvent)));
449 +
450 +        if (!(inpresflags & DEV_NEWVIEW)) {     /* do final motion */
451 +                whichbutton = levptr(XButtonReleasedEvent)->button;
452 +                wx = levptr(XButtonReleasedEvent)->x;
453 +                wy = levptr(XButtonReleasedEvent)->y;
454 +                moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton));
455 +        }
456 +
457 +        qtMinNodesiz = oldnodesiz;      /* restore quadtree resolution */
458 + }
459 +
460 +
461 + static
462   getkey(ekey)                            /* get input key */
463   register XKeyPressedEvent  *ekey;
464   {
# Line 383 | Line 470 | register XKeyPressedEvent  *ekey;
470                  return;
471          switch (buf[0]) {
472          case 'h':                       /* turn on height motion lock */
473 <                heightlocked = 1;
473 >                headlocked = 1;
474                  return;
475          case 'H':                       /* turn off height motion lock */
476 <                heightlocked = 0;
476 >                headlocked = 0;
477                  return;
478 +        case CTRL('S'):
479 +        case 'p':                       /* pause computation */
480 +                inpresflags |= DEV_WAIT;
481 +                return;
482 +        case CTRL('Q'):
483 +        case '\n':
484 +        case '\r':                      /* resume computation */
485 +                inpresflags |= DEV_RESUME;
486 +                return;
487 +        case CTRL('R'):                 /* redraw */
488 +                if (ncolors > 0)
489 +                        new_ctab(ncolors);
490 +                qtRedraw(0, 0, odev.hres, odev.vres);
491 +                return;
492 +        case CTRL('D'):
493          case 'Q':
494          case 'q':                       /* quit the program */
495                  inpresflags |= DEV_SHUTDOWN;
# Line 404 | Line 506 | fixwindow(eexp)                                /* repair damage to window */
506   register XExposeEvent  *eexp;
507   {
508          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
407 eputs("Resizing window in fixwindow\n");
509                  odev.hres = eexp->width;
510                  odev.vres = eexp->height;
511                  inpresflags |= DEV_NEWSIZE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines