Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
radogl.h File Reference
#include "standard.h"
#include <GL/glu.h>
#include "color.h"
#include "object.h"
#include "otypes.h"
#include "lookup.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MATREC
union  MATREC.u
struct  MATREC.u.m
struct  MATREC.u.l

Defines

#define MAXLIGHTS   8 /* number of OGL light sources */
#define MAXSPECEXP   128. /* maximum allowed specular exponent */
#define UNKSPECEXP   25. /* value to use when exponent unknown */
#define issrcmat(m)

Functions

void domatobj (MATREC *mp, FVECT cent)
void domatvert (MATREC *mp, FVECT v, FVECT n)
int newglist (void)
void rgl_checkerr (char *where)
int rgl_filelist (int ic, char **inp, int *nl)
int rgl_octlist (char *fname, FVECT cent, RREAL *radp, int *nl)
void rgl_load (char *inpspec)
void rgl_object (char *name, FILE *fp)
int o_instance (OBJREC *o)
int loadoctrees (void)
double checkoct (char *fname, FVECT cent)
int loadoct (char *fname)
void rgl_matclear (void)
MATRECgetmatp (char *nam)
int o_default (OBJREC *o)
int o_unsupported (OBJREC *o)
MATRECnewmaterial (char *nam)
void freemtl (void *p)
int m_normal (OBJREC *o)
int m_aniso (OBJREC *o)
int m_glass (OBJREC *o)
int m_brdf (OBJREC *o)
int m_brdf2 (OBJREC *o)
int m_light (OBJREC *o)
int m_mirror (OBJREC *o)
int m_prism (OBJREC *o)
void lightinit (void)
void lightclean (void)
void lightdefs (void)
int o_source (OBJREC *o)
int doflatsrc (MATREC *m, FVECT pos, FVECT norm, double area)
int dosphsrc (MATREC *m, FVECT pos, double area)
void setmaterial (MATREC *mp, FVECT cent, int ispoly)
double polyarea (FVECT cent, FVECT norm, int n, FVECT v[])
int o_face (OBJREC *o)
void surfclean (void)
int o_sphere (OBJREC *o)
int o_cone (OBJREC *o)
int o_ring (OBJREC *o)

Variables

double expval
COLOR ambval
int glightid [MAXLIGHTS]
int dolights
int domats
LUTAB mtab

Class Documentation

struct MATREC

Definition at line 24 of file radogl.h.

Class Members
short nlinks
short type
union MATREC u
union MATREC.u

Definition at line 27 of file radogl.h.

Class Members
u l
u m
struct MATREC.u.m

Definition at line 28 of file radogl.h.

Class Members
COLOR ambdiff
GLfloat specexp
COLOR specular
struct MATREC.u.l

Definition at line 33 of file radogl.h.

Class Members
COLOR emission
GLfloat spotang
GLfloat spotdir

Define Documentation

#define issrcmat (   m)
Value:
((m) != NULL && islight((m)->type) && \
                            (m)->type != MAT_GLOW)

Definition at line 49 of file radogl.h.

#define MAXLIGHTS   8 /* number of OGL light sources */

Definition at line 19 of file radogl.h.

#define MAXSPECEXP   128. /* maximum allowed specular exponent */

Definition at line 21 of file radogl.h.

#define UNKSPECEXP   25. /* value to use when exponent unknown */

Definition at line 22 of file radogl.h.


Function Documentation

double checkoct ( char *  fname,
FVECT  cent 
)

Definition at line 166 of file rglinst.c.

{
       char  sbuf[64];
       FILE   *fp = infp;
       char   *fn = infn;
       double siz = 0.;
       register int  i;
       
       if ((infp = fopen(infn=fname, "r")) == NULL) {
              sprintf(errmsg, "cannot open octree file \"%s\"", fname);
              error(SYSTEM, errmsg);
       }
       SET_FILE_BINARY(infp);
                                   /* get header */
       if (checkheader(infp, OCTFMT, NULL) < 0)
              octerror(USER, "not an octree");
                                   /* check format */
       if ((objsize = ogetint(2)-OCTMAGIC) <= 0 ||
                     objsize > MAXOBJSIZ || objsize > sizeof(long))
              octerror(USER, "incompatible octree format");
       if (cent != NULL) {         /* get boundaries (compute center) */
              for (i = 0; i < 3; i++)
                     cent[i] = atof(ogetstr(sbuf));
              siz = atof(ogetstr(sbuf))*.5;
              cent[0] += siz; cent[1] += siz; cent[2] += siz;
       } else {                    /* get size (radius) only */
              for (i = 0; i < 3; i++)
                     ogetstr(sbuf);
              siz = atof(ogetstr(sbuf))*.5;
       }
       fclose(infp);
       infp = fp;
       infn = fn;
       return(siz);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int doflatsrc ( MATREC m,
FVECT  pos,
FVECT  norm,
double  area 
)

Definition at line 123 of file rglsrc.c.

{
       if (!dolights || !issrcmat(m) || area <= FTINY)
              return(0);
                                          /* record type & material */
       lightrec[nlights].type = L_FLAT;
       (lightrec[nlights].m = m)->nlinks++;
                                          /* assign geometry */
       VCOPY(lightrec[nlights].pos, pos);
       VCOPY(lightrec[nlights].norm, norm);
       lightrec[nlights].area = area;
       nlights++; dolights--;
       return(1);
}

Here is the caller graph for this function:

void domatobj ( MATREC mp,
FVECT  cent 
)

Definition at line 14 of file rgldomat.c.

{
       GLfloat       vec[4];

       if ((mp == NULL) | !domats)
              return;
       if (islight(mp->type)) {
              vec[0] = colval(mp->u.l.emission,RED);
              vec[1] = colval(mp->u.l.emission,GRN);
              vec[2] = colval(mp->u.l.emission,BLU);
              vec[3] = 1.;
              glMaterialfv(GL_FRONT, GL_EMISSION, vec);
              vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
              glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec);
              glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec);
       } else {
              vec[0] = colval(mp->u.m.ambdiff,RED);
              vec[1] = colval(mp->u.m.ambdiff,GRN);
              vec[2] = colval(mp->u.m.ambdiff,BLU);
              vec[3] = 1.;
              glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec);
              vec[0] = colval(mp->u.m.specular,RED);
              vec[1] = colval(mp->u.m.specular,GRN);
              vec[2] = colval(mp->u.m.specular,BLU);
              vec[3] = 1.;
              glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec);
              glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mp->u.m.specexp);
              vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
              glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec);
       }
       rgl_checkerr("in domatobj");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void domatvert ( MATREC mp,
FVECT  v,
FVECT  n 
)

Definition at line 51 of file rgldomat.c.

{
       /* unimplemented */
}
int dosphsrc ( MATREC m,
FVECT  pos,
double  area 
)

Definition at line 143 of file rglsrc.c.

{
       if (!dolights || !issrcmat(m) || area <= FTINY)
              return(0);
                                          /* record type & material */
       lightrec[nlights].type = L_SPHERE;
       (lightrec[nlights].m = m)->nlinks++;
                                          /* assign geometry */
       VCOPY(lightrec[nlights].pos, pos);
       lightrec[nlights].area = area;
       nlights++; dolights--;
       return(1);
}

Here is the caller graph for this function:

void freemtl ( void *  p)

Definition at line 103 of file rglmat.c.

{
       register MATREC      *mp = (MATREC *)p;

       if (!--mp->nlinks)
              free((void *)mp);
}

Here is the caller graph for this function:

MATREC* getmatp ( char *  nam)

Definition at line 26 of file rglmat.c.

{
       register LUENT       *lup;

       if (nam == NULL)
              return(NULL);
       if ((lup = lu_find(&mtab, nam)) == NULL)
              return(NULL);
       return((MATREC *)lup->data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void lightclean ( void  )

Definition at line 64 of file rglsrc.c.

{
       if ((dolights += nlights) <= 0)
              return;
       glPopAttrib();
}

Here is the caller graph for this function:

void lightdefs ( void  )

Definition at line 73 of file rglsrc.c.

{
       if (!nlights)
              return;
       glNewList(lightlist, GL_COMPILE);
       while (nlights--) {
              switch (lightrec[nlights].type) {
              case L_FLAT:
                     l_flatsrc(nlights);
                     break;
              case L_SPHERE:
                     l_sphsrc(nlights);
                     break;
              case L_SOURCE:
                     l_source(nlights);
                     break;
              default:
                     error(CONSISTENCY, "botched light type in lightdefs");
              }
              freemtl(lightrec[nlights].m);
              lightrec[nlights].type = L_NONE;
       }
       glEndList();
       rgl_checkerr("defining lights");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void lightinit ( void  )

Definition at line 43 of file rglsrc.c.

{
       GLfloat       ambv[4];

       if (!dolights)
              return;
       glPushAttrib(GL_LIGHTING_BIT);
       if (expval <= FTINY && bright(ambval) > FTINY)
              expval = 0.2/bright(ambval);
       ambv[0] = expval*colval(ambval,RED);
       ambv[1] = expval*colval(ambval,GRN);
       ambv[2] = expval*colval(ambval,BLU);
       ambv[3] = 1.;
       glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambv);
       glCallList(lightlist = newglist());
       rgl_checkerr("in lightinit");
       nlights = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int loadoct ( char *  fname)

Definition at line 206 of file rglinst.c.

{
       OBJECT  fnobjects;
       char  sbuf[256];
       int  nf;
       register int  i;
       long  m;
       
       infn = fname;
       infp = fopen(fname, "r");   /* assume already checked */
       SET_FILE_BINARY(infp);
                                   /* skip header */
       getheader(infp, NULL, NULL);
                                   /* get format */
       objsize = ogetint(2)-OCTMAGIC;
                                   /* skip boundaries */
       for (i = 0; i < 4; i++)
              ogetstr(sbuf);
       nf = 0;                            /* load object files */
       while (*ogetstr(sbuf)) {
              rgl_load(sbuf);
              nf++;
       }
                                   /* get number of objects */
       fnobjects = m = ogetint(objsize);
       if (fnobjects != m)
              octerror(USER, "too many objects");

       if (nf == 0) {
              skiptree();
              for (i = 0; *ogetstr(sbuf); i++)
                     if ((otypmap[i] = otype(sbuf)) < 0) {
                            sprintf(errmsg, "unknown type \"%s\"", sbuf);
                            octerror(WARNING, errmsg);
                     }
              lu_init(&imtab, 1000); nobjects = 0;
              while (loadobj() != OVOID)
                     ;
              lu_done(&imtab);
              if (nobjects != fnobjects)
                     octerror(USER, "inconsistent object count");
       }
       fclose(infp);
       return(nf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int loadoctrees ( void  )

Definition at line 112 of file rglinst.c.

{
       int    levelsleft = MAXLEVEL;
       int    nocts = 0;
       LUTAB  looptab;
                            /* loop through new octree references */
       while (ottab.tsiz) {
              if (!levelsleft--)
                     error(USER, "too many octree levels -- instance loop?");
              looptab = ottab;
              ottab.tsiz = 0;
              nocts += lu_doall(&looptab, buildoctlist, NULL);
              lu_done(&looptab);
       }
       return(nocts);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int m_aniso ( OBJREC o)

Definition at line 147 of file rglmat.c.

{
       register MATREC      *m;
                                   /* check arguments */
       if (o->oargs.nfargs < (o->otype == MAT_TRANS2 ? 8 : 6))
              objerror(o, USER, "bad # of real arguments");
                                   /* allocate/insert material */
       m = newmaterial(o->oname);
                                   /* assign parameters */
       setcolor(m->u.m.ambdiff, o->oargs.farg[0],
                     o->oargs.farg[1], o->oargs.farg[2]);
       if ((m->type = o->otype) == MAT_METAL2)
              copycolor(m->u.m.specular, m->u.m.ambdiff);
       else
              setcolor(m->u.m.specular, 1., 1., 1.);
       scalecolor(m->u.m.specular, o->oargs.farg[3]);
       scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[3]);
       if (m->type == MAT_TRANS2) {
              scalecolor(m->u.m.specular, 1.-o->oargs.farg[6]);
              scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[6]);
       }
       if (o->oargs.farg[4]*o->oargs.farg[5] <= FTINY*FTINY)
              m->u.m.specexp = MAXSPECEXP;
       else
              m->u.m.specexp = 2./(o->oargs.farg[4]*o->oargs.farg[5]);
       if (m->u.m.specexp > MAXSPECEXP)
              m->u.m.specexp = MAXSPECEXP;
       return(0);
}

Here is the call graph for this function:

int m_brdf ( OBJREC o)

Definition at line 195 of file rglmat.c.

{
       register MATREC      *m;
                                   /* check arguments */
       if (o->oargs.nfargs < (o->otype == MAT_TFUNC ? 6 : 4))
              objerror(o, USER, "bad # of real arguments");
                                   /* allocate/insert material */
       m = newmaterial(o->oname);
                                   /* assign parameters */
       setcolor(m->u.m.ambdiff, o->oargs.farg[0],
                     o->oargs.farg[1], o->oargs.farg[2]);
       if ((m->type = o->otype) == MAT_MFUNC)
              copycolor(m->u.m.specular, m->u.m.ambdiff);
       else
              setcolor(m->u.m.specular, 1., 1., 1.);
       scalecolor(m->u.m.specular, o->oargs.farg[3]);
       scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[3]);
       if (m->type == MAT_TFUNC) {
              scalecolor(m->u.m.specular, 1.-o->oargs.farg[4]);
              scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[4]);
       }
       m->u.m.specexp = UNKSPECEXP;
       return(0);
}

Here is the call graph for this function:

int m_brdf2 ( OBJREC o)

Definition at line 223 of file rglmat.c.

{
       register MATREC      *m;

       if (o->oargs.nfargs < 9)
              objerror(o, USER, "bad # of real arguments");
       m = newmaterial(o->oname);
       m->type = o->otype;
                                   /* assign average diffuse front+back */
       setcolor(m->u.m.ambdiff, (o->oargs.farg[0]+o->oargs.farg[3])*.5,
                             (o->oargs.farg[1]+o->oargs.farg[4])*.5,
                             (o->oargs.farg[2]+o->oargs.farg[5])*.5);
                                   /* guess the rest */
       setcolor(m->u.m.specular, .1, .1, .1);
       m->u.m.specexp = UNKSPECEXP;
       return(0);
}

Here is the call graph for this function:

int m_glass ( OBJREC o)

Definition at line 180 of file rglmat.c.

{
       register MATREC      *m;

       m = newmaterial(o->oname);
       m->type = o->otype;
       setcolor(m->u.m.ambdiff, 0., 0., 0.);
       setcolor(m->u.m.specular, .08, .08, .08);
       m->u.m.specexp = MAXSPECEXP;
       return(0);
}

Here is the call graph for this function:

int m_light ( OBJREC o)

Definition at line 244 of file rglmat.c.

{
       FVECT  v;
       register MATREC      *m;

       if (o->oargs.nfargs < (o->otype == MAT_SPOT ? 7 : 3))
              objerror(o, USER, "bad # of real arguments");
       m = newmaterial(o->oname);
       setcolor(m->u.l.emission, o->oargs.farg[0],
                     o->oargs.farg[1], o->oargs.farg[2]);
       if ((m->type = o->otype) == MAT_SPOT) {
              if ((m->u.l.spotang = o->oargs.farg[3]/2.) > 90.)
                     m->u.l.spotang = 180.;
              v[0] = o->oargs.farg[4];
              v[1] = o->oargs.farg[5];
              v[2] = o->oargs.farg[6];
              if (normalize(v) == 0.)
                     objerror(o, USER, "illegal direction");
              VCOPY(m->u.l.spotdir, v);
       } else {
              m->u.l.spotang = 180.;
              m->u.l.spotdir[0] = m->u.l.spotdir[1] = 0.;
              m->u.l.spotdir[2] = -1.;
       }
       return(0);
}

Here is the call graph for this function:

int m_mirror ( OBJREC o)

Definition at line 274 of file rglmat.c.

{
       register MATREC      *m;

       if (o->oargs.nfargs != 3)
              objerror(o, USER, "bad # real arguments");
       m = newmaterial(o->oname);
       m->type = o->otype;
       setcolor(m->u.m.ambdiff, 0., 0., 0.);
       setcolor(m->u.m.specular, o->oargs.farg[0],
                     o->oargs.farg[1], o->oargs.farg[2]);
       m->u.m.specexp = MAXSPECEXP;
       return(0);
}

Here is the call graph for this function:

int m_normal ( OBJREC o)

Definition at line 114 of file rglmat.c.

{
       register MATREC      *m;
                                   /* check arguments */
       if (o->oargs.nfargs != (o->otype == MAT_TRANS ? 7 : 5))
              objerror(o, USER, "bad # of real arguments");
                                   /* allocate/insert material */
       m = newmaterial(o->oname);
                                   /* assign parameters */
       setcolor(m->u.m.ambdiff, o->oargs.farg[0],
                     o->oargs.farg[1], o->oargs.farg[2]);
       if ((m->type = o->otype) == MAT_METAL)
              copycolor(m->u.m.specular, m->u.m.ambdiff);
       else
              setcolor(m->u.m.specular, 1., 1., 1.);
       scalecolor(m->u.m.specular, o->oargs.farg[3]);
       scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[3]);
       if (m->type == MAT_TRANS) {
              scalecolor(m->u.m.specular, 1.-o->oargs.farg[5]);
              scalecolor(m->u.m.ambdiff, 1.-o->oargs.farg[5]);
       }
       if (o->oargs.farg[4] <= FTINY)
              m->u.m.specexp = MAXSPECEXP;
       else
              m->u.m.specexp = 2./(o->oargs.farg[4]*o->oargs.farg[4]);
       if (m->u.m.specexp > MAXSPECEXP)
              m->u.m.specexp = MAXSPECEXP;
       return(0);
}

Here is the call graph for this function:

int m_prism ( OBJREC o)

Definition at line 292 of file rglmat.c.

{
       register MATREC      *m;
                                   /* can't really deal with this type */
       m = newmaterial(o->oname);
       m->type = o->otype;
       setcolor(m->u.m.ambdiff, 0.2, 0.2, 0.2);
       setcolor(m->u.m.specular, 0.1, 0.1, 0.1);
       m->u.m.specexp = UNKSPECEXP;
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int newglist ( void  )

Definition at line 69 of file rglfile.c.

{
       if (!nlistleft--) {
              nextlist = glGenLists(NLIST2ALLOC);
              if (!nextlist)
                     error(SYSTEM, "no list space left in newglist");
              nlistleft = NLIST2ALLOC-1;
       }
       return(nextlist++);
}

Here is the call graph for this function:

Here is the caller graph for this function:

MATREC* newmaterial ( char *  nam)

Definition at line 77 of file rglmat.c.

{
       register LUENT       *lup;
                                   /* look it up (assign entry) */
       if ((lup = lu_find(&mtab, nam)) == NULL)
              goto memerr;
       if (lup->key == NULL) {            /* new entry? */
              lup->key = (char *)malloc(strlen(nam)+1);
              if (lup->key == NULL)
                     goto memerr;
              strcpy(lup->key, nam);
       } else if (lup->data != NULL)
              freemtl(lup->data);
       lup->data = (char *)malloc(sizeof(MATREC));
       if (lup->data == NULL)
              goto memerr;
       ((MATREC *)lup->data)->nlinks = 1;
       return((MATREC *)lup->data);
memerr:
       error(SYSTEM, "out of memory in newmaterial");
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int o_cone ( OBJREC o)

Definition at line 233 of file rglsurf.c.

{
       double x1, y1, h, d;
       FVECT  cent;
       register int  iscyl;

       iscyl = (o->otype==OBJ_CYLINDER) | (o->otype==OBJ_TUBE);
       if (o->oargs.nfargs != (iscyl ? 7 : 8))
              objerror(o, USER, "bad # real arguments");
       if (o->oargs.farg[6] < -FTINY) {
              o->oargs.farg[6] = -o->oargs.farg[6];
              if (iscyl)
                     o->otype = o->otype==OBJ_CYLINDER ?
                                   OBJ_TUBE : OBJ_CYLINDER;
              else {
                     if ((o->oargs.farg[7] = -o->oargs.farg[7]) < -FTINY)
                            objerror(o, USER, "illegal radii");
                     o->otype = o->otype==OBJ_CONE ? OBJ_CUP : OBJ_CONE;
              }
       } else if (!iscyl && o->oargs.farg[7] < -FTINY)
              objerror(o, USER, "illegal radii");
       if (o->oargs.farg[6] <= FTINY && (iscyl || o->oargs.farg[7] <= FTINY))
              return(0);
       if (!iscyl) {
              if (o->oargs.farg[6] < 0.)  /* complains for tiny neg's */
                     o->oargs.farg[6] = 0.;
              if (o->oargs.farg[7] < 0.)
                     o->oargs.farg[7] = 0.;
       }
       h = sqrt(dist2(o->oargs.farg,o->oargs.farg+3));
       if (h <= FTINY)
              return(0);
       cent[0] = .5*(o->oargs.farg[0] + o->oargs.farg[3]);
       cent[1] = .5*(o->oargs.farg[1] + o->oargs.farg[4]);
       cent[2] = .5*(o->oargs.farg[2] + o->oargs.farg[5]);
       setmaterial((MATREC *)o->os, cent, 0);
       if (gluqo == NULL) newquadric();
       glu_rout = "making cylinder";
       gluQuadricOrientation(gluqo, (o->otype==OBJ_CUP) | (o->otype==OBJ_TUBE) ?
                     GLU_INSIDE : GLU_OUTSIDE);
       gluQuadricNormals(gluqo, GLU_SMOOTH);
       glMatrixMode(GL_MODELVIEW);
       glPushMatrix();
                                   /* do base translation */
       glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1],
                     (GLdouble)o->oargs.farg[2]);
                                   /* compute height & rotation angle */
       x1 = o->oargs.farg[1] - o->oargs.farg[4];
       y1 = o->oargs.farg[3] - o->oargs.farg[0];
       /* z1 = 0; */
       d = x1*x1 + y1*y1;
       if (d <= FTINY*FTINY)
              x1 = 1.;
       else
              d = 180./PI * asin(sqrt(d) / h);
       if (o->oargs.farg[5] < o->oargs.farg[2])
              d = 180. - d;
       if (d > FTINY)
              glRotated(d, (GLdouble)x1, (GLdouble)y1, 0.);
       gluCylinder(gluqo, o->oargs.farg[6], o->oargs.farg[iscyl ? 6 : 7],
                     h, NSLICES, 1);
       glPopMatrix();
       return(0);
}

Here is the call graph for this function:

int o_default ( OBJREC o)

Definition at line 40 of file rglmat.c.

{
       register LUENT       *lup;
#ifdef DEBUG
       if (o->otype >= 0 && !ismodifier(o->otype))
              error(CONSISTENCY, "o_default handed non-modifier");
#endif
                                   /* find name in lookup table */
       if ((lup = lu_find(&mtab, o->oname)) == NULL)
              goto memerr;
       if (lup->key == NULL) {            /* new entry? */
              lup->key = (char *)malloc(strlen(o->oname)+1);
              if (lup->key == NULL)
                     goto memerr;
              strcpy(lup->key, o->oname);
       } else if (lup->data != NULL)
              freemtl(lup->data);
       if ((lup->data = o->os) != NULL)   /* make material reference */
              ((MATREC *)lup->data)->nlinks++;
       return(0);
memerr:
       error(SYSTEM, "out of memory in o_default");
       return(0);
}

Here is the call graph for this function:

int o_face ( OBJREC o)

Definition at line 135 of file rglsurf.c.

{
       double area;
       FVECT  norm, cent;
       register int  i;

       if ((o->oargs.nfargs < 9) | (o->oargs.nfargs % 3))
              objerror(o, USER, "bad # real arguments");
       area = polyarea(cent, norm, o->oargs.nfargs/3, (FVECT *)o->oargs.farg);
       if (area <= FTINY)
              return(0);
       if (dolights)                             /* check for source */
              doflatsrc((MATREC *)o->os, cent, norm, area);
       setmaterial((MATREC *)o->os, cent, 1);           /* set material */
       if (o->oargs.nfargs/3 != curpolysize) {
              if (curpolysize) glEnd();
              curpolysize = o->oargs.nfargs/3;
              if (curpolysize == 3)
                     glBegin(GL_TRIANGLES);
              else if (curpolysize == 4)
                     glBegin(GL_QUADS);
       }
       glNormal3d((GLdouble)norm[0], (GLdouble)norm[1], (GLdouble)norm[2]);
       if (curpolysize > 4) {
              if (gluto == NULL) newtess();
              glu_rout = "tessellating polygon";
              gluTessNormal(gluto, (GLdouble)norm[0],
                            (GLdouble)norm[1], (GLdouble)norm[2]);
              gluTessBeginPolygon(gluto, NULL);
              gluTessBeginContour(gluto);
#ifdef SMLFLT
              error(INTERNAL, "bad code segment in o_face");
#endif
              for (i = 0; i < curpolysize; i++)
                     gluTessVertex(gluto, (GLdouble *)(o->oargs.farg+3*i),
                                   (void *)(o->oargs.farg+3*i));
              gluTessEndContour(gluto);
              gluTessEndPolygon(gluto);
              curpolysize = 0;
       } else {
              for (i = 0; i < curpolysize; i++)
                     glVertex3d((GLdouble)o->oargs.farg[3*i],
                                   (GLdouble)o->oargs.farg[3*i+1],
                                   (GLdouble)o->oargs.farg[3*i+2]);
       }
       return(0);
}

Here is the call graph for this function:

int o_instance ( OBJREC o)

Definition at line 49 of file rglinst.c.

{
       XF     xfs;
       register OCTINST     *ot;
                                   /* set up */
       if (o->oargs.nsargs < 1)
              objerror(o, USER, "missing octree");
       setmaterial(NULL, NULL, 0);
                                   /* put out transform (if any) */
       if (o->oargs.nsargs > 1) {
              if (xf(&xfs, o->oargs.nsargs-1, o->oargs.sarg+1) !=
                            o->oargs.nsargs-1)
                     objerror(o, USER, "bad transform");
              glPushAttrib(GL_TRANSFORM_BIT);
              if ((xfs.sca < 1.-FTINY) | (xfs.sca > 1.+FTINY))
                     glEnable(GL_NORMALIZE);
              glMatrixMode(GL_MODELVIEW);
              glPushMatrix();
                                   /* matrix order works out to same */
#ifdef SMLFLT
              glMultMatrixf((GLfloat *)xfs.xfm);
#else
              glMultMatrixd((GLdouble *)xfs.xfm);
#endif
       }
       ot = getoct(o->oargs.sarg[0]);     /* get octree reference */
       if (ot->localmatl &= o->os != NULL)       /* set material */
              setmaterial((MATREC *)o->os, ot->cent, 0);
                                   /* call the assigned list */
       glCallList(ot->listid);

       if (o->oargs.nsargs > 1) {  /* end transform */
              glMatrixMode(GL_MODELVIEW);
              glPopMatrix();
              glPopAttrib();
       }
       rgl_checkerr("creating instance");
       return(0);
}

Here is the call graph for this function:

int o_ring ( OBJREC o)

Definition at line 301 of file rglsurf.c.

{
       double x1, y1, d, h;

       if (o->oargs.nfargs != 8)
              objerror(o, USER, "bad # real arguments");
       if (o->oargs.farg[7] < o->oargs.farg[6]) {
              register double      d = o->oargs.farg[7];
              o->oargs.farg[7] = o->oargs.farg[6];
              o->oargs.farg[6] = d;
       }
       if (o->oargs.farg[6] < -FTINY)
              objerror(o, USER, "negative radius");
       if (o->oargs.farg[6] < 0.)         /* complains for tiny neg's */
              o->oargs.farg[6] = 0.;
       if (o->oargs.farg[7] - o->oargs.farg[6] <= FTINY)
              return(0);
       h = VLEN(o->oargs.farg+3);
       if (h <= FTINY)
              return(0);
       if (dolights)
              doflatsrc((MATREC *)o->os, o->oargs.farg, o->oargs.farg+3, 
                            PI*(o->oargs.farg[7]*o->oargs.farg[7] -
                                   o->oargs.farg[6]*o->oargs.farg[6]));
       setmaterial((MATREC *)o->os, o->oargs.farg, 0);
       if (gluqo == NULL) newquadric();
       glu_rout = "making disk";
       gluQuadricOrientation(gluqo, GLU_OUTSIDE);
       gluQuadricNormals(gluqo, GLU_FLAT);
       glMatrixMode(GL_MODELVIEW);
       glPushMatrix();
       glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1],
                     (GLdouble)o->oargs.farg[2]);
                                   /* compute rotation angle */
       x1 = -o->oargs.farg[4];
       y1 = o->oargs.farg[3];
       /* z1 = 0; */
       d = x1*x1 + y1*y1;
       if (d <= FTINY*FTINY)
              x1 = 1.;
       else
              d = 180./PI * asin(sqrt(d) / h);
       if (o->oargs.farg[5] < 0.)
              d = 180. - d;
       if (d > FTINY)
              glRotated(d, (GLdouble)x1, (GLdouble)y1, 0.);
       gluDisk(gluqo, o->oargs.farg[6], o->oargs.farg[7], NSLICES, 1);
       glPopMatrix();
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int o_source ( OBJREC o)

