ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_clip.c
Revision: 2.3
Committed: Mon Feb 12 17:04:08 1996 UTC (28 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +3 -2 lines
Log Message:
fixed problem with redefined modifiers in clip set

File Contents

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