| 1 |
greg |
1.6 |
/* Copyright (c) 1990 Regents of the University of California */
|
| 2 |
greg |
1.1 |
|
| 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 |
greg |
2.3 |
#define IO_ILLEGAL (IO_FILES|IO_INFO)
|
| 20 |
|
|
|
| 21 |
greg |
1.1 |
static SCENE *slist = NULL; /* list of loaded octrees */
|
| 22 |
|
|
|
| 23 |
|
|
|
| 24 |
|
|
SCENE *
|
| 25 |
|
|
getscene(sname, flags) /* load octree sname */
|
| 26 |
|
|
char *sname;
|
| 27 |
|
|
int flags;
|
| 28 |
|
|
{
|
| 29 |
greg |
2.4 |
extern char *getlibpath();
|
| 30 |
greg |
1.1 |
char *pathname;
|
| 31 |
|
|
register SCENE *sc;
|
| 32 |
|
|
|
| 33 |
greg |
2.3 |
flags &= ~IO_ILLEGAL; /* not allowed */
|
| 34 |
greg |
1.1 |
for (sc = slist; sc != NULL; sc = sc->next)
|
| 35 |
|
|
if (!strcmp(sname, sc->name)) {
|
| 36 |
|
|
if ((sc->ldflags & flags) == flags)
|
| 37 |
|
|
return(sc); /* loaded */
|
| 38 |
|
|
break; /* load the rest */
|
| 39 |
|
|
}
|
| 40 |
|
|
if (sc == NULL) {
|
| 41 |
|
|
sc = (SCENE *)malloc(sizeof(SCENE));
|
| 42 |
|
|
if (sc == NULL)
|
| 43 |
|
|
error(SYSTEM, "out of memory in getscene");
|
| 44 |
|
|
sc->name = savestr(sname);
|
| 45 |
|
|
sc->ldflags = 0;
|
| 46 |
greg |
2.2 |
sc->scube.cutree = EMPTY;
|
| 47 |
|
|
sc->scube.cuorg[0] = sc->scube.cuorg[1] =
|
| 48 |
|
|
sc->scube.cuorg[2] = 0.;
|
| 49 |
|
|
sc->scube.cusize = 0.;
|
| 50 |
|
|
sc->firstobj = sc->nobjs = 0;
|
| 51 |
greg |
1.1 |
sc->next = slist;
|
| 52 |
|
|
slist = sc;
|
| 53 |
|
|
}
|
| 54 |
greg |
2.4 |
if ((pathname = getpath(sname, getlibpath(), R_OK)) == NULL) {
|
| 55 |
greg |
1.1 |
sprintf(errmsg, "cannot find octree file \"%s\"", sname);
|
| 56 |
|
|
error(USER, errmsg);
|
| 57 |
|
|
}
|
| 58 |
greg |
2.3 |
flags &= ~sc->ldflags; /* skip what's already loaded */
|
| 59 |
|
|
if (flags & IO_SCENE)
|
| 60 |
greg |
2.2 |
sc->firstobj = nobjects;
|
| 61 |
greg |
2.3 |
readoct(pathname, flags, &sc->scube, NULL);
|
| 62 |
|
|
if (flags & IO_SCENE)
|
| 63 |
greg |
2.2 |
sc->nobjs = nobjects - sc->firstobj;
|
| 64 |
greg |
1.1 |
sc->ldflags |= flags;
|
| 65 |
|
|
return(sc);
|
| 66 |
|
|
}
|
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
|
|
INSTANCE *
|
| 70 |
|
|
getinstance(o, flags) /* get instance structure */
|
| 71 |
|
|
register OBJREC *o;
|
| 72 |
|
|
int flags;
|
| 73 |
|
|
{
|
| 74 |
|
|
register INSTANCE *in;
|
| 75 |
|
|
|
| 76 |
greg |
2.3 |
flags &= ~IO_ILLEGAL; /* not allowed */
|
| 77 |
greg |
1.1 |
if ((in = (INSTANCE *)o->os) == NULL) {
|
| 78 |
|
|
if ((in = (INSTANCE *)malloc(sizeof(INSTANCE))) == NULL)
|
| 79 |
|
|
error(SYSTEM, "out of memory in getinstance");
|
| 80 |
|
|
if (o->oargs.nsargs < 1)
|
| 81 |
|
|
objerror(o, USER, "bad # of arguments");
|
| 82 |
greg |
1.6 |
if (fullxf(&in->x, o->oargs.nsargs-1,
|
| 83 |
greg |
1.1 |
o->oargs.sarg+1) != o->oargs.nsargs-1)
|
| 84 |
|
|
objerror(o, USER, "bad transform");
|
| 85 |
greg |
1.6 |
if (in->x.f.sca < 0.0)
|
| 86 |
|
|
in->x.f.sca = -in->x.f.sca;
|
| 87 |
|
|
if (in->x.b.sca < 0.0)
|
| 88 |
|
|
in->x.b.sca = -in->x.b.sca;
|
| 89 |
greg |
1.1 |
in->obj = NULL;
|
| 90 |
greg |
1.2 |
o->os = (char *)in;
|
| 91 |
greg |
1.1 |
}
|
| 92 |
|
|
if (in->obj == NULL || (in->obj->ldflags & flags) != flags)
|
| 93 |
|
|
in->obj = getscene(o->oargs.sarg[0], flags);
|
| 94 |
|
|
return(in);
|
| 95 |
|
|
}
|
| 96 |
greg |
1.7 |
|
| 97 |
|
|
|
| 98 |
|
|
freeinstance(o) /* free memory associated with instance */
|
| 99 |
|
|
OBJREC *o;
|
| 100 |
|
|
{
|
| 101 |
greg |
1.8 |
if (o->os == NULL)
|
| 102 |
|
|
return;
|
| 103 |
greg |
1.7 |
free(o->os);
|
| 104 |
greg |
1.8 |
o->os = NULL;
|
| 105 |
greg |
1.7 |
}
|