ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/rglsurf.c
(Generate patch)

Comparing ray/src/common/rglsurf.c (file contents):
Revision 3.3 by gwlarson, Fri Dec 11 13:53:32 1998 UTC vs.
Revision 3.8 by greg, Sun May 25 06:09:44 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert Radiance -> OpenGL surfaces.
6   */
7  
8 + #include "copyright.h"
9 +
10   #include "radogl.h"
11  
12   #ifndef NSLICES
# Line 29 | Line 28 | static char    *glu_rout = "unk";      /* active GLU routine *
28   #define NOPOLY()        if (curpolysize) {glEnd(); curpolysize = 0;} else
29  
30  
31 + void
32   setmaterial(mp, cent, ispoly)   /* prepare for new material */
33   register MATREC *mp;
34   FVECT   cent;
# Line 80 | Line 80 | register FVECT v[];    /* vertex list */
80   }
81  
82  
83 < static
83 > static void
84   glu_error(en)                   /* report an error as a warning */
85   GLenum  en;
86   {
# Line 130 | Line 130 | newquadric()                   /* allocate GLU quadric structure */
130   }
131  
132  
133 + int
134   o_face(o)                       /* convert a face */
135   register OBJREC *o;
136   {
# Line 141 | Line 142 | register OBJREC        *o;
142                  objerror(o, USER, "bad # real arguments");
143          area = polyarea(cent, norm, o->oargs.nfargs/3, (FVECT *)o->oargs.farg);
144          if (area <= FTINY)
145 <                return;
145 >                return(0);
146          if (dolights)                                   /* check for source */
147 <                doflatsrc(o->os, cent, norm, area);
148 <        setmaterial(o->os, cent, 1);                    /* set material */
147 >                doflatsrc((MATREC *)o->os, cent, norm, area);
148 >        setmaterial((MATREC *)o->os, cent, 1);          /* set material */
149          if (o->oargs.nfargs/3 != curpolysize) {
150                  if (curpolysize) glEnd();
151                  curpolysize = o->oargs.nfargs/3;
# Line 176 | Line 177 | register OBJREC        *o;
177                                          (GLdouble)o->oargs.farg[3*i+1],
178                                          (GLdouble)o->oargs.farg[3*i+2]);
179          }
180 +        return(0);
181   }
182  
183  
184 + void
185   surfclean()                     /* clean up surface routines */
186   {
187          setmaterial(NULL, NULL, 0);
# Line 194 | Line 197 | surfclean()                    /* clean up surface routines */
197   }
198  
199  
200 + int
201   o_sphere(o)                     /* convert a sphere */
202   register OBJREC *o;
203   {
# Line 204 | Line 208 | register OBJREC        *o;
208                  o->otype = o->otype==OBJ_SPHERE ? OBJ_BUBBLE : OBJ_SPHERE;
209                  o->oargs.farg[3] = -o->oargs.farg[3];
210          } else if (o->oargs.farg[3] <= FTINY)
211 <                return;
211 >                return(0);
212          if (dolights)
213 <                dosphsrc(o->os, o->oargs.farg,
213 >                dosphsrc((MATREC *)o->os, o->oargs.farg,
214                                  PI*o->oargs.farg[3]*o->oargs.farg[3]);
215 <        setmaterial(o->os, o->oargs.farg, 0);
215 >        setmaterial((MATREC *)o->os, o->oargs.farg, 0);
216          if (gluqo == NULL) newquadric();
217          glu_rout = "making sphere";
218          gluQuadricOrientation(gluqo,
# Line 220 | Line 224 | register OBJREC        *o;
224                          (GLdouble)o->oargs.farg[2]);
225          gluSphere(gluqo, (GLdouble)o->oargs.farg[3], NSLICES, NSTACKS);
226          glPopMatrix();
227 +        return(0);
228   }
229  
230  
231 + int
232   o_cone(o)                       /* convert a cone or cylinder */
233   register OBJREC *o;
234   {
# Line 232 | Line 238 | register OBJREC *o;
238  
239          iscyl = o->otype==OBJ_CYLINDER | o->otype==OBJ_TUBE;
240          if (o->oargs.nfargs != (iscyl ? 7 : 8))
241 <                objerror(o, "bad # real arguments");
241 >                objerror(o, USER, "bad # real arguments");
242          if (o->oargs.farg[6] < -FTINY) {
243                  o->oargs.farg[6] = -o->oargs.farg[6];
244                  if (iscyl)
# Line 256 | Line 262 | register OBJREC *o;
262          cent[0] = .5*(o->oargs.farg[0] + o->oargs.farg[3]);
263          cent[1] = .5*(o->oargs.farg[1] + o->oargs.farg[4]);
264          cent[2] = .5*(o->oargs.farg[2] + o->oargs.farg[5]);
265 <        setmaterial(o->os, cent, 0);
265 >        setmaterial((MATREC *)o->os, cent, 0);
266          if (gluqo == NULL) newquadric();
267          glu_rout = "making cylinder";
268          gluQuadricOrientation(gluqo, o->otype==OBJ_CUP | o->otype==OBJ_TUBE ?
# Line 274 | Line 280 | register OBJREC *o;
280          x1 = o->oargs.farg[1] - o->oargs.farg[4];
281          y1 = o->oargs.farg[3] - o->oargs.farg[0];
282          /* z1 = 0; */
283 <        d = 180./PI * asin(sqrt(x1*x1 + y1*y1) / h);
283 >        d = x1*x1 + y1*y1;
284 >        if (d <= FTINY*FTINY)
285 >                x1 = 1.;
286 >        else
287 >                d = 180./PI * asin(sqrt(d) / h);
288          if (o->oargs.farg[5] < o->oargs.farg[2])
289                  d = 180. - d;
290          if (d > FTINY)
# Line 282 | Line 292 | register OBJREC *o;
292          gluCylinder(gluqo, o->oargs.farg[6], o->oargs.farg[iscyl ? 6 : 7],
293                          h, NSLICES, 1);
294          glPopMatrix();
295 +        return(0);
296   }
297  
298  
299 + int
300   o_ring(o)                       /* convert a ring */
301   register OBJREC *o;
302   {
303 <        double  x1, y1, d;
303 >        double  x1, y1, d, h;
304  
305          if (o->oargs.nfargs != 8)
306 <                objerror(o, "bad # real arguments");
306 >                objerror(o, USER, "bad # real arguments");
307          if (o->oargs.farg[7] < o->oargs.farg[6]) {
308                  register double d = o->oargs.farg[7];
309                  o->oargs.farg[7] = o->oargs.farg[6];
# Line 304 | Line 316 | register OBJREC        *o;
316          if (o->oargs.farg[7] - o->oargs.farg[6] <= FTINY)
317                  return;
318          if (dolights)
319 <                doflatsrc(o->os, o->oargs.farg, o->oargs.farg+3,
319 >                doflatsrc((MATREC *)o->os, o->oargs.farg, o->oargs.farg+3,
320                                  PI*(o->oargs.farg[7]*o->oargs.farg[7] -
321                                          o->oargs.farg[6]*o->oargs.farg[6]));
322 <        setmaterial(o->os, o->oargs.farg, 0);
322 >        setmaterial((MATREC *)o->os, o->oargs.farg, 0);
323          if (gluqo == NULL) newquadric();
324          glu_rout = "making disk";
325          gluQuadricOrientation(gluqo, GLU_OUTSIDE);
# Line 317 | Line 329 | register OBJREC        *o;
329          glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1],
330                          (GLdouble)o->oargs.farg[2]);
331                                          /* compute rotation angle */
332 <        d = VLEN(o->oargs.farg+3);
333 <        if (d <= FTINY)
332 >        h = VLEN(o->oargs.farg+3);
333 >        if (h <= FTINY)
334                  return;
335          x1 = -o->oargs.farg[4];
336          y1 = o->oargs.farg[3];
337          /* z1 = 0; */
338 <        d = 180./PI * asin(sqrt(x1*x1 + y1*y1) / d);
338 >        d = x1*x1 + y1*y1;
339 >        if (d <= FTINY*FTINY)
340 >                x1 = 1.;
341 >        else
342 >                d = 180./PI * asin(sqrt(d) / h);
343          if (o->oargs.farg[5] < 0.)
344                  d = 180. - d;
345          if (d > FTINY)
346                  glRotated(d, (GLdouble)x1, (GLdouble)y1, 0.);
347          gluDisk(gluqo, o->oargs.farg[6], o->oargs.farg[7], NSLICES, 1);
348          glPopMatrix();
349 +        return(0);
350   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines