| 1 |
/* Copyright (c) 1988 Regents of the University of California */
|
| 2 |
|
| 3 |
#ifndef lint
|
| 4 |
static char SCCSid[] = "$SunId$ LBL";
|
| 5 |
#endif
|
| 6 |
|
| 7 |
/*
|
| 8 |
* instance.c - routines for octree objects.
|
| 9 |
*
|
| 10 |
* 11/10/88
|
| 11 |
*/
|
| 12 |
|
| 13 |
#include "standard.h"
|
| 14 |
|
| 15 |
#include "object.h"
|
| 16 |
|
| 17 |
#include "instance.h"
|
| 18 |
|
| 19 |
static SCENE *slist = NULL; /* list of loaded octrees */
|
| 20 |
|
| 21 |
|
| 22 |
SCENE *
|
| 23 |
getscene(sname, flags) /* load octree sname */
|
| 24 |
char *sname;
|
| 25 |
int flags;
|
| 26 |
{
|
| 27 |
extern char *libpath;
|
| 28 |
char *pathname;
|
| 29 |
register SCENE *sc;
|
| 30 |
|
| 31 |
flags &= ~IO_FILES; /* not allowed */
|
| 32 |
for (sc = slist; sc != NULL; sc = sc->next)
|
| 33 |
if (!strcmp(sname, sc->name)) {
|
| 34 |
if ((sc->ldflags & flags) == flags)
|
| 35 |
return(sc); /* loaded */
|
| 36 |
break; /* load the rest */
|
| 37 |
}
|
| 38 |
if (sc == NULL) {
|
| 39 |
sc = (SCENE *)malloc(sizeof(SCENE));
|
| 40 |
if (sc == NULL)
|
| 41 |
error(SYSTEM, "out of memory in getscene");
|
| 42 |
sc->name = savestr(sname);
|
| 43 |
sc->ldflags = 0;
|
| 44 |
sc->next = slist;
|
| 45 |
slist = sc;
|
| 46 |
}
|
| 47 |
if ((pathname = getpath(sname, libpath)) == NULL) {
|
| 48 |
sprintf(errmsg, "cannot find octree file \"%s\"", sname);
|
| 49 |
error(USER, errmsg);
|
| 50 |
}
|
| 51 |
readoct(pathname, flags & ~sc->ldflags, &sc->scube, NULL);
|
| 52 |
sc->ldflags |= flags;
|
| 53 |
return(sc);
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
INSTANCE *
|
| 58 |
getinstance(o, flags) /* get instance structure */
|
| 59 |
register OBJREC *o;
|
| 60 |
int flags;
|
| 61 |
{
|
| 62 |
register INSTANCE *in;
|
| 63 |
|
| 64 |
if ((in = (INSTANCE *)o->os) == NULL) {
|
| 65 |
if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL)
|
| 66 |
error(SYSTEM, "out of memory in getinstance");
|
| 67 |
if (o->oargs.nsargs < 1)
|
| 68 |
objerror(o, USER, "bad # of arguments");
|
| 69 |
in->f.sca = 1.0;
|
| 70 |
setident4(in->f.xfm);
|
| 71 |
if (xf(in->f.xfm, &in->f.sca, o->oargs.nsargs-1,
|
| 72 |
o->oargs.sarg+1) != o->oargs.nsargs-1)
|
| 73 |
objerror(o, USER, "bad transform");
|
| 74 |
if (in->f.sca < 0.0)
|
| 75 |
in->f.sca = -in->f.sca;
|
| 76 |
in->b.sca = 1.0;
|
| 77 |
setident4(in->b.xfm);
|
| 78 |
invxf(in->b.xfm, &in->b.sca,o->oargs.nsargs-1,o->oargs.sarg+1);
|
| 79 |
if (in->b.sca < 0.0)
|
| 80 |
in->b.sca = -in->b.sca;
|
| 81 |
in->obj = NULL;
|
| 82 |
(INSTANCE *)o->os = in;
|
| 83 |
}
|
| 84 |
if (in->obj == NULL || (in->obj->ldflags & flags) != flags)
|
| 85 |
in->obj = getscene(o->oargs.sarg[0], flags);
|
| 86 |
return(in);
|
| 87 |
}
|