Back to index

radiance  4R0+20100331
Defines | Functions | Variables
rhdobj.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DO_LOAD   0 /* load octree object */
#define DO_UNLOAD   1 /* unload (free) octree object */
#define DO_XFORM   2 /* set/print object transform */
#define DO_MOVE   3 /* add to object transform */
#define DO_UNMOVE   4 /* undo last transform change */
#define DO_DUP   5 /* duplicate object */
#define DO_SHOW   6 /* show object (low quality) */
#define DO_LIGHT   7 /* illuminate object (high quality) */
#define DO_HIDE   8 /* hide object */
#define DO_OBJECT   9 /* print object statistics */
#define DO_NCMDS   10 /* number of object display commands */
#define DO_INIT

Functions

int dobj_cleanup (void)
int dobj_command (char *cmd, register char *args)
int dobj_render (void)
double dobj_trace (char nm[], FVECT rorg, FVECT rdir)
int dobj_load (char *oct, char *nam)
int dobj_unload (char *nam)
int dobj_xform (char *nam, int rel, int ac, char **av)
int dobj_putstats (char *nam, FILE *fp)
int dobj_unmove (void)
int dobj_dup (char *oldnm, char *nam)
int dobj_lighting (char *nam, int cn)

Variables

TMstructtmGlobal
char rhdcmd [DO_NCMDS][8]
void(* dobj_lightsamp )(COLR clr, FVECT direc, FVECT pos)

Define Documentation

#define DO_DUP   5 /* duplicate object */

Definition at line 18 of file rhdobj.h.

#define DO_HIDE   8 /* hide object */

Definition at line 21 of file rhdobj.h.

#define DO_INIT
Value:
{"load","clear","xform","move","unmove","dup",\
                            "show","light","hide","object"}

Definition at line 27 of file rhdobj.h.

#define DO_LIGHT   7 /* illuminate object (high quality) */

Definition at line 20 of file rhdobj.h.

#define DO_LOAD   0 /* load octree object */

Definition at line 13 of file rhdobj.h.

#define DO_MOVE   3 /* add to object transform */

Definition at line 16 of file rhdobj.h.

#define DO_NCMDS   10 /* number of object display commands */

Definition at line 24 of file rhdobj.h.

#define DO_OBJECT   9 /* print object statistics */

Definition at line 22 of file rhdobj.h.

#define DO_SHOW   6 /* show object (low quality) */

Definition at line 19 of file rhdobj.h.

#define DO_UNLOAD   1 /* unload (free) octree object */

Definition at line 14 of file rhdobj.h.

#define DO_UNMOVE   4 /* undo last transform change */

Definition at line 17 of file rhdobj.h.

#define DO_XFORM   2 /* set/print object transform */

Definition at line 15 of file rhdobj.h.


Function Documentation

int dobj_cleanup ( void  )

Definition at line 640 of file rhdobj.c.

