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

Comparing ray/src/hd/rhd_glx.c (file contents):
Revision 3.22 by gwlarson, Tue Aug 25 18:11:17 1998 UTC vs.
Revision 3.27 by gwlarson, Sun Jan 3 13:40:25 1999 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ SGI";
21   #endif
22  
23   #include "standard.h"
24 #include "rhd_sample.h"
24  
25   #include <sys/types.h>
26   #include <GL/glx.h>
# Line 29 | Line 28 | static char SCCSid[] = "$SunId$ SGI";
28   #ifdef STEREO
29   #include <X11/extensions/SGIStereo.h>
30   #endif
31 +
32 + #include "rhd_sample.h"
33   #ifdef DOBJ
34   #include "rhdobj.h"
35   #endif
# Line 36 | Line 37 | static char SCCSid[] = "$SunId$ SGI";
37   #include "x11icon.h"
38  
39   #ifndef RAYQLEN
40 < #define RAYQLEN         250             /* max. rays to queue before flush */
40 > #define RAYQLEN         1024            /* max. rays to queue before flush */
41   #endif
42  
43   #ifndef FEQ
# Line 45 | Line 46 | static char SCCSid[] = "$SunId$ SGI";
46  
47   #define GAMMA           1.4             /* default gamma correction */
48  
49 + #define FRAMESTATE(s)   (((s)&(ShiftMask|ControlMask))==(ShiftMask|ControlMask))
50 +
51   #define MOVPCT          7               /* percent distance to move /frame */
52   #define MOVDIR(b)       ((b)==Button1 ? 1 : (b)==Button2 ? 0 : -1)
53   #define MOVDEG          (-5)            /* degrees to orbit CW/down /frame */
# Line 74 | Line 77 | static char SCCSid[] = "$SunId$ SGI";
77  
78   struct driver   odev;                   /* global device driver structure */
79  
80 + char odev_args[64];                     /* command arguments */
81 +
82 + #ifdef STEREO
83   static VIEW     vwright;                /* right eye view */
84 + #endif
85  
86   static int      rayqleft = 0;           /* rays left to queue before flush */
87  
# Line 99 | Line 106 | static int     inpresflags;            /* input result flags */
106   static int      headlocked = 0;         /* lock vertical motion */
107  
108   static int  resizewindow(), getevent(), getkey(), moveview(), wipeclean(),
109 <                setglpersp(), getmove(), fixwindow(), mytmflags();
109 >                setglpersp(), getframe(), getmove(), fixwindow(), mytmflags();
110  
111   #ifdef STEREO
112   static int  pushright(), popright();
# Line 216 | Line 223 | char  *id;
223          pheight *= 2.;
224          setstereobuf(STEREO_BUFFER_LEFT);
225   #endif
226 +        checkglerr("setting rendering parameters");
227          copystruct(&odev.v, &stdview);
228          odev.v.type = VT_PER;
229                                          /* map the window */
# Line 300 | Line 308 | register VIEW  *nv;
308                          dev_input();    /* get resize event */
309                  }
310                  copystruct(&odev.v, nv);        /* setview() already called */
311 +        }
312   #ifdef STEREO
313 <                copystruct(&vwright, nv);
314 <                d = eyesepdist / sqrt(nv->hn2);
315 <                VSUM(vwright.vp, nv->vp, nv->hvec, d);
316 <                /* setview(&vwright);   -- Unnecessary */
313 >        copystruct(&vwright, nv);
314 >        d = eyesepdist / sqrt(nv->hn2);
315 >        VSUM(vwright.vp, nv->vp, nv->hvec, d);
316 >        /* setview(&vwright);   -- Unnecessary */
317   #endif
309        }
318          wipeclean();
319          return(1);
320   }
321  
322  
323 + dev_section(gfn, pfn)           /* add octree for geometry rendering */
324 + char    *gfn, *pfn;
325 + {
326 +        /* unimplemented */
327 + }
328 +
329 +
330   dev_auxcom(cmd, args)           /* process an auxiliary command */
331   char    *cmd, *args;
332   {
# Line 390 | Line 405 | dev_flush()                    /* flush output */
405          if (mapped) {
406   #ifdef STEREO
407                  pushright();                    /* update right eye */
393                glClear(GL_DEPTH_BUFFER_BIT);
408                  smUpdate(&vwright, 100);
409   #ifdef DOBJ
410                  dobj_render();                  /* usually in foreground */
411   #endif
412                  popright();                     /* update left eye */
399                glClear(GL_DEPTH_BUFFER_BIT);
413   #endif
414                  smUpdate(&odev.v, 100);
415                  checkglerr("rendering mesh");
# Line 435 | Line 448 | pushright()                    /* push on right view */
448          glPushMatrix();
449          d = -eyesepdist / sqrt(odev.v.hn2);
450          glTranslated(d*odev.v.hvec[0], d*odev.v.hvec[1], d*odev.v.hvec[2]);
451 +        checkglerr("setting right view");
452   }
453  
454  
# Line 487 | Line 501 | getevent()                     /* get next event */
501                  getkey(levptr(XKeyPressedEvent));
502                  break;
503          case ButtonPress:
504 <                getmove(levptr(XButtonPressedEvent));
504 >                if (FRAMESTATE(levptr(XButtonPressedEvent)->state))
505 >                        getframe(levptr(XButtonPressedEvent));
506 >                else
507 >                        getmove(levptr(XButtonPressedEvent));
508                  break;
509          }
510   }
# Line 506 | Line 523 | static
523   draw_grids(fore)                /* draw holodeck section grids */
524   int     fore;
525   {
509        if (!mapped)
510                return;
526          if (fore)
527                  glColor4ub(0, 255, 255, 0);
528          else
# Line 515 | Line 530 | int    fore;
530          glBegin(GL_LINES);              /* draw each grid line */
531          gridlines(draw3dline);
532          glEnd();
533 +        checkglerr("drawing grid lines");
534   }
535  
536  
# Line 549 | Line 565 | int    dx, dy, mov, orb;
565                          return(0);      /* not on window */
566                  VCOPY(wip, rsL.wp[li]);
567   #endif
568 + #ifdef DEBUG
569 +                fprintf(stderr, "moveview: hit %s at (%f,%f,%f) (t=%f)\n",
570 +                                li < 0 ? "object" : "mesh",
571 +                                wip[0], wip[1], wip[2],
572 +                                (wip[0]-odev.v.vp[0])*odir[0] +
573 +                                (wip[1]-odev.v.vp[1])*odir[1] +
574 +                                (wip[2]-odev.v.vp[2])*odir[2]);
575 + #endif
576                  VSUM(odir, wip, odev.v.vp, -1.);
577          } else                  /* panning with constant viewpoint */
578                  VCOPY(nv.vdir, odir);
# Line 581 | Line 605 | int    dx, dy, mov, orb;
605  
606  
607   static
608 + getframe(ebut)                          /* get focus frame */
609 + XButtonPressedEvent     *ebut;
610 + {
611 +        int     startx = ebut->x, starty = ebut->y;
612 +        int     endx, endy;
613 +
614 +        XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent));
615 +        endx = levptr(XButtonReleasedEvent)->x;
616 +        endy = levptr(XButtonReleasedEvent)->y;
617 +        if (endx == startx | endy == starty) {
618 +                XBell(ourdisplay, 0);
619 +                return;
620 +        }
621 +        if (endx < startx) {register int c = endx; endx = startx; startx = c;}
622 +        if (endy < starty) {register int c = endy; endy = starty; starty = c;}
623 +        sprintf(odev_args, "%.3f %.3f %.3f %.3f",
624 +                        (startx+.5)/odev.hres, 1.-(endy+.5)/odev.vres,
625 +                        (endx+.5)/odev.hres, 1.-(starty+.5)/odev.vres);
626 +        inpresflags |= DFL(DC_FOCUS);
627 + }
628 +
629 +
630 + static
631   getmove(ebut)                           /* get view change */
632   XButtonPressedEvent     *ebut;
633   {
# Line 593 | Line 640 | XButtonPressedEvent    *ebut;
640          int     rootx, rooty, wx, wy;
641          unsigned int    statemask;
642  
643 <        XNoOp(ourdisplay);
643 >        XNoOp(ourdisplay);              /* makes sure we're not idle */
644  
645          lasttime = time(0); nframes = 0;
646          while (!XCheckMaskEvent(ourdisplay,
647                          ButtonReleaseMask, levptr(XEvent))) {
648 <
648 >                                        /* get cursor position */
649                  if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
650                                  &rootx, &rooty, &wx, &wy, &statemask))
651                          break;          /* on another screen */
652  
653                  draw_grids(0);          /* clear old grid lines */
654 + #ifdef STEREO
655 +                pushright(); draw_grids(0); popright();
656 + #endif
657 +                                        /* compute view motion */
658                  if (!moveview(wx, odev.vres-1-wy, movdir, movorb)) {
659                          sleep(1);
660                          lasttime++;
661 <                        continue;
661 >                        continue;       /* cursor in bad place */
662                  }
663 +                draw_grids(1);          /* redraw grid */
664   #ifdef STEREO
665                  pushright();
666                  draw_grids(1);
# Line 618 | Line 670 | XButtonPressedEvent    *ebut;
670   #endif
671                  popright();
672   #endif
673 <                draw_grids(1);
673 >                                        /* redraw mesh */
674                  smUpdate(&odev.v, qlevel);
675   #ifdef DOBJ
676 <                dobj_render();
676 >                dobj_render();          /* redraw object */
677   #endif
678                  glFlush();
679 <                checkglerr("moving view");
628 <                nframes++;
679 >                nframes++;              /* figure out good quality level */
680                  thistime = time(0);
681                  if (thistime - lasttime >= 3 ||
682                                  nframes > (int)(3*3*TARGETFPS)) {
# Line 659 | Line 710 | register VIEW  *vp;
710          double  d, xmin, xmax, ymin, ymax;
711  
712          if (mindpth >= maxdpth) {
713 <                dev_zmin = 0.1;
713 >                dev_zmin = 1.;
714                  dev_zmax = 100.;
715          } else {
716                  dev_zmin = 0.5*mindpth;
717 <                dev_zmax = 1.5*maxdpth;
667 <                if (dev_zmin > dev_zmax/100.)
668 <                        dev_zmin = dev_zmax/100.;
717 >                dev_zmax = 5.0*maxdpth;
718          }
719          if (odev.v.vfore > FTINY)
720                  dev_zmin = odev.v.vfore;
721          if (odev.v.vaft > FTINY)
722                  dev_zmax = odev.v.vaft;
723 <        if (dev_zmin < dev_zmax/5000.)
724 <                dev_zmin = dev_zmax/5000.;
723 >        if (dev_zmin < dev_zmax/100.)
724 >                dev_zmin = dev_zmax/100.;
725          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
726          xmin = -xmax;
727          d = odev.v.hoff * (xmax - xmin);
# Line 690 | Line 739 | register VIEW  *vp;
739                  odev.v.vp[1] + odev.v.vdir[1],
740                  odev.v.vp[2] + odev.v.vdir[2],
741                  odev.v.vup[0], odev.v.vup[1], odev.v.vup[2]);
742 +        checkglerr("setting perspective view");
743   }
744  
745  
# Line 712 | Line 762 | static
762   getkey(ekey)                            /* get input key */
763   register XKeyPressedEvent  *ekey;
764   {
765 +        Window  rootw, childw;
766 +        int     rootx, rooty, wx, wy;
767 +        unsigned int    statemask;
768          int  n;
769          char    buf[8];
770  
# Line 734 | Line 787 | register XKeyPressedEvent  *ekey;
787          case 'v':                       /* spit out view */
788                  inpresflags |= DFL(DC_GETVIEW);
789                  return;
790 +        case 'f':                       /* frame view position */
791 +                if (!XQueryPointer(ourdisplay, gwind, &rootw, &childw,
792 +                                &rootx, &rooty, &wx, &wy, &statemask))
793 +                        return;         /* on another screen */
794 +                sprintf(odev_args, "%.4f %.4f", (wx+.5)/odev.hres,
795 +                                1.-(wy+.5)/odev.vres);
796 +                inpresflags |= DFL(DC_FOCUS);
797 +                return;
798 +        case 'F':                       /* unfocus */
799 +                odev_args[0] = '\0';
800 +                inpresflags |= DFL(DC_FOCUS);
801 +                return;
802          case '\n':
803          case '\r':                      /* resume computation */
804                  inpresflags |= DFL(DC_RESUME);
# Line 744 | Line 809 | register XKeyPressedEvent  *ekey;
809          case CTRL('L'):                 /* refresh from server */
810                  if (inpresflags & DFL(DC_REDRAW))
811                          return;
812 +                setglpersp(&odev.v);            /* reset clipping planes */
813                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
814 <                glDisable(GL_DEPTH_TEST);
814 >                glDisable(GL_DEPTH_TEST);       /* so grids will clear */
815                  draw_grids(1);
816   #ifdef STEREO
817                  pushright();
# Line 757 | Line 823 | register XKeyPressedEvent  *ekey;
823                  glFlush();
824                  smInit(rsL.max_samp);           /* get rid of old values */
825                  inpresflags |= DFL(DC_REDRAW);  /* resend values from server */
760                setglpersp(&odev.v);            /* reset clipping planes */
826                  rayqleft = 0;                   /* hold off update */
827                  return;
828          case 'K':                       /* kill rtrace process(es) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines