| 1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* m_clip.c - routine for clipped (cut) objects. |
| 9 |
– |
* |
| 10 |
– |
* 3/17/86 |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include "copyright.h" |
| 9 |
+ |
|
| 10 |
|
#include "ray.h" |
| 11 |
+ |
#include "rtotypes.h" |
| 12 |
|
|
| 13 |
|
/* |
| 14 |
|
* Clipping objects permit holes and sections to be taken out |
| 19 |
|
*/ |
| 20 |
|
|
| 21 |
|
|
| 22 |
< |
m_clip(m, r) /* clip objects from ray */ |
| 23 |
< |
register OBJREC *m; |
| 24 |
< |
register RAY *r; |
| 22 |
> |
extern int |
| 23 |
> |
m_clip( /* clip objects from ray */ |
| 24 |
> |
register OBJREC *m, |
| 25 |
> |
register RAY *r |
| 26 |
> |
) |
| 27 |
|
{ |
| 28 |
|
OBJECT cset[MAXSET+1], *modset; |
| 29 |
+ |
OBJECT obj, mod; |
| 30 |
|
int entering; |
| 31 |
|
register int i; |
| 32 |
|
|
| 33 |
+ |
obj = objndx(m); |
| 34 |
|
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); |
| 37 |
|
modset = (OBJECT *)malloc((m->oargs.nsargs+1)*sizeof(OBJECT)); |
| 38 |
|
if (modset == NULL) |
| 39 |
|
error(SYSTEM, "out of memory in m_clip"); |
| 55 |
|
} |
| 56 |
|
m->os = (char *)modset; |
| 57 |
|
} |
| 58 |
+ |
if (r == NULL) |
| 59 |
+ |
return(0); /* just initializing */ |
| 60 |
|
if (r->clipset != NULL) |
| 61 |
|
setcopy(cset, r->clipset); |
| 62 |
|
else |
| 80 |
|
r->newcset = cset; |
| 81 |
|
if (strcmp(m->oargs.sarg[0], VOIDID)) { |
| 82 |
|
int inside = 0; |
| 83 |
< |
register RAY *rp; |
| 83 |
> |
register const RAY *rp; |
| 84 |
|
/* check for penetration */ |
| 85 |
|
for (rp = r; rp->parent != NULL; rp = rp->parent) |
| 86 |
|
if (!(rp->rtype & RAYREFL) && rp->parent->ro != NULL |
| 87 |
< |
&& inset(modset, rp->parent->ro->omod)) |
| 87 |
> |
&& inset(modset, rp->parent->ro->omod)) { |
| 88 |
|
if (rp->parent->rod > 0.0) |
| 89 |
|
inside++; |
| 90 |
|
else |
| 91 |
|
inside--; |
| 92 |
+ |
} |
| 93 |
|
if (inside > 0) { /* we just hit the object */ |
| 94 |
|
flipsurface(r); |
| 95 |
< |
return(rayshade(r, modifier(m->oargs.sarg[0]))); |
| 95 |
> |
return(rayshade(r, lastmod(obj, m->oargs.sarg[0]))); |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
raytrans(r); /* else transfer ray */ |