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

Comparing ray/src/hd/rhdisp.c (file contents):
Revision 3.24 by gwlarson, Thu May 14 13:06:32 1998 UTC vs.
Revision 3.36 by gwlarson, Thu Dec 10 10:45:54 1998 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
18   #define VIEWHISTLEN     4       /* number of remembered views */
19   #endif
20  
21 + #ifndef FSIZDEF
22 + #define FSIZDEF         0.125   /* default focus frame size */
23 + #endif
24 +
25   HOLO    *hdlist[HDMAX+1];       /* global holodeck list */
26  
27   char    cmdlist[DC_NCMDS][8] = DC_INIT;
# Line 26 | Line 30 | int    imm_mode = 0;           /* bundles are being delivered imme
30  
31   int     do_outside = 0;         /* render from outside sections */
32  
33 + double  eyesepdist = 1;         /* eye separation distance */
34 +
35   char    *progname;              /* global argv[0] */
36  
37   FILE    *sstdin, *sstdout;      /* server's standard input and output */
# Line 86 | Line 92 | char   *argv[];
92                                  printview();
93                          if (inp & DFL(DC_LASTVIEW))
94                                  new_view(NULL);
95 <                        if (inp & DFL(DC_RESUME)) {
96 <                                serv_request(DR_NOOP, 0, NULL);
91 <                                pause = 0;
92 <                        }
93 <                        if (inp & DFL(DC_PAUSE))
94 <                                pause = 1;
95 <                        if (inp & DFL(DC_REDRAW))
96 <                                imm_mode = beam_sync(1) > 0;
95 >                        if (inp & DFL(DC_FOCUS))
96 >                                set_focus(odev_args);
97                          if (inp & DFL(DC_KILL)) {
98                                  serv_request(DR_KILL, 0, NULL);
99                                  pause = 0;
# Line 104 | Line 104 | char   *argv[];
104                                  serv_request(DR_RESTART, 0, NULL);
105                                  pause = 0;
106                          }
107 +                        if (inp & DFL(DC_RESUME)) {
108 +                                serv_request(DR_NOOP, 0, NULL);
109 +                                pause = 0;
110 +                        }
111 +                        if (inp & DFL(DC_PAUSE))
112 +                                pause = 1;
113 +                        if (inp & DFL(DC_REDRAW))
114 +                                imm_mode = beam_sync(1) > 0;
115                          if (inp & DFL(DC_QUIT))
116                                  serv_request(DR_SHUTDOWN, 0, NULL);
117                  }
118 <                if (rdy & RDY_SIN)              /* user input from sstdin */
118 >                if (rdy & RDY_SIN && !imm_mode) /* user input from sstdin */
119                          switch (usr_input()) {
120                          case DC_PAUSE:
121                                  pause = 1;
# Line 144 | Line 152 | disp_wait()                    /* wait for more input */
152          int     n;
153          register int    i;
154                                  /* see if we can avoid select call */
155 +        flgs = 0;               /* flag what's ready already */
156          if (imm_mode || stdin->_cnt > 0)
157 <                return(RDY_SRV);
157 >                flgs |= RDY_SRV;
158          if (sstdin != NULL && sstdin->_cnt > 0)
159 <                return(RDY_SIN);
160 <        if (dev_flush())
159 >                flgs |= RDY_SIN;
160 >        if (odev.inpready)
161 >                flgs |= RDY_DEV;
162 >        if (flgs)               /* got something? */
163 >                return(flgs);
164 >        if (dev_flush())        /* else flush output & check keyboard+mouse */
165                  return(RDY_DEV);
166 <                                /* make the call */
166 >                                /* if nothing, we need to call select */
167          FD_ZERO(&readset); FD_ZERO(&errset);
168          FD_SET(0, &readset);
169          FD_SET(0, &errset);
# Line 169 | Line 182 | disp_wait()                    /* wait for more input */
182                          return(0);
183                  error(SYSTEM, "select call failure in disp_wait");
184          }
172        flgs = 0;               /* flag what's ready */
185          if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset))
186                  flgs |= RDY_SRV;
187          if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset))
# Line 232 | Line 244 | register PACKHEAD      *p;
244          for (i = p->nr; i--; ) {
245                  hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r);
246                  d = hddepth(hdlist[p->hd], packra(p)[i].d);
247 <                VSUM(wp, ro, rd, d);            /* might be behind viewpoint */
248 <                dev_value(packra(p)[i].v, wp, rd);
247 >                if (d < .99*FHUGE) {
248 >                        VSUM(wp, ro, rd, d);    /* might be behind viewpoint */
249 >                        dev_value(packra(p)[i].v, rd, wp);
250 >                } else
251 >                        dev_value(packra(p)[i].v, rd, NULL);
252          }
253   #ifdef DEBUG
254          if (imm_mode) nimmrays += p->nr;
# Line 271 | Line 286 | again:
286          if (!dev_view(v))       /* notify display driver */
287                  goto again;
288          dev_flush();            /* update screen */
289 <        beam_init();            /* compute new beam set */
289 >        beam_init(0);           /* compute new beam set */
290          for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
291                  if (!beam_view(dv, res[0], res[1])) {
292                          if (!nhist) {
# Line 280 | Line 295 | again:
295                          }
296                          copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN));
297                          goto again;
298 <                }
299 <        beam_sync(0);           /* update server */
298 >                }      
299 >                                /* update server */
300 >        imm_mode = beam_sync(0) > 0;
301                                  /* record new view */
302          if (v < viewhist || v >= viewhist+VIEWHISTLEN) {
303                  copystruct(viewhist + (nhist%VIEWHISTLEN), v);
# Line 290 | Line 306 | again:
306   }
307  
308  
309 + set_focus(args)                 /* set focus frame */
310 + char    *args;
311 + {
312 +        double  hcent, vcent, hsiz, vsiz;
313 +        VIEW    *dv, vwfocus;
314 +        int     i, res[2];
315 +
316 +        i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz);
317 +        if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) {
318 +                beam_init(0);                           /* restore view */
319 +                for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
320 +                        beam_view(dv, res[0], res[1]);
321 +                beam_sync(0);                           /* update server */
322 +                return;
323 +        }
324 +        if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1)
325 +                hsiz = vsiz = FSIZDEF;                  /* gave center only */
326 +        else {
327 +                hsiz -= hcent; hcent += 0.5*hsiz;       /* gave min and max */
328 +                vsiz -= vcent; vcent += 0.5*vsiz;
329 +        }
330 +        beam_init(0);                                   /* add basic views */
331 +        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
332 +                beam_view(dv, res[0]>>4, res[1]>>4);
333 +        copystruct(&vwfocus, &odev.v);                  /* add focus view */
334 +        switch (odev.v.type) {
335 +        case VT_PER:
336 +                vwfocus.horiz = 2.*180./PI*atan(
337 +                                hsiz * tan(PI/180./2.*odev.v.horiz) );
338 +                vwfocus.vert = 2.*180./PI*atan(
339 +                                vsiz * tan(PI/180./2.*odev.v.vert) );
340 +                break;
341 +        case VT_PAR:
342 +        case VT_ANG:
343 +                vwfocus.horiz = hsiz * odev.v.horiz;
344 +                vwfocus.vert = vsiz * odev.v.vert;
345 +                break;
346 +        case VT_HEM:
347 +                vwfocus.horiz = 2.*180./PI*asin(
348 +                                hsiz * sin(PI/180./2.*odev.v.horiz) );
349 +                vwfocus.vert = 2.*180./PI*asin(
350 +                                vsiz * sin(PI/180./2.*odev.v.vert) );
351 +                break;
352 +        case VT_CYL:
353 +                vwfocus.horiz = hsiz * odev.v.horiz;
354 +                vwfocus.vert = 2.*180./PI*atan(
355 +                                vsiz * tan(PI/180./2.*odev.v.vert) );
356 +                break;
357 +        default:
358 +                error(INTERNAL, "bad view type in set_focus");
359 +        }
360 +        vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz;
361 +        vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz;
362 +        setview(&vwfocus);
363 +        beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100,
364 +                        (int)(3*odev.vres*vsiz)+100);
365 +        beam_sync(0);                                   /* update server */
366 + }
367 +
368 +
369   int
370   usr_input()                     /* get user input and process it */
371   {
# Line 301 | Line 377 | usr_input()                    /* get user input and process it */
377          if (fgets(cmd, sizeof(cmd), sstdin) == NULL) {
378                  fclose(sstdin);
379                  sstdin = NULL;
380 <                return(0);
380 >                return(-1);
381          }
382 +        if (*cmd == '\n')
383 +                return(DC_RESUME);
384          for (args = cmd; *args && !isspace(*args); args++)
385                  ;
386          while (isspace(*args))
387                  *args++ = '\0';
310        if (!*cmd)
311                return(DC_RESUME);
388          if (*args && args[i=strlen(args)-1] == '\n')
389                  args[i] = '\0';
390          for (i = 0; i < DC_NCMDS; i++)
391                  if (!strcmp(cmd, cmdlist[i]))
392                          break;
393          if (i >= DC_NCMDS) {
394 <                sprintf(errmsg, "unknown command: %s", cmd);
319 <                error(COMMAND, errmsg);
394 >                dev_auxcom(cmd, args);
395                  return(-1);
396          }
397          switch (i) {
# Line 333 | Line 408 | usr_input()                    /* get user input and process it */
408          case DC_LASTVIEW:               /* restore previous view */
409                  new_view(NULL);
410                  break;
411 +        case DC_FOCUS:                  /* set focus frame */
412 +                set_focus(args);
413 +                break;
414          case DC_PAUSE:                  /* pause the current calculation */
415          case DC_RESUME:                 /* resume the calculation */
416                  /* handled in main() */
# Line 405 | Line 483 | serv_result()                  /* get next server result and process
483                  break;
484          case DS_OUTSECT:
485                  do_outside = 1;
486 +                goto noargs;
487 +        case DS_EYESEP:
488 +                if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY)
489 +                        error(INTERNAL, "bad eye separation from server");
490                  break;
491          case DS_STARTIMM:
492          case DS_ENDIMM:
493   #ifdef DEBUG
494 <                if (imm_mode != (msg.type==DS_STARTIMM)) {
494 >                {
495                          time_t  tnow = time(NULL);
496 <                        if (imm_mode) timm += tnow - tmodesw;
497 <                        else tadd += tnow - tmodesw;
496 >                        if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw;
497 >                        else timm += tnow - tmodesw;
498                          tmodesw = tnow;
499                  }
500   #endif
501 <                imm_mode = msg.type==DS_STARTIMM;
502 <                /* fall through */
501 >                if (!(imm_mode = msg.type==DS_STARTIMM))
502 >                        dev_flush();
503 >                goto noargs;
504          case DS_ACKNOW:
505          case DS_SHUTDOWN:
506 <                if (msg.nbytes) {
424 <                        sprintf(errmsg,
425 <                                "unexpected body with server message %d",
426 <                                        msg.type);
427 <                        error(INTERNAL, errmsg);
428 <                }
429 <                break;
506 >                goto noargs;
507          default:
508                  error(INTERNAL, "unrecognized result from server process");
509          }
510          return(msg.type);               /* return message type */
511 + noargs:
512 +        if (msg.nbytes) {
513 +                sprintf(errmsg, "unexpected body with server message %d",
514 +                                msg.type);
515 +                error(INTERNAL, errmsg);
516 +        }
517 +        return(msg.type);
518   readerr:
519          if (feof(stdin))
520                  error(SYSTEM, "server process died");
# Line 444 | Line 528 | char   *p;
528   {
529          MSGHEAD msg;
530          int     m;
531 +                                /* consistency checks */
532 + #ifdef DEBUG
533 +        if (nbytes < 0 || nbytes > 0 & p == NULL)
534 +                error(CONSISTENCY, "bad buffer handed to serv_request");
535 + #endif
536                                  /* get server's attention for big request */
537          if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) {
538                  serv_request(DR_ATTEN, 0, NULL);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines