1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines for reading instances and converting to OpenGL. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "radogl.h" |
11 |
|
#include "octree.h" |
12 |
+ |
#include "platform.h" |
13 |
|
|
14 |
+ |
#define MAXLEVEL 16 /* maximum instance hierarchy level */ |
15 |
+ |
|
16 |
|
typedef struct { |
17 |
|
int listid; /* our list id */ |
18 |
|
short localmatl; /* uses local material only */ |
20 |
|
char octfile[256]; /* octree file path */ |
21 |
|
} OCTINST; /* octree to instantiate */ |
22 |
|
|
21 |
– |
OBJECT nobjects; /* number of objects loaded so far */ |
22 |
– |
|
23 |
– |
extern int free(); |
24 |
– |
|
23 |
|
static double ogetflt(); |
24 |
|
static long ogetint(); |
25 |
|
static char *ogetstr(); |
26 |
< |
static int loadobj(), octerror(), skiptree(); |
26 |
> |
static int loadobj(); |
27 |
> |
static void skiptree(); |
28 |
> |
static void octerror(); |
29 |
|
static OCTINST *getoct(); |
30 |
|
|
31 |
|
static char *infn; /* input file name */ |
33 |
|
static int objsize; /* size of stored OBJECT's */ |
34 |
|
static short otypmap[NUMOTYPE+8]; /* object type map */ |
35 |
|
|
36 |
< |
static long imhash(mod) char *mod; {return((long)mod);} |
36 |
> |
static unsigned long imhash(mod) char *mod; {return((unsigned long)mod);} |
37 |
|
static LUTAB imtab = {imhash,NULL,NULL,NULL,0,NULL,0}; |
38 |
|
|
39 |
|
static LUTAB ottab = LU_SINIT(free,free); |
40 |
|
|
41 |
|
|
42 |
+ |
int |
43 |
|
o_instance(o) /* convert instance to list call */ |
44 |
|
register OBJREC *o; |
45 |
|
{ |
68 |
|
} |
69 |
|
ot = getoct(o->oargs.sarg[0]); /* get octree reference */ |
70 |
|
if (ot->localmatl &= o->os != NULL) /* set material */ |
71 |
< |
setmaterial(o->os, ot->cent, 0); |
71 |
> |
setmaterial((MATREC *)o->os, ot->cent, 0); |
72 |
|
/* call the assigned list */ |
73 |
|
glCallList(ot->listid); |
74 |
|
|
75 |
|
if (o->oargs.nsargs > 1) { /* end transform */ |
76 |
+ |
glMatrixMode(GL_MODELVIEW); |
77 |
|
glPopMatrix(); |
78 |
|
glPopAttrib(); |
79 |
|
} |
80 |
|
rgl_checkerr("creating instance"); |
81 |
+ |
return(0); |
82 |
|
} |
83 |
|
|
84 |
|
|
104 |
|
int |
105 |
|
loadoctrees() /* load octrees we've saved up */ |
106 |
|
{ |
107 |
+ |
int levelsleft = MAXLEVEL; |
108 |
|
int nocts = 0; |
109 |
|
LUTAB looptab; |
110 |
|
/* loop through new octree references */ |
111 |
|
while (ottab.tsiz) { |
112 |
+ |
if (!levelsleft--) |
113 |
+ |
error(USER, "too many octree levels -- instance loop?"); |
114 |
|
copystruct(&looptab, &ottab); |
115 |
|
ottab.tsiz = 0; |
116 |
|
nocts += lu_doall(&looptab, buildoctlist); |
124 |
|
getoct(name) /* get/assign octree list id */ |
125 |
|
char *name; |
126 |
|
{ |
121 |
– |
extern char *getpath(), *getlibpath(); |
127 |
|
char *path; |
128 |
|
register LUENT *lp; |
129 |
|
register OCTINST *op; |
137 |
|
strcpy(lp->key, name); |
138 |
|
} |
139 |
|
if ((op = (OCTINST *)lp->data) == NULL) { |
140 |
< |
path = getpath(name, getlibpath(), R_OK); |
140 |
> |
path = getpath(name, getrlibpath(), R_OK); |
141 |
|
if (path == NULL) { |
142 |
|
sprintf(errmsg, "cannot find octree \"%s\"", name); |
143 |
|
error(USER, errmsg); |
169 |
|
sprintf(errmsg, "cannot open octree file \"%s\"", fname); |
170 |
|
error(SYSTEM, errmsg); |
171 |
|
} |
172 |
< |
#ifdef MSDOS |
168 |
< |
setmode(fileno(infp), O_BINARY); |
169 |
< |
#endif |
172 |
> |
SET_FILE_BINARY(infp); |
173 |
|
/* get header */ |
174 |
|
if (checkheader(infp, OCTFMT, NULL) < 0) |
175 |
|
octerror(USER, "not an octree"); |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
+ |
int |
198 |
|
loadoct(fname) /* read in objects from octree */ |
199 |
|
char *fname; |
200 |
|
{ |
206 |
|
|
207 |
|
infn = fname; |
208 |
|
infp = fopen(fname, "r"); /* assume already checked */ |
209 |
< |
#ifdef MSDOS |
206 |
< |
setmode(fileno(infp), O_BINARY); |
207 |
< |
#endif |
209 |
> |
SET_FILE_BINARY(infp); |
210 |
|
/* skip header */ |
211 |
|
getheader(infp, NULL, NULL); |
212 |
|
/* get format */ |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
< |
static |
285 |
> |
static void |
286 |
|
skiptree() /* skip octree on input */ |
287 |
|
{ |
288 |
|
register int i; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
< |
static |
310 |
> |
static int |
311 |
|
loadobj() /* get next object */ |
312 |
|
{ |
313 |
|
static OBJREC ob; |
356 |
|
#endif |
357 |
|
/* get real arguments */ |
358 |
|
if (ob.oargs.nfargs = ogetint(2)) { |
359 |
< |
ob.oargs.farg = (FLOAT *)malloc |
360 |
< |
(ob.oargs.nfargs*sizeof(FLOAT)); |
359 |
> |
ob.oargs.farg = (RREAL *)malloc |
360 |
> |
(ob.oargs.nfargs*sizeof(RREAL)); |
361 |
|
if (ob.oargs.farg == NULL) |
362 |
|
goto memerr; |
363 |
|
for (i = 0; i < ob.oargs.nfargs; i++) |
380 |
|
} |
381 |
|
|
382 |
|
|
383 |
< |
static |
383 |
> |
static void |
384 |
|
octerror(etyp, msg) /* octree error */ |
385 |
|
int etyp; |
386 |
|
char *msg; |