ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_clip.c
Revision: 2.10
Committed: Wed Jul 25 04:12:36 2007 UTC (16 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R1, rad4R0, rad3R9
Changes since 2.9: +3 -1 lines
Log Message:
Fixed bug in shadow cache related to antimatter holes

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.10 static const char RCSid[] = "$Id: m_clip.c,v 2.9 2005/04/19 01:15:06 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * m_clip.c - routine for clipped (cut) objects.
6 greg 2.5 */
7    
8 greg 2.6 #include "copyright.h"
9 greg 1.1
10     #include "ray.h"
11 schorsch 2.8 #include "rtotypes.h"
12 greg 1.1
13     /*
14     * Clipping objects permit holes and sections to be taken out
15     * of other objects. The method is simple:
16     *
17     * The argument is the clipped materials;
18     * the first is used to shade upon exit.
19     */
20    
21    
22 schorsch 2.8 extern int
23     m_clip( /* clip objects from ray */
24     register OBJREC *m,
25     register RAY *r
26     )
27 greg 1.1 {
28     OBJECT cset[MAXSET+1], *modset;
29 gwlarson 2.4 OBJECT obj, mod;
30 greg 1.1 int entering;
31     register int i;
32    
33 gwlarson 2.4 obj = objndx(m);
34 greg 1.1 if ((modset = (OBJECT *)m->os) == NULL) {
35     if (m->oargs.nsargs < 1 || m->oargs.nsargs > MAXSET)
36     objerror(m, USER, "bad # arguments");
37     modset = (OBJECT *)malloc((m->oargs.nsargs+1)*sizeof(OBJECT));
38     if (modset == NULL)
39     error(SYSTEM, "out of memory in m_clip");
40     modset[0] = 0;
41     for (i = 0; i < m->oargs.nsargs; i++) {
42     if (!strcmp(m->oargs.sarg[i], VOIDID))
43     continue;
44 greg 2.3 if ((mod = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
45 greg 1.1 sprintf(errmsg, "unknown modifier \"%s\"",
46     m->oargs.sarg[i]);
47     objerror(m, WARNING, errmsg);
48     continue;
49     }
50     if (inset(modset, mod)) {
51     objerror(m, WARNING, "duplicate modifier");
52     continue;
53     }
54     insertelem(modset, mod);
55     }
56 greg 1.2 m->os = (char *)modset;
57 greg 1.1 }
58 greg 2.10 if (r == NULL)
59     return(0); /* just initializing */
60 greg 1.1 if (r->clipset != NULL)
61     setcopy(cset, r->clipset);
62     else
63     cset[0] = 0;
64    
65     entering = r->rod > 0.0; /* entering clipped region? */
66    
67     for (i = modset[0]; i > 0; i--) {
68     if (entering) {
69     if (!inset(cset, modset[i])) {
70     if (cset[0] >= MAXSET)
71     error(INTERNAL, "set overflow in m_clip");
72     insertelem(cset, modset[i]);
73     }
74     } else {
75     if (inset(cset, modset[i]))
76     deletelem(cset, modset[i]);
77     }
78     }
79     /* compute ray value */
80     r->newcset = cset;
81     if (strcmp(m->oargs.sarg[0], VOIDID)) {
82     int inside = 0;
83 greg 2.9 register const RAY *rp;
84 greg 1.1 /* check for penetration */
85     for (rp = r; rp->parent != NULL; rp = rp->parent)
86     if (!(rp->rtype & RAYREFL) && rp->parent->ro != NULL
87 schorsch 2.7 && inset(modset, rp->parent->ro->omod)) {
88 greg 1.1 if (rp->parent->rod > 0.0)
89     inside++;
90     else
91     inside--;
92 schorsch 2.7 }
93 greg 1.1 if (inside > 0) { /* we just hit the object */
94     flipsurface(r);
95 gwlarson 2.4 return(rayshade(r, lastmod(obj, m->oargs.sarg[0])));
96 greg 1.1 }
97     }
98     raytrans(r); /* else transfer ray */
99 greg 2.2 return(1);
100 greg 1.1 }