ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_clip.c
Revision: 2.6
Committed: Tue Feb 25 02:47:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.5: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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