ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/instance.c
Revision: 1.4
Committed: Thu Oct 5 07:54:06 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +0 -4 lines
Log Message:
Preinitialization of matrix for xf() and invxf() no longer necessary.

File Contents

# Content
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, R_OK)) == 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 if (xf(in->f.xfm, &in->f.sca, o->oargs.nsargs-1,
70 o->oargs.sarg+1) != o->oargs.nsargs-1)
71 objerror(o, USER, "bad transform");
72 if (in->f.sca < 0.0)
73 in->f.sca = -in->f.sca;
74 invxf(in->b.xfm, &in->b.sca,o->oargs.nsargs-1,o->oargs.sarg+1);
75 if (in->b.sca < 0.0)
76 in->b.sca = -in->b.sca;
77 in->obj = NULL;
78 o->os = (char *)in;
79 }
80 if (in->obj == NULL || (in->obj->ldflags & flags) != flags)
81 in->obj = getscene(o->oargs.sarg[0], flags);
82 return(in);
83 }