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.2 by gregl, Thu Nov 20 18:04:28 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 = 1;
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 365 | Line 372 | getevent()                     /* get next event */
372                  getkey(levptr(XKeyPressedEvent));
373                  break;
374          case ButtonPress:
375 <                /* getmove(levptr(XButtonPressedEvent)); */
375 >                getmove(levptr(XButtonPressedEvent));
376                  break;
377          }
378   }
379  
380  
381   static
382 + moveview(dx, dy, move)          /* move our view */
383 + int     dx, dy, move;
384 + {
385 +        VIEW    nv;
386 +        double  d;
387 +        register int    i;
388 +                                /* start with old view */
389 +        copystruct(&nv, &odev.v);
390 +                                /* change view direction */
391 +        if (move) {
392 +                register RLEAF  *lp;
393 +                if ((lp = qtFindLeaf(dx, dy)) == NULL)
394 +                        return(0);      /* not on window */
395 +                for (i = 0; i < 3; i++)
396 +                        nv.vdir[i] = lp->wp[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 +
436 +        do {
437 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
438 +                                &rootx, &rooty, &wx, &wy, &statemask))
439 +                        break;          /* on another screen */
440 +
441 +                if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton)))
442 +                        sleep(1);
443 +
444 +        } while (!XCheckMaskEvent(ourdisplay,
445 +                        ButtonReleaseMask, levptr(XEvent)));
446 +
447 +        if (!(inpresflags & DEV_NEWVIEW)) {     /* do final motion */
448 +                whichbutton = levptr(XButtonReleasedEvent)->button;
449 +                wx = levptr(XButtonReleasedEvent)->x;
450 +                wy = levptr(XButtonReleasedEvent)->y;
451 +                moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton));
452 +        }
453 +
454 +        qtMinNodesiz = oldnodesiz;      /* restore quadtree resolution */
455 + }
456 +
457 +
458 + static
459   getkey(ekey)                            /* get input key */
460   register XKeyPressedEvent  *ekey;
461   {
# Line 383 | Line 467 | register XKeyPressedEvent  *ekey;
467                  return;
468          switch (buf[0]) {
469          case 'h':                       /* turn on height motion lock */
470 <                heightlocked = 1;
470 >                headlocked = 1;
471                  return;
472          case 'H':                       /* turn off height motion lock */
473 <                heightlocked = 0;
473 >                headlocked = 0;
474                  return;
475 +        case CTRL('Z'):
476 +        case 'p':                       /* pause computation */
477 +                inpresflags |= DEV_WAIT;
478 +                return;
479 +        case '\n':
480 +        case '\r':                      /* release */
481 +                return;
482 +        case CTRL('D'):
483          case 'Q':
484          case 'q':                       /* quit the program */
485                  inpresflags |= DEV_SHUTDOWN;
# Line 404 | Line 496 | fixwindow(eexp)                                /* repair damage to window */
496   register XExposeEvent  *eexp;
497   {
498          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
407 eputs("Resizing window in fixwindow\n");
499                  odev.hres = eexp->width;
500                  odev.vres = eexp->height;
501                  inpresflags |= DEV_NEWSIZE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines