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.10 by gregl, Fri Dec 5 09:38:55 1997 UTC vs.
Revision 3.17 by gregl, Fri Dec 19 14:44:58 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 194 | 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 -= 50;
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 427 | Line 468 | draw_grids()                   /* draw holodeck section grids */
468  
469  
470   static
471 < moveview(dx, dy, move)          /* move our view */
472 < int     dx, dy, move;
471 > moveview(dx, dy, mov, orb)      /* move our view */
472 > int     dx, dy, mov, orb;
473   {
474          VIEW    nv;
475 +        FVECT   odir, 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++)
443 <                        nv.vdir[i] = qtL.wp[li][i] - nv.vp[i];
484 >                VSUM(odir, 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++)
502 <                        nv.vp[i] += d * odev.v.vup[i];
490 >        if (orb && mov) {               /* orbit left/right */
491 >                spinvector(odir, odir, nv.vup, d=MOVDEG*PI/180.*mov);
492 >                VSUM(nv.vp, qtL.wp[li], odir, -1.);
493 >                spinvector(nv.vdir, nv.vdir, nv.vup, d);
494 >        } else if (orb) {               /* orbit up/down */
495 >                fcross(v1, odir, nv.vup);
496 >                if (normalize(v1) == 0.)
497 >                        return(0);
498 >                spinvector(odir, odir, v1, d=MOVDEG*PI/180.*orb);
499 >                VSUM(nv.vp, qtL.wp[li], odir, -1.);
500 >                spinvector(nv.vdir, nv.vdir, v1, d);
501 >        } else if (mov) {               /* move forward/backward */
502 >                d = MOVPCT/100. * mov;
503 >                VSUM(nv.vp, nv.vp, odir, d);
504          }
505 +        if (!mov ^ !orb && headlocked) {        /* restore head height */
506 +                VSUM(v1, odev.v.vp, nv.vp, -1.);
507 +                d = DOT(v1, odev.v.vup);
508 +                VSUM(nv.vp, nv.vp, odev.v.vup, d);
509 +        }
510          if (setview(&nv) != NULL)
511                  return(0);      /* illegal view */
512          dev_view(&nv);
513 <        inpresflags |= DEV_NEWVIEW;
513 >        inpresflags |= DFL(DC_SETVIEW);
514          return(1);
515   }
516  
# Line 472 | Line 519 | static
519   getmove(ebut)                           /* get view change */
520   XButtonPressedEvent     *ebut;
521   {
522 <        int     whichbutton = ebut->button;
522 >        int     movdir = MOVDIR(ebut->button);
523 >        int     movorb = MOVORB(ebut->state);
524          int     oldnodesiz = qtMinNodesiz;
525          Window  rootw, childw;
526          int     rootx, rooty, wx, wy;
# Line 488 | Line 536 | XButtonPressedEvent    *ebut;
536                                  &rootx, &rooty, &wx, &wy, &statemask))
537                          break;          /* on another screen */
538  
539 <                if (!moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton))) {
539 >                if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
540                          sleep(1);
541                          continue;
542                  }
# Line 496 | Line 544 | XButtonPressedEvent    *ebut;
544                  qtUpdate();
545                  draw_grids();
546          }
547 <        if (!(inpresflags & DEV_NEWVIEW)) {     /* do final motion */
548 <                whichbutton = levptr(XButtonReleasedEvent)->button;
547 >        if (!(inpresflags & DFL(DC_SETVIEW))) { /* do final motion */
548 >                movdir = MOVDIR(levptr(XButtonReleasedEvent)->button);
549                  wx = levptr(XButtonReleasedEvent)->x;
550                  wy = levptr(XButtonReleasedEvent)->y;
551 <                moveview(wx, odev.vres-1-wy, MOVDIR(whichbutton));
551 >                moveview(wx, odev.vres-1-wy, movdir, movorb);
552          }
553          dev_flush();
554  
# Line 525 | Line 573 | register XKeyPressedEvent  *ekey;
573          case 'H':                       /* turn off height motion lock */
574                  headlocked = 0;
575                  return;
576 <        case CTRL('S'):
576 >        case 'l':                       /* retrieve last view */
577 >                inpresflags |= DFL(DC_LASTVIEW);
578 >                return;
579          case 'p':                       /* pause computation */
580 <                inpresflags |= DEV_WAIT;
580 >                inpresflags |= DFL(DC_PAUSE);
581                  return;
582          case 'v':                       /* spit out view */
583 <                fputs(VIEWSTR, stderr);
534 <                fprintview(&odev.v, stderr);
535 <                fputc('\n', stderr);
583 >                inpresflags |= DFL(DC_GETVIEW);
584                  return;
537        case CTRL('Q'):
585          case '\n':
586          case '\r':                      /* resume computation */
587 <                inpresflags |= DEV_RESUME;
587 >                inpresflags |= DFL(DC_RESUME);
588                  return;
589          case CTRL('R'):                 /* redraw screen */
590                  if (ncolors > 0)
# Line 545 | Line 592 | register XKeyPressedEvent  *ekey;
592                  qtRedraw(0, 0, odev.hres, odev.vres);
593                  return;
594          case CTRL('L'):                 /* refresh from server */
595 <                if (inpresflags & DEV_REDRAW)
595 >                if (inpresflags & DFL(DC_REDRAW))
596                          return;
597                  XClearWindow(ourdisplay, gwind);
598                  draw_grids();
# Line 553 | Line 600 | register XKeyPressedEvent  *ekey;
600                  qtCompost(100);                 /* unload the old tree */
601                  if (ncolors > 0)
602                          new_ctab(ncolors);
603 <                inpresflags |= DEV_REDRAW;      /* resend values from server */
603 >                inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
604                  return;
605 <        case CTRL('D'):
606 <        case 'Q':
605 >        case 'K':                       /* kill rtrace process(es) */
606 >                inpresflags |= DFL(DC_KILL);
607 >                break;
608 >        case 'R':                       /* restart rtrace */
609 >                inpresflags |= DFL(DC_RESTART);
610 >                break;
611 >        case 'C':                       /* clobber holodeck */
612 >                inpresflags |= DFL(DC_CLOBBER);
613 >                break;
614          case 'q':                       /* quit the program */
615 <                inpresflags |= DEV_SHUTDOWN;
615 >                inpresflags |= DFL(DC_QUIT);
616                  return;
617          default:
618                  XBell(ourdisplay, 0);
# Line 574 | Line 628 | register XExposeEvent  *eexp;
628          if (odev.hres == 0 || odev.vres == 0) { /* first exposure */
629                  odev.hres = eexp->width;
630                  odev.vres = eexp->height;
577                inpresflags |= DEV_NEWSIZE;
631          }
632          qtRedraw(eexp->x, odev.vres - eexp->y - eexp->height,
633                          eexp->x + eexp->width, odev.vres - eexp->y);
# Line 588 | Line 641 | register XConfigureEvent  *ersz;
641          if (ersz->width == odev.hres && ersz->height == odev.vres)
642                  return;
643  
591        if (odev.hres != 0 && odev.vres != 0) {
592                odev.v.horiz = 2.*180./PI * atan(
593                        tan(PI/180./2.*odev.v.horiz) * ersz->width/odev.hres );
594                odev.v.vert = 2.*180./PI * atan(
595                        tan(PI/180./2.*odev.v.vert) * ersz->height/odev.vres );
596                inpresflags |= DEV_NEWVIEW;
597        }
644          odev.hres = ersz->width;
645          odev.vres = ersz->height;
646  
647 <        inpresflags |= DEV_NEWSIZE;
647 >        odev.v.horiz = 2.*180./PI * atan(0.5/VIEWDIST*pwidth*odev.hres);
648 >        odev.v.vert = 2.*180./PI * atan(0.5/VIEWDIST*pheight*odev.vres);
649 >
650 >        inpresflags |= DFL(DC_SETVIEW);
651   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines