Back to index

radiance  4R0+20100331
Functions | Variables
rglmat.c File Reference
#include "copyright.h"
#include "radogl.h"

Go to the source code of this file.

Functions

void rgl_matclear ()
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)

Variables

static const char RCSid [] = "$Id: rglmat.c,v 3.6 2003/11/14 17:22:06 schorsch Exp $"
int domats = 1
LUTAB mtab = LU_SINIT(free,freemtl)

Function Documentation

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:

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:

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_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_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:

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:


Variable Documentation

int domats = 1

Definition at line 12 of file rglmat.c.

Definition at line 14 of file rglmat.c.

const char RCSid[] = "$Id: rglmat.c,v 3.6 2003/11/14 17:22:06 schorsch Exp $" [static]

Definition at line 2 of file rglmat.c.