{
       register DLIGHTS     *lp;

       while (dobjects != NULL)
              freedobj(dobjects);
       savedxf(curobj = NULL);
       while ((lp = dlightsets) != NULL) {
              dlightsets = lp->next;
              free((void *)lp);
       }
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_command ( char *  cmd,
register char *  args 
)

Definition at line 455 of file rhdobj.c.

{
       int    somechange = 0;
       int    cn, na;
       register int  nn;
       char   *alist[MAXAC+1], *nm;
                                   /* find command */
       for (cn = 0; cn < DO_NCMDS; cn++)
              if (!strcmp(cmd, rhdcmd[cn]))
                     break;
       if (cn >= DO_NCMDS)
              return(-1);          /* not in our list */
                                   /* make argument list */
       for (na = 0; *args; na++) {
              if (na > MAXAC)
                     goto toomany;
              alist[na] = args;
              while (*args && !isspace(*args))
                     args++;
              while (isspace(*args))
                     *args++ = '\0';
       }
       alist[na] = NULL;
                                   /* execute command */
       switch (cn) {
       case DO_LOAD:                      /* load an octree */
              if (na == 1)
                     dobj_load(alist[0], alist[0]);
              else if (na == 2)
                     dobj_load(alist[0], alist[1]);
              else {
                     cmderror(cn, "need octree [name]");
                     return(0);
              }
              break;
       case DO_UNLOAD:                           /* clear an object */
              if (na > 1) goto toomany;
              if (na && alist[0][0] == '*')
                     somechange += dobj_cleanup();
              else
                     somechange += dobj_unload(na ? alist[0] : curname);
              break;
       case DO_XFORM:                            /* transform object */
       case DO_MOVE:
              if (na && alist[0][0] != '-') {
                     nm = alist[0]; nn = 1;
              } else {
                     nm = curname; nn = 0;
              }
              if (cn == DO_MOVE && nn >= na) {
                     cmderror(cn, "missing transform");
                     return(0);
              }
              somechange += dobj_xform(nm, cn==DO_MOVE, na-nn, alist+nn);
              break;
       case DO_UNMOVE:                           /* undo last transform */
              somechange += dobj_unmove();
              break;
       case DO_OBJECT:                           /* print object statistics */
              if (dobj_putstats(na ? alist[0] : curname, sstdout))
                     if (na && alist[0][0] != '*' && (curobj == NULL ||
                                   strcmp(alist[0], curobj->name)))
                            savedxf(curobj = getdobj(alist[0]));
              break;
       case DO_DUP:                       /* duplicate object */
              for (nn = 0; nn < na; nn++)
                     if (alist[nn][0] == '-')
                            break;
              switch (nn) {
              case 0:
                     cmderror(cn, "need new object name");
                     return(0);
              case 1:
                     nm = curname;
                     break;
              case 2:
                     nm = alist[0];
                     break;
              default:
                     goto toomany;
              }
              if (!dobj_dup(nm, alist[nn-1]))
                     break;
              if (na > nn)
                     somechange += dobj_xform(curname, 1, na-nn, alist+nn);
              else
                     curobj->drawcode = DO_HIDE;
              savedxf(curobj);
              break;
       case DO_SHOW:                      /* change rendering option */
       case DO_LIGHT:
       case DO_HIDE:
              if (na > 1) goto toomany;
              dobj_lighting(na ? alist[0] : curname, cn);
              somechange++;
              break;
       default:
              error(CONSISTENCY, "bad command id in dobj_command");
       }
       return(somechange);
toomany:
       cmderror(cn, "too many arguments");
       return(-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_dup ( char *  oldnm,
char *  nam 
)

Definition at line 791 of file rhdobj.c.

{
       register DOBJECT     *op, *opdup;
                                   /* check arguments */
       if ((op = getdobj(oldnm)) == NULL) {
              error(COMMAND, "no object");
              return(0);
       }
       if (nam == NULL) {
              error(COMMAND, "missing name");
              return(0);
       }
       if ((*nam == '*') | (*nam == '-')) {
              error(COMMAND, "illegal name");
              return(0);
       }
       if (getdobj(nam) != NULL) {
              error(COMMAND, "name already taken (clear first)");
              return(0);
       }
                                   /* allocate and copy struct */
       opdup = (DOBJECT *)malloc(sizeof(DOBJECT));
       if (opdup == NULL)
              error(SYSTEM, "out of memory in dobj_dup");
       *opdup = *op;
                                   /* rename */
       strcpy(opdup->name, nam);
                                   /* get our own copy of transform */
       for (opdup->xfac = 0; opdup->xfac < op->xfac; opdup->xfac++)
              opdup->xfav[opdup->xfac] = savestr(op->xfav[opdup->xfac]);
       opdup->xfav[opdup->xfac] = NULL;
                                   /* insert it into our list */
       opdup->next = dobjects;
       curobj = dobjects = opdup;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_lighting ( char *  nam,
int  cn 
)

Definition at line 833 of file rhdobj.c.

{
       int    i, res[2];
       VIEW   *dv;
       register DOBJECT     *op;

       if (nam == NULL) {
              error(COMMAND, "no current object");
              return(0);
       }
       if (nam[0] == '*') {
              for (op = dobjects; op != NULL; op = op->next)
                     if ((op->drawcode = cn) == DO_LIGHT)
                            getdlights(op, 1);
                     else
                            op->ol = NULL;
       } else if ((op = getdobj(nam)) == NULL) {
              error(COMMAND, "unknown object");
              return(0);
       } else if ((op->drawcode = cn) == DO_LIGHT) {
              if (!getdlights(op, 1))
                     error(COMMAND, "insufficient samples to light object");
       } else
              op->ol = NULL;

       if (dobj_lightsamp != NULL) {             /* restore beam set */
              dobj_lightsamp = NULL;
              beam_init(1);
              for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++)
                     beam_view(dv, res[0], res[1]);
              beam_sync(1);               /* update server */
       }
       return 0; /* XXX not sure if this is the right value */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_load ( char *  oct,
char *  nam 
)

Definition at line 565 of file rhdobj.c.

{
       char   *fpp, fpath[128];
       register DOBJECT     *op;
                                   /* check arguments */
       if (oct == NULL) {
              error(COMMAND, "missing octree");
              return(0);
       }
       if (nam == NULL) {
              error(COMMAND, "missing name");
              return(0);
       }
       if ((*nam == '*') | (*nam == '-')) {
              error(COMMAND, "illegal name");
              return(0);
       }
       if (getdobj(nam) != NULL) {
              error(COMMAND, "name already taken (clear first)");
              return(0);
       }
                                   /* get octree path */
       if ((fpp = getpath(oct, getrlibpath(), R_OK)) == NULL) {
              sprintf(errmsg, "cannot find octree \"%s\"", oct);
              error(COMMAND, errmsg);
              return(0);
       }
       strcpy(fpath, fpp);
       op = (DOBJECT *)malloc(sizeof(DOBJECT));
       if (op == NULL)
              error(SYSTEM, "out of memory in dobj_load");
                                   /* set struct fields */
       strcpy(op->name, nam);
       op->ol = NULL;
       op->drawcode = DO_HIDE;
       setident4(op->xfb.f.xfm); op->xfb.f.sca = 1.;
       setident4(op->xfb.b.xfm); op->xfb.b.sca = 1.;
       op->xfav[op->xfac=0] = NULL;
                                   /* load octree into display list */
       dolights = 0;
       domats = 1;
       op->listid = rgl_octlist(fpath, op->center, &op->radius, &op->nlists);
                                   /* start rtrace */
       rtargv[RTARGC-1] = fpath;
       rtargv[RTARGC] = NULL;
       open_process(&(op->rtp), rtargv);
                                   /* insert into main list */
       op->next = dobjects;
       curobj = dobjects = op;
       savedxf(NULL);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_putstats ( char *  nam,
FILE *  fp 
)

Definition at line 721 of file rhdobj.c.

{
       FVECT  ocent;
       register DOBJECT     *op;
       register int  i;

       if (nam == NULL) {
              error(COMMAND, "no current object");
              return(0);
       }
       if (nam[0] == '*') {
              i = 0;
              for (op = dobjects; op != NULL; op = op->next)
                     i += dobj_putstats(op->name, fp);
              return(i);
       }
       if ((op = getdobj(nam)) == NULL) {
              error(COMMAND, "unknown object");
              return(0);
       }
       getdcent(ocent, op);
       fprintf(fp, "%s: %s, center [%g %g %g], radius %g", op->name,
                     op->drawcode==DO_HIDE ? "hidden" :
                     op->drawcode==DO_LIGHT && op->ol!=NULL ? "lighted" :
                     "shown",
                     ocent[0],ocent[1],ocent[2], getdrad(op));
       if (op->xfac)
              fputs(", (xform", fp);
       for (i = 0; i < op->xfac; i++) {
              putc(' ', fp);
              fputs(op->xfav[i], fp);
       }
       if (op->xfac)
              fputc(')', fp);
       fputc('\n', fp);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_render ( void  )

Definition at line 922 of file rhdobj.c.

{
       int    nrendered = 0;
       GLboolean     normalizing;
       GLfloat       vec[4];
       FVECT  v1;
       register DOBJECT     *op;
       register int  i;
                                   /* anything to render? */
       for (op = dobjects; op != NULL; op = op->next)
              if (op->drawcode != DO_HIDE)
                     break;
       if (op == NULL)
              return(0);
                                   /* set up general rendering params */
       glGetBooleanv(GL_NORMALIZE, &normalizing);
       glPushAttrib(GL_LIGHTING_BIT|GL_TRANSFORM_BIT|GL_ENABLE_BIT|
              GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_POLYGON_BIT);
       glDepthFunc(GL_LESS);
       glEnable(GL_DEPTH_TEST);
       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
       glShadeModel(GL_SMOOTH);
       glFrontFace(GL_CCW);
       glDisable(GL_CULL_FACE);
       for (i = MAXLIGHTS; i--; )
              glDisable(glightid[i]);
       glEnable(GL_LIGHTING);
       rgl_checkerr("setting rendering modes in dobj_render");
                                   /* render each object */
       for (op = dobjects; op != NULL; op = op->next) {
              if (op->drawcode == DO_HIDE)
                     continue;
                                   /* set up lighting */
              if (op->drawcode == DO_LIGHT && op->ol != NULL) {
                     BYTE   pval;
                     double expval, d;
                                          /* use computed sources */
                     if (tmMapPixels(tmGlobal, &pval, &op->ol->larb,
                                   TM_NOCHROM, 1) != TM_E_OK)
                            error(CONSISTENCY, "dobj_render w/o tone map");
                     expval = pval * (WHTEFFICACY/256.) /
                                   tmLuminance(op->ol->larb);
                     vec[0] = expval * colval(op->ol->lamb,RED);
                     vec[1] = expval * colval(op->ol->lamb,GRN);
                     vec[2] = expval * colval(op->ol->lamb,BLU);
                     vec[3] = 1.;
                     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec);
                     for (i = op->ol->nl; i--; ) {
                            VCOPY(vec, op->ol->li[i].direc);
                            vec[3] = 0.;
                            glLightfv(glightid[i], GL_POSITION, vec);
                            d = expval * op->ol->li[i].omega;
                            vec[0] = d * colval(op->ol->li[i].val,RED);
                            vec[1] = d * colval(op->ol->li[i].val,GRN);
                            vec[2] = d * colval(op->ol->li[i].val,BLU);
                            vec[3] = 1.;
                            glLightfv(glightid[i], GL_SPECULAR, vec);
                            glLightfv(glightid[i], GL_DIFFUSE, vec);
                            vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
                            glLightfv(glightid[i], GL_AMBIENT, vec);
                            glEnable(glightid[i]);
                     }
              } else {                    /* fake lighting */
                     vec[0] = vec[1] = vec[2] = 0.; vec[3] = 1.;
                     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, vec);
                     getdcent(v1, op);
                     VSUB(v1, odev.v.vp, v1);
                     if (normalize(v1) <= getdrad(op)) {
                            vec[0] = -odev.v.vdir[0];
                            vec[1] = -odev.v.vdir[1];
                            vec[2] = -odev.v.vdir[2];
                     } else
                            VCOPY(vec, v1);
                     vec[3] = 0.;
                     glLightfv(GL_LIGHT0, GL_POSITION, vec);
                     vec[0] = vec[1] = vec[2] = .7; vec[3] = 1.;
                     glLightfv(GL_LIGHT0, GL_SPECULAR, vec);
                     glLightfv(GL_LIGHT0, GL_DIFFUSE, vec);
                     vec[0] = vec[1] = vec[2] = .3; vec[3] = 1.;
                     glLightfv(GL_LIGHT0, GL_AMBIENT, vec);
                     glEnable(GL_LIGHT0);
              }
                                   /* set up object transform */
              if (op->xfac) {
                     if (!normalizing && (op->xfb.f.sca < 1.-FTINY) |
                                          (op->xfb.f.sca > 1.+FTINY))
                            glEnable(GL_NORMALIZE);
                     glMatrixMode(GL_MODELVIEW);
                     glPushMatrix();
                                   /* matrix order works out to same */
#ifdef SMLFLT
                     glMultMatrixf((GLfloat *)op->xfb.f.xfm);
#else
                     glMultMatrixd((GLdouble *)op->xfb.f.xfm);
#endif
              }
                                   /* render the display list */
              glCallList(op->listid);
              nrendered++;
                                   /* restore matrix */
              if (op->xfac) {
                     glMatrixMode(GL_MODELVIEW);
                     glPopMatrix();
                     if (!normalizing)
                            glDisable(GL_NORMALIZE);
              }
                                   /* restore lighting */
              if (op->drawcode == DO_LIGHT && op->ol != NULL)
                     for (i = op->ol->nl; i--; )
                            glDisable(glightid[i]);
              else
                     glDisable(GL_LIGHT0);
                                   /* check errors */
       }
       glPopAttrib();                     /* restore rendering params */
       rgl_checkerr("rendering objects in dobj_render");
       return(nrendered);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double dobj_trace ( char  nm[],
FVECT  rorg,
FVECT  rdir 
)

Definition at line 873 of file rhdobj.c.

{
       register DOBJECT     *op;
       FVECT  xorg, xdir;
       double darr[6];
                                   /* check each visible object? */
       if (nm == NULL || *nm == '*') {
              double dist, mindist = 1.01*FHUGE;

              if (nm != NULL) nm[0] = '\0';
              for (op = dobjects; op != NULL; op = op->next) {
                     if (op->drawcode == DO_HIDE)
                            continue;
                     dist = dobj_trace(op->name, rorg, rdir);
                     if (dist < mindist) {
                            if (nm != NULL) strcpy(nm, op->name);
                            mindist = dist;
                     }
              }
              return(mindist);
       }
                                   /* else check particular object */
       if ((op = getdobj(nm)) == NULL) {
              error(COMMAND, "unknown object");
              return(FHUGE);
       }
       if (op->xfac) {             /* put ray in local coordinates */
              multp3(xorg, rorg, op->xfb.b.xfm);
              multv3(xdir, rdir, op->xfb.b.xfm);
              VCOPY(darr, xorg); VCOPY(darr+3, xdir);
       } else {
              VCOPY(darr, rorg); VCOPY(darr+3, rdir);
       }
                            /* trace it */
       if (process(&(op->rtp), (char *)darr, (char *)darr, sizeof(double),
                     6*sizeof(double)) != sizeof(double))
              error(SYSTEM, "rtrace communication error");
                            /* return distance */
       if (darr[0] >= .99*FHUGE)
              return(FHUGE);
       return(darr[0]*op->xfb.f.sca);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_unload ( char *  nam)

Definition at line 623 of file rhdobj.c.

{
       register DOBJECT     *op;

       if ((op = getdobj(nam)) == NULL) {
              error(COMMAND, "no object");
              return(0);
       }
       freedobj(op);
       savedxf(curobj = NULL);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_unmove ( void  )

Definition at line 764 of file rhdobj.c.

{
       int    txfac;
       char   *txfav[MAXAC+1];

       if (curobj == NULL) {
              error(COMMAND, "no current object");
              return(0);
       }
                                   /* hold last transform */
       memcpy((void *)txfav, (void *)lastxfav, 
                     (txfac=lastxfac)*sizeof(char *));
                                   /* save this transform */
       memcpy((void *)lastxfav, (void *)curobj->xfav, 
                     (lastxfac=curobj->xfac)*sizeof(char *));
                                   /* copy back last transform */
       memcpy((void *)curobj->xfav, (void *)txfav, 
                     (curobj->xfac=txfac)*sizeof(char *));
                                   /* set matrices */
       fullxf(&curobj->xfb, curobj->xfac, curobj->xfav);
                                   /* don't know local lights anymore */
       getdlights(curobj, 0);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dobj_xform ( char *  nam,
int  rel,
int  ac,
char **  av 
)

Definition at line 656 of file rhdobj.c.

{
       register DOBJECT     *op;
       FVECT  cent;
       double rad;
       char   scoord[16];
       int    i;

       if ((op = getdobj(nam)) == NULL) {
              error(COMMAND, "no object");
              return(0);
       }
       if (rel)
              rel = op->xfac + 8;
       if (ac + rel > MAXAC) {
              error(COMMAND, "too many transform arguments");
              return(0);
       }
       savedxf(curobj = op);              /* remember current transform */
       if (rel && ac == 4 && !strcmp(av[0], "-t"))
              rel = -1;                   /* don't move for translate */
       else {
              getdcent(cent, op);         /* don't move if near orig. */
              rad = getdrad(op);
              if (DOT(cent,cent) < rad*rad)
                     rel = -1;
       }
       if (!rel) {                        /* remove old transform */
              while (op->xfac)
                     freestr(op->xfav[--op->xfac]);
       } else if (rel > 0) {                     /* relative move */
              op->xfav[op->xfac++] = savestr("-t");
              for (i = 0; i < 3; i++) {
                     sprintf(scoord, "%.4e", -cent[i]);
                     op->xfav[op->xfac++] = savestr(scoord);
              }
       }
       while (ac--)
              op->xfav[op->xfac++] = savestr(*av++);
       if (rel > 0) {                            /* move back */
              op->xfav[op->xfac++] = savestr("-t");
              for (i = 0; i < 3; i++) {
                     sprintf(scoord, "%.4e", cent[i]);
                     op->xfav[op->xfac++] = savestr(scoord);
              }
       }
       op->xfav[op->xfac] = NULL;
       if (fullxf(&op->xfb, op->xfac, op->xfav) != op->xfac) {
              error(COMMAND, "bad transform arguments");
              dobj_unmove();
              savedxf(op);         /* save current transform instead */
              return(0);
       }
                                   /* don't know local lights anymore */
       getdlights(op, 0);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

void(* dobj_lightsamp)(COLR clr, FVECT direc, FVECT pos)

Definition at line 23 of file rhdobj.c.

char rhdcmd[DO_NCMDS][8]

Definition at line 20 of file rhdobj.c.

Definition at line 64 of file rhd_glx1.c.