Back to index

radiance  4R0+20100331
vwright.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: vwright.c,v 2.8 2009/06/14 00:33:16 greg Exp $";
00003 #endif
00004 /*
00005  * Move a viewpoint the given distance to the right
00006  */
00007 
00008 
00009 #include "standard.h"
00010 
00011 #include "view.h"
00012 
00013 #include <ctype.h>
00014 
00015 VIEW   vw = STDVIEW;
00016 
00017 char   *progname;
00018 
00019 
00020 int
00021 main(
00022        int    argc,
00023        char   *argv[]
00024 )
00025 {
00026        char   linebuf[256];
00027        char   *err;
00028        int    gotview = 0;
00029        FVECT  hvn, vvn;
00030        double dist;
00031        register int  i;
00032 
00033        progname = argv[0];
00034        ++argv; --argc;
00035        while (argc && argv[0][0] == '-' && argv[0][1] == 'v') {
00036               int    rv;
00037               if (argc > 2 && argv[0][2] == 'f') {
00038                      rv = viewfile(argv[1], &vw, NULL);
00039                      if (rv <= 0) {
00040                             fprintf(stderr, "%s: %s file '%s'\n",
00041                                           progname,
00042                                           rv < 0 ? "cannot open view" :
00043                                           "no view in", argv[1]);
00044                             exit(1);
00045                      }
00046                      ++gotview;
00047                      ++argv; --argc;
00048               } else {
00049                      rv = getviewopt(&vw, argc, argv);
00050                      if (rv < 0) {
00051                             fprintf(stderr, "%s: bad view option at '%s'\n",
00052                                           progname, argv[0]);
00053                             exit(1);
00054                      }
00055                      ++gotview;
00056                      argv += rv; argc -= rv;
00057               }
00058               ++argv; --argc;
00059        }
00060        if (argc != 1)
00061               goto userr;
00062        if (!gotview)
00063               while (fgets(linebuf, sizeof(linebuf), stdin) != NULL) {
00064                      if (linebuf[0] == '\n')
00065                             break;
00066                      if (isview(linebuf) && sscanview(&vw, linebuf) > 0)
00067                             ++gotview;
00068               }
00069        if (!gotview) {
00070               fprintf(stderr, "%s: no view on standard input\n", progname);
00071               exit(1);
00072        }
00073        if ((err= setview(&vw)) != NULL) {
00074               fprintf(stderr, "%s: %s\n", progname, err);
00075               exit(1);
00076        }
00077        VCOPY(hvn, vw.hvec);
00078        normalize(hvn);
00079        VCOPY(vvn, vw.vvec);
00080        normalize(vvn);
00081        if (isalpha(argv[0][0])) {  /* print out variables */
00082               switch (vw.type) {
00083                      case VT_PER: i=1; break;
00084                      case VT_PAR: i=2; break;
00085                      case VT_ANG: i=3; break;
00086                      case VT_HEM: i=4; break;
00087                      case VT_CYL: i=5; break;
00088                      case VT_PLS: i=6; break;
00089                      default: i=0; break;
00090               }
00091               printf("%st:%d;", argv[0], i);
00092               printf("%spx:%g;%spy:%g;%spz:%g;", argv[0], vw.vp[0],
00093                             argv[0], vw.vp[1], argv[0], vw.vp[2]);
00094               printf("%sdx:%g;%sdy:%g;%sdz:%g;", argv[0], vw.vdir[0],
00095                             argv[0], vw.vdir[1], argv[0], vw.vdir[2]);
00096               printf("%sd:%g;", argv[0], vw.vdist);
00097               printf("%sux:%g;%suy:%g;%suz:%g;", argv[0], vw.vup[0],
00098                             argv[0], vw.vup[1], argv[0], vw.vup[2]);
00099               printf("%sh:%g;%sv:%g;", argv[0], vw.horiz,
00100                             argv[0], vw.vert);
00101               printf("%ss:%g;%sl:%g;%so:%g;%sa:%g;",
00102                             argv[0], vw.hoff, argv[0], vw.voff,
00103                             argv[0], vw.vfore, argv[0], vw.vaft);
00104               printf("%shx:%g;%shy:%g;%shz:%g;%shn:%g;",
00105                             argv[0], hvn[0], argv[0], hvn[1],
00106                             argv[0], hvn[2], argv[0], sqrt(vw.hn2));
00107               printf("%svx:%g;%svy:%g;%svz:%g;%svn:%g;\n",
00108                             argv[0], vvn[0], argv[0], vvn[1],
00109                             argv[0], vvn[2], argv[0], sqrt(vw.vn2));
00110               exit(0);
00111        }
00112        if (!isflt(argv[0]))
00113               goto userr;
00114        dist = atof(argv[0]);
00115        for (i = 0; i < 3; i++)
00116               vw.vp[i] += dist*hvn[i];
00117        fprintview(&vw, stdout);
00118        putchar('\n');
00119        exit(0);
00120 userr:
00121        fprintf(stderr, "Usage: %s {offset|name}\n", progname);
00122        exit(1);
00123 }