| 5 |
|
* Routines for reading instances and converting to OpenGL. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
< |
/* ==================================================================== |
| 9 |
< |
* The Radiance Software License, Version 1.0 |
| 10 |
< |
* |
| 11 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 12 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 13 |
< |
* |
| 14 |
< |
* Redistribution and use in source and binary forms, with or without |
| 15 |
< |
* modification, are permitted provided that the following conditions |
| 16 |
< |
* are met: |
| 17 |
< |
* |
| 18 |
< |
* 1. Redistributions of source code must retain the above copyright |
| 19 |
< |
* notice, this list of conditions and the following disclaimer. |
| 20 |
< |
* |
| 21 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
| 22 |
< |
* notice, this list of conditions and the following disclaimer in |
| 23 |
< |
* the documentation and/or other materials provided with the |
| 24 |
< |
* distribution. |
| 25 |
< |
* |
| 26 |
< |
* 3. The end-user documentation included with the redistribution, |
| 27 |
< |
* if any, must include the following acknowledgment: |
| 28 |
< |
* "This product includes Radiance software |
| 29 |
< |
* (http://radsite.lbl.gov/) |
| 30 |
< |
* developed by the Lawrence Berkeley National Laboratory |
| 31 |
< |
* (http://www.lbl.gov/)." |
| 32 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
| 33 |
< |
* if and wherever such third-party acknowledgments normally appear. |
| 34 |
< |
* |
| 35 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 36 |
< |
* and "The Regents of the University of California" must |
| 37 |
< |
* not be used to endorse or promote products derived from this |
| 38 |
< |
* software without prior written permission. For written |
| 39 |
< |
* permission, please contact [email protected]. |
| 40 |
< |
* |
| 41 |
< |
* 5. Products derived from this software may not be called "Radiance", |
| 42 |
< |
* nor may "Radiance" appear in their name, without prior written |
| 43 |
< |
* permission of Lawrence Berkeley National Laboratory. |
| 44 |
< |
* |
| 45 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 46 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 47 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 48 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 49 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 50 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 51 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 52 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 53 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 54 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 55 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 56 |
< |
* SUCH DAMAGE. |
| 57 |
< |
* ==================================================================== |
| 58 |
< |
* |
| 59 |
< |
* This software consists of voluntary contributions made by many |
| 60 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 61 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
| 62 |
< |
* <http://www.lbl.gov/>. |
| 63 |
< |
*/ |
| 8 |
> |
#include "copyright.h" |
| 9 |
|
|
| 10 |
+ |
#include <stdio.h> |
| 11 |
+ |
#include <string.h> |
| 12 |
+ |
#include <time.h> |
| 13 |
+ |
|
| 14 |
+ |
#include "platform.h" |
| 15 |
+ |
#include "resolu.h" |
| 16 |
|
#include "radogl.h" |
| 17 |
|
#include "octree.h" |
| 18 |
|
|
| 25 |
|
char octfile[256]; /* octree file path */ |
| 26 |
|
} OCTINST; /* octree to instantiate */ |
| 27 |
|
|
| 28 |
< |
static double ogetflt(); |
| 29 |
< |
static long ogetint(); |
| 30 |
< |
static char *ogetstr(); |
| 31 |
< |
static int loadobj(); |
| 32 |
< |
static void skiptree(); |
| 33 |
< |
static void octerror(); |
| 34 |
< |
static OCTINST *getoct(); |
| 28 |
> |
static double ogetflt(void); |
| 29 |
> |
static long ogetint(int); |
| 30 |
> |
static char *ogetstr(char *); |
| 31 |
> |
static int loadobj(void); |
| 32 |
> |
static void skiptree(void); |
| 33 |
> |
static void octerror(int etyp, char *msg); |
| 34 |
> |
static OCTINST *getoct(char *); |
| 35 |
|
|
| 36 |
|
static char *infn; /* input file name */ |
| 37 |
|
static FILE *infp; /* input file stream */ |
| 38 |
|
static int objsize; /* size of stored OBJECT's */ |
| 39 |
|
static short otypmap[NUMOTYPE+8]; /* object type map */ |
| 40 |
|
|
| 41 |
< |
static unsigned long imhash(mod) char *mod; {return((unsigned long)mod);} |
| 41 |
> |
static unsigned long imhash(const char *mod) {return((unsigned long)mod);} |
| 42 |
|
static LUTAB imtab = {imhash,NULL,NULL,NULL,0,NULL,0}; |
| 43 |
|
|
| 44 |
|
static LUTAB ottab = LU_SINIT(free,free); |
| 60 |
|
o->oargs.nsargs-1) |
| 61 |
|
objerror(o, USER, "bad transform"); |
| 62 |
|
glPushAttrib(GL_TRANSFORM_BIT); |
| 63 |
< |
if (xfs.sca < 1.-FTINY | xfs.sca > 1.+FTINY) |
| 63 |
> |
if ((xfs.sca < 1.-FTINY) | (xfs.sca > 1.+FTINY)) |
| 64 |
|
glEnable(GL_NORMALIZE); |
| 65 |
|
glMatrixMode(GL_MODELVIEW); |
| 66 |
|
glPushMatrix(); |
| 83 |
|
glPopAttrib(); |
| 84 |
|
} |
| 85 |
|
rgl_checkerr("creating instance"); |
| 86 |
+ |
return(0); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
static int |
| 91 |
< |
buildoctlist(lp) /* build octree list */ |
| 92 |
< |
LUENT *lp; |
| 91 |
> |
buildoctlist(lp, p) /* build octree list */ |
| 92 |
> |
const LUENT *lp; |
| 93 |
> |
void *p; |
| 94 |
|
{ |
| 95 |
|
int old_dolights = dolights, old_domats = domats; |
| 96 |
|
register OCTINST *op = (OCTINST *)lp->data; |
| 117 |
|
while (ottab.tsiz) { |
| 118 |
|
if (!levelsleft--) |
| 119 |
|
error(USER, "too many octree levels -- instance loop?"); |
| 120 |
< |
copystruct(&looptab, &ottab); |
| 120 |
> |
looptab = ottab; |
| 121 |
|
ottab.tsiz = 0; |
| 122 |
< |
nocts += lu_doall(&looptab, buildoctlist); |
| 122 |
> |
nocts += lu_doall(&looptab, buildoctlist, NULL); |
| 123 |
|
lu_done(&looptab); |
| 124 |
|
} |
| 125 |
|
return(nocts); |
| 130 |
|
getoct(name) /* get/assign octree list id */ |
| 131 |
|
char *name; |
| 132 |
|
{ |
| 180 |
– |
extern char *getpath(), *getlibpath(); |
| 133 |
|
char *path; |
| 134 |
|
register LUENT *lp; |
| 135 |
|
register OCTINST *op; |
| 143 |
|
strcpy(lp->key, name); |
| 144 |
|
} |
| 145 |
|
if ((op = (OCTINST *)lp->data) == NULL) { |
| 146 |
< |
path = getpath(name, getlibpath(), R_OK); |
| 146 |
> |
path = getpath(name, getrlibpath(), R_OK); |
| 147 |
|
if (path == NULL) { |
| 148 |
|
sprintf(errmsg, "cannot find octree \"%s\"", name); |
| 149 |
< |
error(USER, errmsg); |
| 149 |
> |
error(SYSTEM, errmsg); |
| 150 |
|
} |
| 151 |
|
op = (OCTINST *)(lp->data = (char *)malloc(sizeof(OCTINST))); |
| 152 |
|
strcpy(op->octfile, path); |
| 157 |
|
return(op); |
| 158 |
|
memerr: |
| 159 |
|
error(SYSTEM, "out of memory in getoct"); |
| 160 |
+ |
return NULL; /* pro forma return */ |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 176 |
|
sprintf(errmsg, "cannot open octree file \"%s\"", fname); |
| 177 |
|
error(SYSTEM, errmsg); |
| 178 |
|
} |
| 179 |
< |
#ifdef MSDOS |
| 227 |
< |
setmode(fileno(infp), O_BINARY); |
| 228 |
< |
#endif |
| 179 |
> |
SET_FILE_BINARY(infp); |
| 180 |
|
/* get header */ |
| 181 |
|
if (checkheader(infp, OCTFMT, NULL) < 0) |
| 182 |
|
octerror(USER, "not an octree"); |
| 183 |
|
/* check format */ |
| 184 |
|
if ((objsize = ogetint(2)-OCTMAGIC) <= 0 || |
| 185 |
|
objsize > MAXOBJSIZ || objsize > sizeof(long)) |
| 186 |
< |
octerror("incompatible octree format"); |
| 186 |
> |
octerror(USER, "incompatible octree format"); |
| 187 |
|
if (cent != NULL) { /* get boundaries (compute center) */ |
| 188 |
|
for (i = 0; i < 3; i++) |
| 189 |
|
cent[i] = atof(ogetstr(sbuf)); |
| 213 |
|
|
| 214 |
|
infn = fname; |
| 215 |
|
infp = fopen(fname, "r"); /* assume already checked */ |
| 216 |
< |
#ifdef MSDOS |
| 266 |
< |
setmode(fileno(infp), O_BINARY); |
| 267 |
< |
#endif |
| 216 |
> |
SET_FILE_BINARY(infp); |
| 217 |
|
/* skip header */ |
| 218 |
|
getheader(infp, NULL, NULL); |
| 219 |
|
/* get format */ |
| 340 |
|
/* get name id */ |
| 341 |
|
ob.oname = ogetstr(idbuf); |
| 342 |
|
/* get string arguments */ |
| 343 |
< |
if (ob.oargs.nsargs = ogetint(2)) { |
| 343 |
> |
if ((ob.oargs.nsargs = ogetint(2))) { |
| 344 |
|
ob.oargs.sarg = (char **)malloc |
| 345 |
|
(ob.oargs.nsargs*sizeof(char *)); |
| 346 |
|
if (ob.oargs.sarg == NULL) |
| 362 |
|
ob.oargs.iarg = NULL; |
| 363 |
|
#endif |
| 364 |
|
/* get real arguments */ |
| 365 |
< |
if (ob.oargs.nfargs = ogetint(2)) { |
| 366 |
< |
ob.oargs.farg = (FLOAT *)malloc |
| 367 |
< |
(ob.oargs.nfargs*sizeof(FLOAT)); |
| 365 |
> |
if ((ob.oargs.nfargs = ogetint(2))) { |
| 366 |
> |
ob.oargs.farg = (RREAL *)malloc |
| 367 |
> |
(ob.oargs.nfargs*sizeof(RREAL)); |
| 368 |
|
if (ob.oargs.farg == NULL) |
| 369 |
|
goto memerr; |
| 370 |
|
for (i = 0; i < ob.oargs.nfargs; i++) |
| 375 |
|
(*ofun[ob.otype].funp)(&ob); |
| 376 |
|
/* record material if modifier */ |
| 377 |
|
if (ismodifier(ob.otype)) { |
| 378 |
< |
if ((lep = lu_find(&imtab, (char *)nobjects)) == NULL) |
| 378 |
> |
if ((lep = lu_find(&imtab, (char *)(size_t)nobjects)) == NULL) |
| 379 |
|
goto memerr; |
| 380 |
< |
lep->key = (char *)nobjects; |
| 380 |
> |
lep->key = (char *)(size_t)nobjects; |
| 381 |
|
lep->data = (char *)getmatp(ob.oname); |
| 382 |
|
} |
| 383 |
|
freefargs(&ob.oargs); /* free arguments */ |
| 384 |
|
return(nobjects++); /* return object id */ |
| 385 |
|
memerr: |
| 386 |
|
error(SYSTEM, "out of memory in loadobj"); |
| 387 |
+ |
return OVOID; /* pro forma return */ |
| 388 |
|
} |
| 389 |
|
|
| 390 |
|
|