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

Comparing ray/src/gen/mkillum2.c (file contents):
Revision 1.1 by greg, Tue Jul 23 15:42:42 1991 UTC vs.
Revision 1.2 by greg, Wed Jul 24 12:22:05 1991 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include  "cone.h"
16  
17 + #include  "random.h"
18  
19 +
20   printobj(mod, obj)              /* print out an object */
21   char  *mod;
22   register OBJREC  *obj;
# Line 42 | Line 44 | register OBJREC  *obj;
44   }
45  
46  
47 < mkillum(ob, il, rt)             /* make an illum object */
47 > o_default(ob, il, rt, nm)       /* default illum action */
48   OBJREC  *ob;
49   struct illum_args  *il;
50   struct rtproc  *rt;
51 + char  *nm;
52   {
53 +        sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"",
54 +                        nm, ofun[ob->otype].funame, ob->oname);
55 +        error(WARNING, errmsg);
56 +        if (!(il->flags & IL_LIGHT))
57 +                printobj(il->altname, ob);
58 + }
59 +
60 +
61 + o_face(ob, il, rt, nm)          /* make an illum face */
62 + OBJREC  *ob;
63 + struct illum_args  *il;
64 + struct rtproc  *rt;
65 + char  *nm;
66 + {
67 + }
68 +
69 +
70 + o_sphere(ob, il, rt, nm)        /* make an illum sphere */
71 + OBJREC  *ob;
72 + struct illum_args  *il;
73 + struct rtproc  *rt;
74 + char  *nm;
75 + {
76 +        int  dim[4];
77 +        int  n, nalt, nazi;
78 +        float  *distarr;
79 +        double  r1, r2;
80 +        FVECT  pos, dir;
81 +        FVECT  u, v;
82 +        register int  i, j;
83 +                                /* check arguments */
84 +        if (ob->oargs.nfargs != 4)
85 +                objerror(ob, USER, "bad # of arguments");
86 +                                /* set up sampling */
87 +        n = 4.*PI * il->sampdens;
88 +        nalt = sqrt(n/PI) + .5;
89 +        nazi = PI*nalt + .5;
90 +        n = nalt*nazi;
91 +        distarr = (float *)calloc(n, 3*sizeof(float));
92 +        if (distarr == NULL)
93 +                error(SYSTEM, "out of memory in o_sphere");
94 +        dim[0] = random();
95 +                                /* sample sphere */
96 +        for (dim[1] = 0; dim[1] < nalt; dim[1]++)
97 +            for (dim[2] = 0; dim[2] < nazi; dim[2]++)
98 +                for (i = 0; i < il->nsamps; i++) {
99 +                                        /* random direction */
100 +                    dim[3] = 1;
101 +                    r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
102 +                    dim[3] = 2;
103 +                    r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
104 +                    rounddir(dir, r1, r2);
105 +                                        /* random location */
106 +                    mkaxes(u, v, dir);          /* yuck! */
107 +                    dim[3] = 3;
108 +                    r1 = sqrt(urand(urind(ilhash(dim,4),i)));
109 +                    dim[3] = 4;
110 +                    r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
111 +                    for (j = 0; j < 3; j++)
112 +                        org[j] = obj->oargs.farg[j] + obj->oargs.farg[3] *
113 +                                        ( r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
114 +                                                - sqrt(1.01-r1*r1)*dir[j] );
115 +
116 +                                        /* send sample */
117 +                    raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
118 +                }
119 +        rayflush(rt);
120 +                                /* write out distribution */
121 +        rounddist(distarr, nalt, nazi, il, ob);
122 +                                /* clean up */
123 +        free((char *)distarr);
124 + }
125 +
126 +
127 + o_ring(ob, il, rt, nm)          /* make an illum ring */
128 + OBJREC  *ob;
129 + struct illum_args  *il;
130 + struct rtproc  *rt;
131 + char  *nm;
132 + {
133 + }
134 +
135 +
136 + raysamp(res, org, dir, rt)      /* compute a ray sample */
137 + float  res[3];
138 + FVECT  org, dir;
139 + register struct rtproc  *rt;
140 + {
141 +        register float  *fp;
142 +
143 +        if (rt->nrays == rt->bsiz)
144 +                rayflush(rt);
145 +        rt->dest[rt->nrays] = res;
146 +        fp = rt->buf + 6*rt->nrays++;
147 +        *fp++ = org[0]; *fp++ = org[1]; *fp++ = org[2];
148 +        *fp++ = dir[0]; *fp++ = dir[1]; *fp = dir[2];
149 + }
150 +
151 +
152 + rayflush(rt)                    /* flush buffered rays */
153 + register struct rtproc  *rt;
154 + {
155 +        register int  i;
156 +
157 +        if (rt->nrays <= 0)
158 +                return;
159 +        i = 6*rt->nrays + 3;
160 +        rt->buf[i++] = 0.; rt->buf[i++] = 0.; rt->buf[i] = 0.;
161 +        if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
162 +                        3*sizeof(float)*rt->nrays,
163 +                        6*sizeof(float)*(rt->nrays+1)) <
164 +                        3*sizeof(float)*rt->nrays )
165 +                error(SYSTEM, "error reading from rtrace process");
166 +        i = rt->nrays;
167 +        while (i--) {
168 +                rt->dest[i][0] += rt->buf[3*i];
169 +                rt->dest[i][1] += rt->buf[3*i+1];
170 +                rt->dest[i][2] += rt->buf[3*i+2];
171 +        }
172 +        rt->nrays = 0;
173   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines