| 1 |
greg |
2.15 |
/* RCSid $Id: source.h,v 2.14 2004/09/08 06:07:52 greg Exp $ */
|
| 2 |
greg |
1.1 |
/*
|
| 3 |
|
|
* source.h - header file for ray tracing sources.
|
| 4 |
|
|
*
|
| 5 |
greg |
2.5 |
* Include after ray.h
|
| 6 |
|
|
*/
|
| 7 |
schorsch |
2.7 |
#ifndef _RAD_SOURCE_H_
|
| 8 |
|
|
#define _RAD_SOURCE_H_
|
| 9 |
schorsch |
2.11 |
|
| 10 |
|
|
#include <string.h>
|
| 11 |
|
|
|
| 12 |
schorsch |
2.7 |
#ifdef __cplusplus
|
| 13 |
|
|
extern "C" {
|
| 14 |
|
|
#endif
|
| 15 |
schorsch |
2.10 |
|
| 16 |
greg |
2.12 |
#ifndef AIMREQT
|
| 17 |
greg |
1.6 |
#define AIMREQT 100 /* required aim success/failure */
|
| 18 |
greg |
2.12 |
#endif
|
| 19 |
|
|
#ifndef SHADCACHE
|
| 20 |
|
|
#define SHADCACHE 20 /* shadow cache resolution */
|
| 21 |
|
|
#endif
|
| 22 |
greg |
1.6 |
|
| 23 |
greg |
1.1 |
#define SDISTANT 01 /* source distant flag */
|
| 24 |
|
|
#define SSKIP 02 /* source skip flag */
|
| 25 |
greg |
1.3 |
#define SPROX 04 /* source proximity flag */
|
| 26 |
|
|
#define SSPOT 010 /* source spotlight flag */
|
| 27 |
greg |
1.6 |
#define SVIRTUAL 020 /* source virtual flag */
|
| 28 |
|
|
#define SFLAT 040 /* source flat flag */
|
| 29 |
greg |
1.14 |
#define SCYL 0100 /* source cylindrical flag */
|
| 30 |
|
|
#define SFOLLOW 0200 /* source follow path flag */
|
| 31 |
greg |
1.1 |
|
| 32 |
|
|
typedef struct {
|
| 33 |
greg |
1.6 |
FVECT aim; /* aim direction or center */
|
| 34 |
|
|
float siz; /* output solid angle or area */
|
| 35 |
greg |
2.4 |
float flen; /* focal length (negative if distant source) */
|
| 36 |
greg |
1.3 |
} SPOT; /* spotlight */
|
| 37 |
|
|
|
| 38 |
|
|
typedef struct {
|
| 39 |
greg |
2.12 |
union {
|
| 40 |
|
|
struct {
|
| 41 |
|
|
FVECT u, v; /* unit vectors */
|
| 42 |
|
|
} f; /* flat source indexing */
|
| 43 |
|
|
struct {
|
| 44 |
|
|
FVECT o; /* origin position */
|
| 45 |
|
|
RREAL e1, e2; /* 1/extent */
|
| 46 |
|
|
int ax; /* major direction */
|
| 47 |
|
|
} d; /* distant source indexing */
|
| 48 |
|
|
} p; /* indexing parameters */
|
| 49 |
|
|
OBJECT obs[1]; /* cache obstructors (extends struct) */
|
| 50 |
|
|
} OBSCACHE; /* obstructor cache */
|
| 51 |
|
|
|
| 52 |
|
|
typedef struct {
|
| 53 |
greg |
1.6 |
int sflags; /* source flags */
|
| 54 |
greg |
1.1 |
FVECT sloc; /* direction or position of source */
|
| 55 |
greg |
1.14 |
FVECT ss[3]; /* source dimension vectors, U, V, and W */
|
| 56 |
|
|
float srad; /* maximum source radius */
|
| 57 |
|
|
float ss2; /* solid angle or projected area */
|
| 58 |
greg |
2.12 |
OBJREC *so; /* source destination object */
|
| 59 |
greg |
1.6 |
struct {
|
| 60 |
greg |
1.3 |
float prox; /* proximity */
|
| 61 |
|
|
SPOT *s; /* spot */
|
| 62 |
|
|
} sl; /* localized source information */
|
| 63 |
greg |
1.6 |
union {
|
| 64 |
greg |
2.3 |
long success; /* successes - AIMREQT*failures */
|
| 65 |
greg |
1.12 |
struct {
|
| 66 |
|
|
short pn; /* projection number */
|
| 67 |
greg |
2.3 |
int sn; /* next source to aim for */
|
| 68 |
greg |
1.12 |
} sv; /* virtual source */
|
| 69 |
greg |
1.6 |
} sa; /* source aiming information */
|
| 70 |
greg |
2.8 |
unsigned long
|
| 71 |
|
|
ntests, nhits; /* shadow tests and hits */
|
| 72 |
greg |
2.12 |
#ifdef SHADCACHE
|
| 73 |
|
|
OBSCACHE *obscache; /* obstructor cache */
|
| 74 |
|
|
#endif
|
| 75 |
greg |
1.2 |
} SRCREC; /* light source */
|
| 76 |
greg |
1.1 |
|
| 77 |
greg |
1.15 |
#define MAXSPART 64 /* maximum partitions per source */
|
| 78 |
greg |
1.14 |
|
| 79 |
|
|
#define SU 0 /* U vector or partition */
|
| 80 |
|
|
#define SV 1 /* V vector or partition */
|
| 81 |
|
|
#define SW 2 /* W vector or partition */
|
| 82 |
|
|
#define S0 3 /* leaf partition */
|
| 83 |
|
|
|
| 84 |
|
|
#define snorm ss[SW] /* normal vector for flat source */
|
| 85 |
|
|
|
| 86 |
|
|
typedef struct {
|
| 87 |
|
|
int sn; /* source number */
|
| 88 |
|
|
short np; /* number of partitions */
|
| 89 |
|
|
short sp; /* this partition number */
|
| 90 |
|
|
double dom; /* solid angle of partition */
|
| 91 |
|
|
unsigned char spt[MAXSPART/2]; /* source partitioning */
|
| 92 |
|
|
} SRCINDEX; /* source index structure */
|
| 93 |
|
|
|
| 94 |
|
|
#define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0)
|
| 95 |
|
|
|
| 96 |
schorsch |
2.10 |
#define clrpart(pt) memset((char *)(pt), '\0', MAXSPART/2)
|
| 97 |
greg |
1.14 |
#define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1))
|
| 98 |
|
|
#define spart(pt,pi) ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3)
|
| 99 |
|
|
|
| 100 |
greg |
1.8 |
/*
|
| 101 |
|
|
* Special support functions for sources
|
| 102 |
|
|
*/
|
| 103 |
|
|
|
| 104 |
|
|
/*
|
| 105 |
greg |
1.10 |
* Virtual source materials must define the following.
|
| 106 |
greg |
1.8 |
*
|
| 107 |
|
|
* vproj(pm, op, sp, i) Compute i'th virtual projection
|
| 108 |
|
|
* of source sp in object op and assign
|
| 109 |
|
|
* the 4x4 transformation matrix pm.
|
| 110 |
|
|
* Return 1 on success, 0 if no i'th projection.
|
| 111 |
|
|
*
|
| 112 |
|
|
* nproj The number of projections. The value of
|
| 113 |
|
|
* i passed to vproj runs from 0 to nproj-1.
|
| 114 |
|
|
*/
|
| 115 |
|
|
|
| 116 |
greg |
1.2 |
typedef struct {
|
| 117 |
greg |
1.8 |
int (*vproj)(); /* project virtual sources */
|
| 118 |
|
|
int nproj; /* number of possible projections */
|
| 119 |
|
|
} VSMATERIAL; /* virtual source material functions */
|
| 120 |
greg |
1.4 |
|
| 121 |
|
|
typedef struct {
|
| 122 |
greg |
2.5 |
void (*setsrc)(); /* set light source for object */
|
| 123 |
|
|
void (*partit)(); /* partition light source object */
|
| 124 |
greg |
1.8 |
double (*getpleq)(); /* plane equation for surface */
|
| 125 |
|
|
double (*getdisk)(); /* maximum disk for surface */
|
| 126 |
|
|
} SOBJECT; /* source object functions */
|
| 127 |
greg |
1.1 |
|
| 128 |
greg |
1.8 |
typedef union {
|
| 129 |
|
|
VSMATERIAL *mf; /* material functions */
|
| 130 |
|
|
SOBJECT *of; /* object functions */
|
| 131 |
|
|
} SRCFUNC; /* source functions */
|
| 132 |
|
|
|
| 133 |
|
|
extern SRCFUNC sfun[]; /* source dispatch table */
|
| 134 |
|
|
|
| 135 |
greg |
1.2 |
extern SRCREC *source; /* our source list */
|
| 136 |
greg |
1.1 |
extern int nsources; /* the number of sources */
|
| 137 |
|
|
|
| 138 |
greg |
1.14 |
#define sflatform(sn,dir) -DOT(source[sn].snorm, dir)
|
| 139 |
|
|
|
| 140 |
greg |
1.11 |
#define getplaneq(c,o) (*sfun[(o)->otype].of->getpleq)(c,o)
|
| 141 |
|
|
#define getmaxdisk(c,o) (*sfun[(o)->otype].of->getdisk)(c,o)
|
| 142 |
|
|
#define setsource(s,o) (*sfun[(o)->otype].of->setsrc)(s,o)
|
| 143 |
greg |
2.5 |
|
| 144 |
|
|
/* defined in source.c */
|
| 145 |
greg |
2.12 |
extern OBJREC *findmaterial(OBJREC *o);
|
| 146 |
greg |
2.5 |
extern void marksources(void);
|
| 147 |
|
|
extern void freesources(void);
|
| 148 |
|
|
extern int srcray(RAY *sr, RAY *r, SRCINDEX *si);
|
| 149 |
|
|
extern void srcvalue(RAY *r);
|
| 150 |
|
|
extern int sourcehit(RAY *r);
|
| 151 |
schorsch |
2.13 |
typedef void srcdirf_t(COLOR cv, void *np, FVECT ldir, double omega);
|
| 152 |
|
|
extern void direct(RAY *r, srcdirf_t *f, void *p);
|
| 153 |
greg |
2.5 |
extern void srcscatter(RAY *r);
|
| 154 |
|
|
extern int m_light(OBJREC *m, RAY *r);
|
| 155 |
greg |
2.15 |
extern void initobscache(int sn);
|
| 156 |
greg |
2.14 |
extern int srcblocker(RAY *r);
|
| 157 |
greg |
2.12 |
extern int srcblocked(RAY *r);
|
| 158 |
|
|
extern void freeobscache(SRCREC *s);
|
| 159 |
greg |
2.5 |
/* defined in srcsamp.c */
|
| 160 |
|
|
extern double nextssamp(RAY *r, SRCINDEX *si);
|
| 161 |
|
|
extern int skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt);
|
| 162 |
|
|
extern void nopart(SRCINDEX *si, RAY *r);
|
| 163 |
|
|
extern void cylpart(SRCINDEX *si, RAY *r);
|
| 164 |
|
|
extern void flatpart(SRCINDEX *si, RAY *r);
|
| 165 |
|
|
extern double scylform(int sn, FVECT dir);
|
| 166 |
|
|
/* defined in srcsupp.c */
|
| 167 |
|
|
extern void initstypes(void);
|
| 168 |
|
|
extern int newsource(void);
|
| 169 |
|
|
extern void setflatss(SRCREC *src);
|
| 170 |
|
|
extern void fsetsrc(SRCREC *src, OBJREC *so);
|
| 171 |
|
|
extern void ssetsrc(SRCREC *src, OBJREC *so);
|
| 172 |
|
|
extern void sphsetsrc(SRCREC *src, OBJREC *so);
|
| 173 |
|
|
extern void rsetsrc(SRCREC *src, OBJREC *so);
|
| 174 |
|
|
extern void cylsetsrc(SRCREC *src, OBJREC *so);
|
| 175 |
|
|
extern SPOT *makespot(OBJREC *m);
|
| 176 |
|
|
extern int spotout(RAY *r, SPOT *s);
|
| 177 |
|
|
extern double fgetmaxdisk(FVECT ocent, OBJREC *op);
|
| 178 |
|
|
extern double rgetmaxdisk(FVECT ocent, OBJREC *op);
|
| 179 |
|
|
extern double fgetplaneq(FVECT nvec, OBJREC *op);
|
| 180 |
|
|
extern double rgetplaneq(FVECT nvec, OBJREC *op);
|
| 181 |
|
|
extern int commonspot(SPOT *sp1, SPOT *sp2, FVECT org);
|
| 182 |
|
|
extern int commonbeam(SPOT *sp1, SPOT *sp2, FVECT org);
|
| 183 |
|
|
extern int checkspot(SPOT *sp, FVECT nrm);
|
| 184 |
|
|
extern double spotdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT pos);
|
| 185 |
|
|
extern double beamdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT dir);
|
| 186 |
|
|
extern double intercircle(FVECT cc, FVECT c1, FVECT c2,
|
| 187 |
|
|
double r1s, double r2s);
|
| 188 |
|
|
/* defined in virtuals.c */
|
| 189 |
|
|
extern void markvirtuals(void);
|
| 190 |
|
|
extern void addvirtuals(int sn, int nr);
|
| 191 |
|
|
extern void vproject(OBJREC *o, int sn, int n);
|
| 192 |
|
|
extern OBJREC *vsmaterial(OBJREC *o);
|
| 193 |
|
|
extern int makevsrc(OBJREC *op, int sn, MAT4 pm);
|
| 194 |
|
|
extern double getdisk(FVECT oc, OBJREC *op, int sn);
|
| 195 |
|
|
extern int vstestvis(int f, OBJREC *o, FVECT oc, double or2, int sn);
|
| 196 |
|
|
extern void virtverb(int sn, FILE *fp);
|
| 197 |
|
|
|
| 198 |
schorsch |
2.7 |
|
| 199 |
|
|
#ifdef __cplusplus
|
| 200 |
|
|
}
|
| 201 |
greg |
2.5 |
#endif
|
| 202 |
schorsch |
2.7 |
#endif /* _RAD_SOURCE_H_ */
|
| 203 |
|
|
|