1 |
greg |
2.18 |
/* RCSid $Id: source.h,v 2.17 2007/07/25 05:38:24 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 |
2.18 |
#define SCIR 0100 /* source circular flag */ |
30 |
|
|
#define SCYL 0200 /* source cylindrical flag */ |
31 |
|
|
#define SFOLLOW 0400 /* source follow path flag */ |
32 |
greg |
1.1 |
|
33 |
|
|
typedef struct { |
34 |
greg |
1.6 |
FVECT aim; /* aim direction or center */ |
35 |
|
|
float siz; /* output solid angle or area */ |
36 |
greg |
2.4 |
float flen; /* focal length (negative if distant source) */ |
37 |
greg |
1.3 |
} SPOT; /* spotlight */ |
38 |
|
|
|
39 |
|
|
typedef struct { |
40 |
greg |
2.12 |
union { |
41 |
|
|
struct { |
42 |
|
|
FVECT u, v; /* unit vectors */ |
43 |
|
|
} f; /* flat source indexing */ |
44 |
|
|
struct { |
45 |
|
|
FVECT o; /* origin position */ |
46 |
|
|
RREAL e1, e2; /* 1/extent */ |
47 |
|
|
int ax; /* major direction */ |
48 |
|
|
} d; /* distant source indexing */ |
49 |
|
|
} p; /* indexing parameters */ |
50 |
|
|
OBJECT obs[1]; /* cache obstructors (extends struct) */ |
51 |
|
|
} OBSCACHE; /* obstructor cache */ |
52 |
|
|
|
53 |
|
|
typedef struct { |
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 |
2.16 |
int sflags; /* source flags */ |
76 |
greg |
1.2 |
} SRCREC; /* light source */ |
77 |
greg |
1.1 |
|
78 |
greg |
1.15 |
#define MAXSPART 64 /* maximum partitions per source */ |
79 |
greg |
1.14 |
|
80 |
|
|
#define SU 0 /* U vector or partition */ |
81 |
|
|
#define SV 1 /* V vector or partition */ |
82 |
|
|
#define SW 2 /* W vector or partition */ |
83 |
|
|
#define S0 3 /* leaf partition */ |
84 |
|
|
|
85 |
|
|
#define snorm ss[SW] /* normal vector for flat source */ |
86 |
|
|
|
87 |
|
|
typedef struct { |
88 |
greg |
2.16 |
double dom; /* solid angle of partition */ |
89 |
greg |
1.14 |
int sn; /* source number */ |
90 |
|
|
short np; /* number of partitions */ |
91 |
|
|
short sp; /* this partition number */ |
92 |
|
|
unsigned char spt[MAXSPART/2]; /* source partitioning */ |
93 |
|
|
} SRCINDEX; /* source index structure */ |
94 |
|
|
|
95 |
|
|
#define initsrcindex(s) ((s)->sn = (s)->sp = -1, (s)->np = 0) |
96 |
|
|
|
97 |
schorsch |
2.10 |
#define clrpart(pt) memset((char *)(pt), '\0', MAXSPART/2) |
98 |
greg |
1.14 |
#define setpart(pt,i,v) ((pt)[(i)>>2] |= (v)<<(((i)&3)<<1)) |
99 |
|
|
#define spart(pt,pi) ((pt)[(pi)>>2] >> (((pi)&3)<<1) & 3) |
100 |
|
|
|
101 |
greg |
1.8 |
/* |
102 |
|
|
* Special support functions for sources |
103 |
|
|
*/ |
104 |
|
|
|
105 |
|
|
/* |
106 |
greg |
1.10 |
* Virtual source materials must define the following. |
107 |
greg |
1.8 |
* |
108 |
|
|
* vproj(pm, op, sp, i) Compute i'th virtual projection |
109 |
|
|
* of source sp in object op and assign |
110 |
|
|
* the 4x4 transformation matrix pm. |
111 |
|
|
* Return 1 on success, 0 if no i'th projection. |
112 |
|
|
* |
113 |
|
|
* nproj The number of projections. The value of |
114 |
|
|
* i passed to vproj runs from 0 to nproj-1. |
115 |
|
|
*/ |
116 |
|
|
|
117 |
greg |
1.2 |
typedef struct { |
118 |
greg |
1.8 |
int (*vproj)(); /* project virtual sources */ |
119 |
|
|
int nproj; /* number of possible projections */ |
120 |
|
|
} VSMATERIAL; /* virtual source material functions */ |
121 |
greg |
1.4 |
|
122 |
|
|
typedef struct { |
123 |
greg |
2.5 |
void (*setsrc)(); /* set light source for object */ |
124 |
|
|
void (*partit)(); /* partition light source object */ |
125 |
greg |
1.8 |
double (*getpleq)(); /* plane equation for surface */ |
126 |
|
|
double (*getdisk)(); /* maximum disk for surface */ |
127 |
|
|
} SOBJECT; /* source object functions */ |
128 |
greg |
1.1 |
|
129 |
greg |
1.8 |
typedef union { |
130 |
|
|
VSMATERIAL *mf; /* material functions */ |
131 |
|
|
SOBJECT *of; /* object functions */ |
132 |
|
|
} SRCFUNC; /* source functions */ |
133 |
|
|
|
134 |
|
|
extern SRCFUNC sfun[]; /* source dispatch table */ |
135 |
|
|
|
136 |
greg |
1.2 |
extern SRCREC *source; /* our source list */ |
137 |
greg |
1.1 |
extern int nsources; /* the number of sources */ |
138 |
|
|
|
139 |
greg |
1.14 |
#define sflatform(sn,dir) -DOT(source[sn].snorm, dir) |
140 |
|
|
|
141 |
greg |
1.11 |
#define getplaneq(c,o) (*sfun[(o)->otype].of->getpleq)(c,o) |
142 |
|
|
#define getmaxdisk(c,o) (*sfun[(o)->otype].of->getdisk)(c,o) |
143 |
|
|
#define setsource(s,o) (*sfun[(o)->otype].of->setsrc)(s,o) |
144 |
greg |
2.5 |
|
145 |
|
|
/* defined in source.c */ |
146 |
greg |
2.12 |
extern OBJREC *findmaterial(OBJREC *o); |
147 |
greg |
2.5 |
extern void marksources(void); |
148 |
|
|
extern void freesources(void); |
149 |
|
|
extern int srcray(RAY *sr, RAY *r, SRCINDEX *si); |
150 |
|
|
extern void srcvalue(RAY *r); |
151 |
|
|
extern int sourcehit(RAY *r); |
152 |
schorsch |
2.13 |
typedef void srcdirf_t(COLOR cv, void *np, FVECT ldir, double omega); |
153 |
|
|
extern void direct(RAY *r, srcdirf_t *f, void *p); |
154 |
greg |
2.5 |
extern void srcscatter(RAY *r); |
155 |
|
|
extern int m_light(OBJREC *m, RAY *r); |
156 |
greg |
2.17 |
/* defined in srcobstr.c */ |
157 |
greg |
2.15 |
extern void initobscache(int sn); |
158 |
greg |
2.14 |
extern int srcblocker(RAY *r); |
159 |
greg |
2.12 |
extern int srcblocked(RAY *r); |
160 |
|
|
extern void freeobscache(SRCREC *s); |
161 |
greg |
2.17 |
extern void markclip(OBJREC *m); |
162 |
greg |
2.5 |
/* defined in srcsamp.c */ |
163 |
|
|
extern double nextssamp(RAY *r, SRCINDEX *si); |
164 |
|
|
extern int skipparts(int ct[3], int sz[3], int pp[2], unsigned char *pt); |
165 |
|
|
extern void nopart(SRCINDEX *si, RAY *r); |
166 |
|
|
extern void cylpart(SRCINDEX *si, RAY *r); |
167 |
|
|
extern void flatpart(SRCINDEX *si, RAY *r); |
168 |
|
|
extern double scylform(int sn, FVECT dir); |
169 |
|
|
/* defined in srcsupp.c */ |
170 |
|
|
extern void initstypes(void); |
171 |
|
|
extern int newsource(void); |
172 |
|
|
extern void setflatss(SRCREC *src); |
173 |
|
|
extern void fsetsrc(SRCREC *src, OBJREC *so); |
174 |
|
|
extern void ssetsrc(SRCREC *src, OBJREC *so); |
175 |
|
|
extern void sphsetsrc(SRCREC *src, OBJREC *so); |
176 |
|
|
extern void rsetsrc(SRCREC *src, OBJREC *so); |
177 |
|
|
extern void cylsetsrc(SRCREC *src, OBJREC *so); |
178 |
|
|
extern SPOT *makespot(OBJREC *m); |
179 |
|
|
extern int spotout(RAY *r, SPOT *s); |
180 |
|
|
extern double fgetmaxdisk(FVECT ocent, OBJREC *op); |
181 |
|
|
extern double rgetmaxdisk(FVECT ocent, OBJREC *op); |
182 |
|
|
extern double fgetplaneq(FVECT nvec, OBJREC *op); |
183 |
|
|
extern double rgetplaneq(FVECT nvec, OBJREC *op); |
184 |
|
|
extern int commonspot(SPOT *sp1, SPOT *sp2, FVECT org); |
185 |
|
|
extern int commonbeam(SPOT *sp1, SPOT *sp2, FVECT org); |
186 |
|
|
extern int checkspot(SPOT *sp, FVECT nrm); |
187 |
|
|
extern double spotdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT pos); |
188 |
|
|
extern double beamdisk(FVECT oc, OBJREC *op, SPOT *sp, FVECT dir); |
189 |
|
|
extern double intercircle(FVECT cc, FVECT c1, FVECT c2, |
190 |
|
|
double r1s, double r2s); |
191 |
|
|
/* defined in virtuals.c */ |
192 |
|
|
extern void markvirtuals(void); |
193 |
|
|
extern void addvirtuals(int sn, int nr); |
194 |
|
|
extern void vproject(OBJREC *o, int sn, int n); |
195 |
|
|
extern OBJREC *vsmaterial(OBJREC *o); |
196 |
|
|
extern int makevsrc(OBJREC *op, int sn, MAT4 pm); |
197 |
|
|
extern double getdisk(FVECT oc, OBJREC *op, int sn); |
198 |
|
|
extern int vstestvis(int f, OBJREC *o, FVECT oc, double or2, int sn); |
199 |
|
|
extern void virtverb(int sn, FILE *fp); |
200 |
|
|
|
201 |
schorsch |
2.7 |
|
202 |
|
|
#ifdef __cplusplus |
203 |
|
|
} |
204 |
greg |
2.5 |
#endif |
205 |
schorsch |
2.7 |
#endif /* _RAD_SOURCE_H_ */ |
206 |
|
|
|