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.27 by gwlarson, Sun Jan 3 13:40:25 1999 UTC vs.
Revision 3.28 by gwlarson, Thu Jun 10 15:22:21 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1998 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 22 | Line 22 | static char SCCSid[] = "$SunId$ SGI";
22  
23   #include "standard.h"
24  
25 #include <sys/types.h>
25   #include <GL/glx.h>
26   #include <GL/glu.h>
27   #ifdef STEREO
# Line 54 | Line 53 | static char SCCSid[] = "$SunId$ SGI";
53   #define MOVORB(s)       ((s)&ShiftMask ? 1 : (s)&ControlMask ? -1 : 0)
54  
55   #ifndef TARGETFPS
56 < #define TARGETFPS       4.0             /* target frames/sec during motion */
56 > #define TARGETFPS       2.0             /* target frames/sec during motion */
57   #endif
58  
59   #define MINWIDTH        480             /* minimum graphics window width */
# Line 111 | Line 110 | static int  resizewindow(), getevent(), getkey(), move
110   #ifdef STEREO
111   static int  pushright(), popright();
112   #endif
113 + static double   getdistance();
114 + #define mapdepth(d) ((d)> 0.9995 ? FHUGE: dev_zmin/ \
115 +                     (1.-(d)*(1.-dev_zmin/dev_zmax)))
116  
117   extern time_t   time();
118  
# Line 261 | Line 263 | dev_close()                    /* close our display and free resources
263   dev_clear()                     /* clear our representation */
264   {
265          smInit(rsL.max_samp);
266 <        wipeclean();
266 >        wipeclean(1);
267          rayqleft = 0;                   /* hold off update */
268   }
269  
# Line 315 | Line 317 | register VIEW  *nv;
317          VSUM(vwright.vp, nv->vp, nv->hvec, d);
318          /* setview(&vwright);   -- Unnecessary */
319   #endif
320 <        wipeclean();
320 >        wipeclean(0);
321          return(1);
322   }
323  
# Line 405 | Line 407 | dev_flush()                    /* flush output */
407          if (mapped) {
408   #ifdef STEREO
409                  pushright();                    /* update right eye */
410 <                smUpdate(&vwright, 100);
410 >                smUpdate(&vwright, MAXQUALITY);
411   #ifdef DOBJ
412                  dobj_render();                  /* usually in foreground */
413   #endif
414                  popright();                     /* update left eye */
415   #endif
416 <                smUpdate(&odev.v, 100);
416 >                smUpdate(&odev.v, MAXQUALITY);
417                  checkglerr("rendering mesh");
418   #ifdef DOBJ
419                  dobj_render();
# Line 533 | Line 535 | int    fore;
535          checkglerr("drawing grid lines");
536   }
537  
538 + static double
539 + getdistance(dx, dy, direc)      /* distance from fore plane along view ray */
540 + int     dx, dy;
541 + FVECT   direc;
542 + {
543 +        GLfloat gldepth;
544 +        double  dist;
545  
546 +        if (dx<0 | dx>=odev.hres | dy<0 | dy>=odev.vres)
547 +                return(FHUGE);
548 +        glReadPixels(dx,dy, 1,1, GL_DEPTH_COMPONENT,GL_FLOAT, &gldepth);
549 +        dist = mapdepth(gldepth);
550 +        if (dist >= .99*FHUGE)
551 +                return(FHUGE);
552 +        return((dist-odev.v.vfore)/DOT(direc,odev.v.vdir));
553 + }
554 +
555 +
556   static
557   moveview(dx, dy, mov, orb)      /* move our view */
558   int     dx, dy, mov, orb;
559   {
560          VIEW    nv;
561          FVECT   odir, v1, wip;
562 <        double  d;
562 >        double  d,d1;
563          register int    li;
564                                  /* start with old view */
565          copystruct(&nv, &odev.v);
# Line 549 | Line 568 | int    dx, dy, mov, orb;
568                          (dx+.5)/odev.hres, (dy+.5)/odev.vres) < -FTINY)
569                  return(0);              /* outside view */
570          if (mov | orb) {        /* moving relative to geometry */
571 +                d = getdistance(dx, dy, odir);/*distance from front plane */
572   #ifdef DOBJ
573 <                d = dobj_trace(NULL, v1, odir); /* check objects */
573 >                d1 = dobj_trace(NULL, v1, odir);        /* check objects */
574                                                  /* check holodeck */
575 <                if ((li = smFindSamp(v1, odir)) >= 0) {
576 <                        VCOPY(wip, rsL.wp[li]);
557 <                        if (d < .99*FHUGE && d*d <= dist2(v1, wip))
558 <                                li = -1;        /* object is closer */
559 <                } else if (d >= .99*FHUGE)
560 <                        return(0);              /* nothing visible */
561 <                if (li < 0)
562 <                        VSUM(wip, v1, odir, d); /* else get object point */
563 < #else
564 <                if ((li = smFindSamp(v1, odir)) < 0)
565 <                        return(0);      /* not on window */
566 <                VCOPY(wip, rsL.wp[li]);
575 >                if (d1 < d)
576 >                        d = d1;
577   #endif
578 < #ifdef DEBUG
578 >                if (d >= .99*FHUGE)
579 >                        d = 0.5*(dev_zmax+dev_zmin);    /* just guess */
580 >                VSUM(wip, v1, odir, d);
581 >                VSUB(odir, wip, odev.v.vp);
582 > #if 0
583                  fprintf(stderr, "moveview: hit %s at (%f,%f,%f) (t=%f)\n",
584                                  li < 0 ? "object" : "mesh",
585                                  wip[0], wip[1], wip[2],
# Line 573 | Line 587 | int    dx, dy, mov, orb;
587                                  (wip[1]-odev.v.vp[1])*odir[1] +
588                                  (wip[2]-odev.v.vp[2])*odir[2]);
589   #endif
576                VSUM(odir, wip, odev.v.vp, -1.);
590          } else                  /* panning with constant viewpoint */
591                  VCOPY(nv.vdir, odir);
592          if (orb && mov) {               /* orbit left/right */
# Line 633 | Line 646 | XButtonPressedEvent    *ebut;
646   {
647          int     movdir = MOVDIR(ebut->button);
648          int     movorb = MOVORB(ebut->state);
649 <        int     qlevel = 99;
649 >        int     qlevel = MAXQUALITY-1;
650          time_t  lasttime, thistime;
651          int     nframes;
652          Window  rootw, childw;
# Line 642 | Line 655 | XButtonPressedEvent    *ebut;
655  
656          XNoOp(ourdisplay);              /* makes sure we're not idle */
657  
658 <        lasttime = time(0); nframes = 0;
658 >        nframes = 0;
659          while (!XCheckMaskEvent(ourdisplay,
660                          ButtonReleaseMask, levptr(XEvent))) {
661                                          /* get cursor position */
# Line 676 | Line 689 | XButtonPressedEvent    *ebut;
689                  dobj_render();          /* redraw object */
690   #endif
691                  glFlush();
692 <                nframes++;              /* figure out good quality level */
692 >                                        /* figure out good quality level */
693 >                if (!nframes++) {               /* ignore first frame */
694 >                        lasttime = time(0);
695 >                        continue;
696 >                }
697                  thistime = time(0);
698 <                if (thistime - lasttime >= 3 ||
698 >                if (thistime - lasttime >= 6 ||
699                                  nframes > (int)(3*3*TARGETFPS)) {
700 <                        qlevel = thistime<=lasttime ? 1000 :
700 >                        qlevel = thistime<=lasttime ? 3*MAXQUALITY :
701                                  (int)((double)nframes/(thistime-lasttime)
702                                          / TARGETFPS * qlevel + 0.5);
703 <                        lasttime = thistime; nframes = 0;
704 <                        if (qlevel > 99) {
705 <                                if (qlevel > 300) {     /* put on the brakes */
703 >                        nframes = 0;
704 >                        if (qlevel >= MAXQUALITY) {
705 >                                if (qlevel >= 3*MAXQUALITY) {   /* brakes!! */
706                                          sleep(1);
707                                          lasttime++;
708                                  }
709 <                                qlevel = 99;
709 >                                qlevel = MAXQUALITY-1;
710                          } else if (qlevel < 1)
711                                  qlevel = 1;
712                  }
# Line 713 | Line 730 | register VIEW  *vp;
730                  dev_zmin = 1.;
731                  dev_zmax = 100.;
732          } else {
733 <                dev_zmin = 0.5*mindpth;
733 >                dev_zmin = 0.1*mindpth;
734                  dev_zmax = 5.0*maxdpth;
735          }
736          if (odev.v.vfore > FTINY)
737                  dev_zmin = odev.v.vfore;
738          if (odev.v.vaft > FTINY)
739                  dev_zmax = odev.v.vaft;
740 <        if (dev_zmin < dev_zmax/100.)
741 <                dev_zmin = dev_zmax/100.;
740 >        if (dev_zmin < dev_zmax/500.)
741 >                dev_zmin = dev_zmax/500.;
742          xmax = dev_zmin * tan(PI/180./2. * odev.v.horiz);
743          xmin = -xmax;
744          d = odev.v.hoff * (xmax - xmin);
# Line 744 | Line 761 | register VIEW  *vp;
761  
762  
763   static
764 < wipeclean()                     /* prepare for redraw */
764 > wipeclean(tmflag)                       /* prepare for redraw */
765 > int     tmflag;
766   {
767                                          /* clear depth buffer */
768   #ifdef STEREO
# Line 753 | Line 771 | wipeclean()                    /* prepare for redraw */
771          setstereobuf(STEREO_BUFFER_LEFT);
772   #endif
773          glClear(GL_DEPTH_BUFFER_BIT);
774 <        smClean();                      /* reset drawing routines */
774 >        smClean(tmflag);                /* reset drawing routines */
775          setglpersp(&odev.v);            /* reset view & clipping planes */
776   }
777  
# Line 804 | Line 822 | register XKeyPressedEvent  *ekey;
822                  inpresflags |= DFL(DC_RESUME);
823                  return;
824          case CTRL('R'):                 /* redraw screen */
825 <                wipeclean();
825 >                wipeclean(1);
826                  return;
827          case CTRL('L'):                 /* refresh from server */
828                  if (inpresflags & DFL(DC_REDRAW))
# Line 854 | Line 872 | register XExposeEvent  *eexp;
872          }
873          if (eexp->count)                /* wait for final exposure */
874                  return;
875 <        wipeclean();                    /* clear depth */
875 >        wipeclean(0);                   /* clear depth */
876   }
877  
878  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines