| 1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Read and write portable ambient values |
| 6 |
+ |
* |
| 7 |
+ |
* Declarations of external symbols in ambient.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include <stdio.h> |
| 10 |
> |
#include "copyright.h" |
| 11 |
|
|
| 12 |
< |
#include "color.h" |
| 12 |
> |
#include "ray.h" |
| 13 |
|
|
| 14 |
|
#include "ambient.h" |
| 15 |
|
|
| 18 |
|
|
| 19 |
|
#define getvec(v,fp) (v)[0]=getflt(fp);(v)[1]=getflt(fp);(v)[2]=getflt(fp) |
| 20 |
|
|
| 21 |
+ |
#define badflt(x) ((x) < -FHUGE || (x) > FHUGE) |
| 22 |
|
|
| 23 |
< |
extern double getflt(); |
| 24 |
< |
extern long getint(); |
| 23 |
> |
#define badvec(v) (badflt((v)[0]) || badflt((v)[1]) || badflt((v)[2])) |
| 24 |
|
|
| 25 |
|
|
| 26 |
+ |
|
| 27 |
+ |
void |
| 28 |
+ |
putambmagic(fp) /* write out ambient value magic number */ |
| 29 |
+ |
FILE *fp; |
| 30 |
+ |
{ |
| 31 |
+ |
putint((long)AMBMAGIC, 2, fp); |
| 32 |
+ |
} |
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+ |
int |
| 36 |
+ |
hasambmagic(fp) /* read in and check validity of magic # */ |
| 37 |
+ |
FILE *fp; |
| 38 |
+ |
{ |
| 39 |
+ |
register int magic; |
| 40 |
+ |
|
| 41 |
+ |
magic = getint(2, fp); |
| 42 |
+ |
if (feof(fp)) |
| 43 |
+ |
return(0); |
| 44 |
+ |
return(magic == AMBMAGIC); |
| 45 |
+ |
} |
| 46 |
+ |
|
| 47 |
+ |
|
| 48 |
+ |
int |
| 49 |
|
writambval(av, fp) /* write ambient value to stream */ |
| 50 |
|
register AMBVAL *av; |
| 51 |
|
FILE *fp; |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
+ |
int |
| 70 |
+ |
ambvalOK(av) /* check consistency of ambient value */ |
| 71 |
+ |
register AMBVAL *av; |
| 72 |
+ |
{ |
| 73 |
+ |
double d; |
| 74 |
+ |
|
| 75 |
+ |
if (badvec(av->pos)) return(0); |
| 76 |
+ |
if (badvec(av->dir)) return(0); |
| 77 |
+ |
d = DOT(av->dir,av->dir); |
| 78 |
+ |
if (d < 0.9999 || d > 1.0001) return(0); |
| 79 |
+ |
if (av->lvl < 0 || av->lvl > 100) return(0); |
| 80 |
+ |
if (av->weight <= 0. || av->weight > 1.) return(0); |
| 81 |
+ |
if (av->rad <= 0. || av->rad >= FHUGE) return(0); |
| 82 |
+ |
if (colval(av->val,RED) < 0. || |
| 83 |
+ |
colval(av->val,RED) > FHUGE || |
| 84 |
+ |
colval(av->val,GRN) < 0. || |
| 85 |
+ |
colval(av->val,GRN) > FHUGE || |
| 86 |
+ |
colval(av->val,BLU) < 0. || |
| 87 |
+ |
colval(av->val,BLU) > FHUGE) return(0); |
| 88 |
+ |
if (badvec(av->gpos)) return(0); |
| 89 |
+ |
if (badvec(av->gdir)) return(0); |
| 90 |
+ |
return(1); |
| 91 |
+ |
} |
| 92 |
+ |
|
| 93 |
+ |
|
| 94 |
+ |
int |
| 95 |
|
readambval(av, fp) /* read ambient value from stream */ |
| 96 |
|
register AMBVAL *av; |
| 97 |
|
FILE *fp; |
| 110 |
|
av->rad = getflt(fp); |
| 111 |
|
getvec(av->gpos, fp); |
| 112 |
|
getvec(av->gdir, fp); |
| 113 |
< |
return(feof(fp) ? 0 : 1); |
| 113 |
> |
return(feof(fp) ? 0 : ambvalOK(av)); |
| 114 |
|
} |