Definition at line 101 of file rglsrc.c.

{
       if (!dolights || !issrcmat((MATREC *)o->os))
              return(0);
       if (o->oargs.nfargs != 4)
              objerror(o, USER, "bad # real arguments");
                                          /* record type & material */
       lightrec[nlights].type = L_SOURCE;
       (lightrec[nlights].m = (MATREC *)o->os)->nlinks++;
                                          /* assign direction */
       VCOPY(lightrec[nlights].pos, o->oargs.farg);
                                          /* compute solid angle */
       if (o->oargs.farg[3] <= FTINY)
              objerror(o, USER, "zero size");
       lightrec[nlights].area = 2.*PI*(1. - cos(PI/180./2.*o->oargs.farg[3]));
       nlights++; dolights--;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int o_sphere ( OBJREC o)

Definition at line 202 of file rglsurf.c.

{
                                   /* check arguments */
       if (o->oargs.nfargs != 4)
              objerror(o, USER, "bad # real arguments");
       if (o->oargs.farg[3] < -FTINY) {
              o->otype = o->otype==OBJ_SPHERE ? OBJ_BUBBLE : OBJ_SPHERE;
              o->oargs.farg[3] = -o->oargs.farg[3];
       } else if (o->oargs.farg[3] <= FTINY)
              return(0);
       if (dolights)
              dosphsrc((MATREC *)o->os, o->oargs.farg,
                            PI*o->oargs.farg[3]*o->oargs.farg[3]);
       setmaterial((MATREC *)o->os, o->oargs.farg, 0);
       if (gluqo == NULL) newquadric();
       glu_rout = "making sphere";
       gluQuadricOrientation(gluqo,
                     o->otype==OBJ_BUBBLE ? GLU_INSIDE : GLU_OUTSIDE);
       gluQuadricNormals(gluqo, GLU_SMOOTH);
       glMatrixMode(GL_MODELVIEW);
       glPushMatrix();
       glTranslated((GLdouble)o->oargs.farg[0], (GLdouble)o->oargs.farg[1],
                     (GLdouble)o->oargs.farg[2]);
       gluSphere(gluqo, (GLdouble)o->oargs.farg[3], NSLICES, NSTACKS);
       glPopMatrix();
       return(0);
}

Here is the call graph for this function:

int o_unsupported ( OBJREC o)

Definition at line 68 of file rglmat.c.

{
       objerror(o, WARNING, "unsupported type");
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double polyarea ( FVECT  cent,
FVECT  norm,
int  n,
FVECT  v[] 
)

Here is the caller graph for this function:

void rgl_checkerr ( char *  where)

Definition at line 82 of file rglfile.c.

{
       register GLenum      errcode;

       while ((errcode = glGetError()) != GL_NO_ERROR) {
              sprintf(errmsg, "OpenGL error %s: %s",
                            where, gluErrorString(errcode));
              error(WARNING, errmsg);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rgl_filelist ( int  ic,
char **  inp,
int *  nl 
)

Definition at line 96 of file rglfile.c.

{
       int    listid;

       initotypes();        /* prepare */
       listid = newglist();
       glNewList(listid, GL_COMPILE);
       lightinit();         /* start light source list */
       while (ic--)         /* load each file */
              rgl_load(*inp++);
       surfclean();         /* clean up first pass */
       lightclean();        /* clean up light sources also */
       glEndList();         /* end of top display list */
       lightdefs();         /* define light sources */
       loadoctrees();              /* load octrees (sublists) for instances */
       if (nl != NULL)             /* return total number of lists allocated */
              *nl = nextlist - listid;
       return(listid);             /* all done -- return list id */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rgl_load ( char *  inpspec)

Definition at line 151 of file rglfile.c.

{
       char   *fgetline();
       FILE   *infp;
       char   buf[1024];
       register int  c;

       if (inpspec == NULL) {
              infp = stdin;
              inpspec = "standard input";
       } else if (inpspec[0] == '!') {
              if ((infp = popen(inpspec+1, "r")) == NULL) {
                     sprintf(errmsg, "cannot execute \"%s\"", inpspec);
                     error(SYSTEM, errmsg);
              }
       } else if ((infp = fopen(inpspec, "r")) == NULL) {
              sprintf(errmsg, "cannot open scene file \"%s\"", inpspec);
              error(SYSTEM, errmsg);
       }
       while ((c = getc(infp)) != EOF) {
              if (isspace(c))
                     continue;
              if (c == '#') {                           /* comment */
                     fgets(buf, sizeof(buf), infp);
              } else if (c == '!') {                    /* command */
                     ungetc(c, infp);
                     fgetline(buf, sizeof(buf), infp);
                     rgl_load(buf);
              } else {                           /* object */
                     ungetc(c, infp);
                     rgl_object(inpspec, infp);
              }
       }
       if (inpspec[0] == '!')
              pclose(infp);
       else
              fclose(infp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rgl_matclear ( void  )

Definition at line 18 of file rglmat.c.

{
       lu_done(&mtab);
       domats = 1;
}

Here is the call graph for this function:

void rgl_object ( char *  name,
FILE *  fp 
)

Definition at line 193 of file rglfile.c.

{
       static OBJREC ob;
       char  sbuf[MAXSTR];
       int  rval;
                                   /* get modifier */
       strcpy(sbuf, "EOF");
       fgetword(sbuf, MAXSTR, fp);
       ob.omod = 0;                /* use ob.os for pointer to material */
       if (!strcmp(sbuf, VOIDID) || !strcmp(sbuf, ALIASMOD))
              ob.os = NULL;
       else
              ob.os = (char *)getmatp(sbuf);
                                   /* get type */
       strcpy(sbuf, "EOF");
       fgetword(sbuf, MAXSTR, fp);
       if ((ob.otype = otype(sbuf)) < 0) {
              sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf);
              error(USER, errmsg);
       }
                                   /* get identifier */
       sbuf[0] = '\0';
       fgetword(sbuf, MAXSTR, fp);
       ob.oname = sbuf;
                                   /* get arguments */
       if (ob.otype == MOD_ALIAS) {
              char  sbuf2[MAXSTR];        /* get alias */
              strcpy(sbuf2, "EOF");
              fgetword(sbuf2, MAXSTR, fp);
              if (ob.os == NULL)
                     ob.os = (char *)getmatp(sbuf2);
              o_default(&ob);                    /* fake reference */
              return;
       }
       if ((rval = readfargs(&ob.oargs, fp)) == 0) {
              sprintf(errmsg, "(%s): bad arguments", name);
              objerror(&ob, USER, errmsg);
       } else if (rval < 0) {
              sprintf(errmsg, "(%s): error reading scene", name);
              error(SYSTEM, errmsg);
       }
                                   /* execute */
       (*ofun[ob.otype].funp)(&ob);
                                   /* free arguments */
       freefargs(&ob.oargs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rgl_octlist ( char *  fname,
FVECT  cent,
RREAL radp,
int *  nl 
)

Definition at line 121 of file rglfile.c.

{
       double r;
       int    listid;
                            /* modeled after rgl_filelist() */
       initotypes();
                            /* check the octree and get its size */
       r = checkoct(fname, cent);
       if (radp != NULL) *radp = r;
                            /* start the display list */
       listid = newglist();
       glNewList(listid, GL_COMPILE);
       lightinit();         /* start light source list */
       loadoct(fname);             /* load octree objects into display list */
       surfclean();         /* clean up and close top list */
       lightclean();        /* clean up light sources also */
       glEndList();         /* close top list */
       lightdefs();         /* define light sources */
       loadoctrees();              /* load referenced octrees into sublists */
       if (nl != NULL)             /* return total number of lists allocated */
              *nl = nextlist - listid;
       return(listid);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void setmaterial ( MATREC mp,
FVECT  cent,
int  ispoly 
)

Definition at line 32 of file rglsurf.c.

{
       if (mp != curmat && domats) {
              NOPOLY();
              domatobj(curmat = mp, cent);
       } else if (!ispoly) {
              NOPOLY();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void surfclean ( void  )

Definition at line 186 of file rglsurf.c.

{
       setmaterial(NULL, NULL, 0);
       if (gluqo != NULL) {
              gluDeleteQuadric(gluqo);
              gluqo = NULL;
       }
       if (gluto != NULL) {
              gluDeleteTess(gluto);
              gluto = NULL;
       }
       rgl_checkerr("in surfclean");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

static double ambval

Definition at line 658 of file rad.c.

{
       if (vdef(EXPOSURE)) {
              if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
                     return(.5/pow(2.,vflt(EXPOSURE)));
              return(.5/vflt(EXPOSURE));
       }
       if (vlet(ZONE) == 'E')
              return(10.);
       if (vlet(ZONE) == 'I')
              return(.01);
       badvalue(ZONE);
       return 0; /* pro forma return */
}
int dolights

Definition at line 16 of file rglsrc.c.

int domats

Definition at line 12 of file rglmat.c.

double expval

Definition at line 12 of file rglsrc.c.

Definition at line 18 of file rglsrc.c.

Definition at line 14 of file rglmat.c.