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

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.44 by gwlarson, Wed Jun 17 13:29:55 1998 UTC vs.
Revision 2.46 by gwlarson, Sun Jan 10 12:45:19 1999 UTC

# Line 124 | Line 124 | double  newa;
124   setambient(afile)                       /* initialize calculation */
125   char  *afile;
126   {
127 +        int     readonly = 0;
128          long  pos, flen;
129          AMBVAL  amb;
130                                                  /* init ambient limits */
# Line 138 | Line 139 | char  *afile;
139                  return;
140          }
141                                                  /* open ambient file */
142 <        if ((ambfp = fopen(afile, "r+")) != NULL) {
143 <                initambfile(0);
142 >        if ((ambfp = fopen(afile, "r+")) == NULL)
143 >                readonly = (ambfp = fopen(afile, "r")) != NULL;
144 >        if (ambfp != NULL) {
145 >                initambfile(0);                 /* file exists */
146                  pos = ftell(ambfp);
147                  while (readambval(&amb, ambfp))
148                          avinsert(avstore(&amb));
149 <                                                /* align */
149 >                nambshare = nambvals;           /* share loaded values */
150 >                if (readonly) {
151 >                        sprintf(errmsg,
152 >                                "loaded %u values from read-only ambient file",
153 >                                        nambvals);
154 >                        error(WARNING, errmsg);
155 >                        fclose(ambfp);          /* close file so no writes */
156 >                        ambfp = NULL;
157 >                        return;                 /* avoid ambsync() */
158 >                }
159 >                                                /* align file pointer */
160                  pos += (long)nambvals*AMBVALSIZ;
161                  flen = lseek(fileno(ambfp), 0L, 2);
162                  if (flen != pos) {
# Line 154 | Line 167 | char  *afile;
167                          fseek(ambfp, pos, 0);
168                          ftruncate(fileno(ambfp), pos);
169                  }
170 <                nambshare = nambvals;
171 <        } else if ((ambfp = fopen(afile, "w+")) != NULL)
172 <                initambfile(1);
160 <        else {
170 >        } else if ((ambfp = fopen(afile, "w+")) != NULL) {
171 >                initambfile(1);                 /* else create new file */
172 >        } else {
173                  sprintf(errmsg, "cannot open ambient file \"%s\"", afile);
174                  error(SYSTEM, errmsg);
175          }
# Line 377 | Line 389 | COLOR  cr;
389   register AMBVAL  *ap;
390   FVECT  pv, nv;
391   {
392 <        FVECT  v1, v2;
392 >        FVECT  v1;
393          register int  i;
394          double  d;
395  
# Line 386 | Line 398 | FVECT  pv, nv;
398          for (i = 0; i < 3; i++)
399                  d += ap->gpos[i]*(pv[i]-ap->pos[i]);
400                                          /* gradient due to rotation */
401 <        VCOPY(v1, ap->dir);
402 <        fcross(v2, v1, nv);
391 <        d += DOT(ap->gdir, v2);
401 >        VCROSS(v1, ap->dir, nv);
402 >        d += DOT(ap->gdir, v1);
403          if (d <= 0.0) {
404                  setcolor(cr, 0.0, 0.0, 0.0);
405                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines