--- ray/src/rt/raytrace.c 2010/09/26 15:51:15 2.61 +++ ray/src/rt/raytrace.c 2014/02/19 14:12:48 2.65 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: raytrace.c,v 2.61 2010/09/26 15:51:15 greg Exp $"; +static const char RCSid[] = "$Id: raytrace.c,v 2.65 2014/02/19 14:12:48 greg Exp $"; #endif /* * raytrace.c - routines for tracing and shading rays. @@ -35,7 +35,7 @@ static int checkhit(RAY *r, CUBE *cu, OBJECT *cxs); static void checkset(OBJECT *os, OBJECT *cs); -extern int +int rayorigin( /* start new ray from old one */ RAY *r, int rt, @@ -120,13 +120,13 @@ rayorigin( /* start new ray from old one */ r->rweight = minweight; return(0); } - return(r->rlvl <= abs(maxdepth) && r->rweight >= minweight ? 0 : -1); + return(r->rweight >= minweight && r->rlvl <= abs(maxdepth) ? 0 : -1); } -extern void +void rayclear( /* clear a ray for (re)evaluation */ - register RAY *r + RAY *r ) { r->rno = raynum++; @@ -143,7 +143,7 @@ rayclear( /* clear a ray for (re)evaluation */ } -extern void +void raytrace( /* trace a ray and compute its value */ RAY *r ) @@ -163,9 +163,9 @@ raytrace( /* trace a ray and compute its value */ } -extern void +void raycont( /* check for clipped object and continue */ - register RAY *r + RAY *r ) { if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || @@ -174,9 +174,9 @@ raycont( /* check for clipped object and continue */ } -extern void +void raytrans( /* transmit ray as is */ - register RAY *r + RAY *r ) { RAY tr; @@ -190,13 +190,13 @@ raytrans( /* transmit ray as is */ } -extern int +int rayshade( /* shade ray r with material mod */ - register RAY *r, + RAY *r, int mod ) { - register OBJREC *m; + OBJREC *m; r->rt = r->rot; /* set effective ray length */ for ( ; mod != OVOID; mod = m->omod) { @@ -225,9 +225,9 @@ rayshade( /* shade ray r with material mod */ } -extern void +void rayparticipate( /* compute ray medium participation */ - register RAY *r + RAY *r ) { COLOR ce, ca; @@ -258,13 +258,13 @@ rayparticipate( /* compute ray medium participation } -extern void +void raytexture( /* get material modifiers */ RAY *r, OBJECT mod ) { - register OBJREC *m; + OBJREC *m; /* execute textures and patterns */ for ( ; mod != OVOID; mod = m->omod) { m = objptr(mod); @@ -283,9 +283,9 @@ raytexture( /* get material modifiers */ } -extern int +int raymixture( /* mix modifiers */ - register RAY *r, + RAY *r, OBJECT fore, OBJECT back, double coef @@ -293,7 +293,7 @@ raymixture( /* mix modifiers */ { RAY fr, br; int foremat, backmat; - register int i; + int i; /* bound coefficient */ if (coef > 1.0) coef = 1.0; @@ -343,10 +343,10 @@ raymixture( /* mix modifiers */ } -extern double +double raydist( /* compute (cumulative) ray distance */ - register const RAY *r, - register int flags + const RAY *r, + int flags ) { double sum = 0.0; @@ -359,9 +359,9 @@ raydist( /* compute (cumulative) ray distance */ } -extern void +void raycontrib( /* compute (cumulative) ray contribution */ - double rc[3], + RREAL rc[3], const RAY *r, int flags ) @@ -385,14 +385,14 @@ raycontrib( /* compute (cumulative) ray contribution } -extern double +double raynormal( /* compute perturbed normal for ray */ FVECT norm, - register RAY *r + RAY *r ) { double newdot; - register int i; + int i; /* The perturbation is added to the surface normal to obtain * the new normal. If the new normal would affect the surface @@ -421,7 +421,7 @@ raynormal( /* compute perturbed normal for ray */ } -extern void +void newrayxf( /* get new tranformation matrix for ray */ RAY *r ) @@ -430,8 +430,8 @@ newrayxf( /* get new tranformation matrix for ray */ struct xfn *next; FULLXF xf; } xfseed = { &xfseed }, *xflast = &xfseed; - register struct xfn *xp; - register const RAY *rp; + struct xfn *xp; + const RAY *rp; /* * Search for transform in circular list that @@ -442,7 +442,7 @@ newrayxf( /* get new tranformation matrix for ray */ if (rp->rox == &xp->xf) { /* xp in use */ xp = xp->next; /* move to next */ if (xp == xflast) { /* need new one */ - xp = (struct xfn *)malloc(sizeof(struct xfn)); + xp = (struct xfn *)bmalloc(sizeof(struct xfn)); if (xp == NULL) error(SYSTEM, "out of memory in newrayxf"); @@ -459,9 +459,9 @@ newrayxf( /* get new tranformation matrix for ray */ } -extern void +void flipsurface( /* reverse surface orientation */ - register RAY *r + RAY *r ) { r->rod = -r->rod; @@ -474,7 +474,7 @@ flipsurface( /* reverse surface orientation */ } -extern void +void rayhit( /* standard ray hit test */ OBJECT *oset, RAY *r @@ -491,17 +491,17 @@ rayhit( /* standard ray hit test */ } -extern int +int localhit( /* check for hit in the octree */ - register RAY *r, - register CUBE *scene + RAY *r, + CUBE *scene ) { OBJECT cxset[MAXCSET+1]; /* set of checked objects */ FVECT curpos; /* current cube position */ int sflags; /* sign flags */ double t, dt; - register int i; + int i; nrays++; /* increment trace counter */ sflags = 0; @@ -520,8 +520,7 @@ localhit( /* check for hit in the octree */ if (r->rmax > FTINY) { /* except aft plane if one */ r->ro = &Aftplane; r->rot = r->rmax; - for (i = 0; i < 3; i++) - r->rop[i] = r->rorg[i] + r->rot*r->rdir[i]; + VSUM(r->rop, r->rorg, r->rdir, r->rot); } /* find global cube entrance point */ t = 0.0; @@ -544,8 +543,7 @@ localhit( /* check for hit in the octree */ if (t >= r->rot) /* clipped already */ return(0); /* advance position */ - for (i = 0; i < 3; i++) - curpos[i] += r->rdir[i]*t; + VSUM(curpos, curpos, r->rdir, t); if (!incube(scene, curpos)) /* non-intersecting ray */ return(0); @@ -561,8 +559,8 @@ raymove( /* check for hit as we move */ FVECT pos, /* current position, modified herein */ OBJECT *cxs, /* checked objects, modified by checkhit */ int dirf, /* direction indicators to speed tests */ - register RAY *r, - register CUBE *cu + RAY *r, + CUBE *cu ) { int ax; @@ -570,7 +568,7 @@ raymove( /* check for hit as we move */ if (istree(cu->cutree)) { /* recurse on subcubes */ CUBE cukid; - register int br, sgn; + int br, sgn; cukid.cusize = cu->cusize * 0.5; /* find subcube */ VCOPY(cukid.cuorg, cu->cuorg); @@ -636,16 +634,14 @@ raymove( /* check for hit as we move */ ax = 2; } } - pos[0] += r->rdir[0]*t; - pos[1] += r->rdir[1]*t; - pos[2] += r->rdir[2]*t; + VSUM(pos, pos, r->rdir, t); return(ax); } static int checkhit( /* check for hit in full cube */ - register RAY *r, + RAY *r, CUBE *cu, OBJECT *cxs ) @@ -666,12 +662,12 @@ checkhit( /* check for hit in full cube */ static void checkset( /* modify checked set and set to check */ - register OBJECT *os, /* os' = os - cs */ - register OBJECT *cs /* cs' = cs + os */ + OBJECT *os, /* os' = os - cs */ + OBJECT *cs /* cs' = cs + os */ ) { OBJECT cset[MAXCSET+MAXSET+1]; - register int i, j; + int i, j; int k; /* copy os in place, cset <- cs */ cset[0] = 0;