| 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 loading and displaying Radiance objects in rholo with GLX. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include <string.h> |
| 9 |
+ |
|
| 10 |
|
#include "radogl.h" |
| 11 |
|
#include "tonemap.h" |
| 12 |
|
#include "rhdisp.h" |
| 13 |
|
#include "rhdriver.h" |
| 14 |
|
#include "rhdobj.h" |
| 15 |
+ |
#include "rtprocess.h" |
| 16 |
|
|
| 17 |
|
extern FILE *sstdout; /* user standard output */ |
| 18 |
|
|
| 53 |
|
struct dobject *next; /* next object in list */ |
| 54 |
|
char name[64]; /* object name */ |
| 55 |
|
FVECT center; /* orig. object center */ |
| 56 |
< |
FLOAT radius; /* orig. object radius */ |
| 56 |
> |
RREAL radius; /* orig. object radius */ |
| 57 |
|
int listid; /* GL display list identifier */ |
| 58 |
< |
int rtp[3]; /* associated rtrace process */ |
| 58 |
> |
int nlists; /* number of lists allocated */ |
| 59 |
> |
SUBPROC rtp; /* associated rtrace process */ |
| 60 |
|
DLIGHTS *ol; /* object lights */ |
| 61 |
|
FULLXF xfb; /* coordinate transform */ |
| 62 |
|
short drawcode; /* drawing code */ |
| 120 |
|
} |
| 121 |
|
dobjects = ohead.next; |
| 122 |
|
if (!foundlink) { |
| 123 |
< |
glDeleteLists(op->listid, 1); |
| 124 |
< |
close_process(op->rtp); |
| 123 |
> |
glDeleteLists(op->listid, op->nlists); |
| 124 |
> |
close_process(&(op->rtp)); |
| 125 |
|
} |
| 126 |
|
while (op->xfac) |
| 127 |
|
freestr(op->xfav[--op->xfac]); |
| 128 |
< |
free((char *)op); |
| 128 |
> |
free((void *)op); |
| 129 |
|
return(1); |
| 130 |
|
} |
| 131 |
|
|
| 300 |
|
/* avg. reflected brightness */ |
| 301 |
|
d = AVGREFL / (double)ncells; |
| 302 |
|
scalecolor(csum, d); |
| 303 |
< |
if (tmCvColors(&dlightsets->larb, TM_NOCHROM, csum, 1) != TM_E_OK) |
| 303 |
> |
if (tmCvColors(&dlightsets->larb, TM_NOCHROM, &csum, 1) != TM_E_OK) |
| 304 |
|
error(CONSISTENCY, "tone mapping problem in ssph_compute"); |
| 305 |
|
/* greedy light source clustering */ |
| 306 |
|
while (dlightsets->nl < MAXLIGHTS) { |
| 340 |
|
d = 1.0/ncells; |
| 341 |
|
scalecolor(dlightsets->lamb, d); |
| 342 |
|
done: /* clear sphere sample array */ |
| 343 |
< |
bzero((char *)ssamp, sizeof(ssamp)); |
| 343 |
> |
memset((void *)ssamp, '\0', sizeof(ssamp)); |
| 344 |
|
return(ncells); |
| 345 |
|
} |
| 346 |
|
|
| 407 |
|
quit(0); |
| 408 |
|
if (!ssph_compute()) { /* compute light sources from sphere */ |
| 409 |
|
dlightsets = dl->next; |
| 410 |
< |
free((char *)dl); |
| 410 |
> |
free((void *)dl); |
| 411 |
|
return(0); |
| 412 |
|
} |
| 413 |
|
op->ol = dl; |
| 417 |
|
} |
| 418 |
|
|
| 419 |
|
|
| 420 |
< |
static int |
| 420 |
> |
static |
| 421 |
|
cmderror(cn, err) /* report command error */ |
| 422 |
|
int cn; |
| 423 |
|
char *err; |
| 424 |
|
{ |
| 425 |
|
sprintf(errmsg, "%s: %s", rhdcmd[cn], err); |
| 426 |
|
error(COMMAND, errmsg); |
| 426 |
– |
return(cn); |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
|
| 433 |
|
register char *args; |
| 434 |
|
{ |
| 435 |
|
int somechange = 0; |
| 436 |
– |
VIEW sameview; |
| 436 |
|
int cn, na, doxfm; |
| 437 |
|
register int nn; |
| 438 |
|
char *alist[MAXAC+1], *nm; |
| 460 |
|
dobj_load(alist[0], alist[0]); |
| 461 |
|
else if (na == 2) |
| 462 |
|
dobj_load(alist[0], alist[1]); |
| 463 |
< |
else |
| 464 |
< |
return(cmderror(cn, "need octree [name]")); |
| 463 |
> |
else { |
| 464 |
> |
cmderror(cn, "need octree [name]"); |
| 465 |
> |
return(0); |
| 466 |
> |
} |
| 467 |
|
break; |
| 468 |
|
case DO_UNLOAD: /* clear an object */ |
| 469 |
|
if (na > 1) goto toomany; |
| 479 |
|
} else { |
| 480 |
|
nm = curname; nn = 0; |
| 481 |
|
} |
| 482 |
< |
if (cn == DO_MOVE && nn >= na) |
| 483 |
< |
return(cmderror(cn, "missing transform")); |
| 482 |
> |
if (cn == DO_MOVE && nn >= na) { |
| 483 |
> |
cmderror(cn, "missing transform"); |
| 484 |
> |
return(0); |
| 485 |
> |
} |
| 486 |
|
somechange += dobj_xform(nm, cn==DO_MOVE, na-nn, alist+nn); |
| 487 |
|
break; |
| 488 |
|
case DO_UNMOVE: /* undo last transform */ |
| 500 |
|
break; |
| 501 |
|
switch (nn) { |
| 502 |
|
case 0: |
| 503 |
< |
return(cmderror(cn, "need new object name")); |
| 503 |
> |
cmderror(cn, "need new object name"); |
| 504 |
> |
return(0); |
| 505 |
|
case 1: |
| 506 |
|
nm = curname; |
| 507 |
|
break; |
| 529 |
|
default: |
| 530 |
|
error(CONSISTENCY, "bad command id in dobj_command"); |
| 531 |
|
} |
| 532 |
< |
if (somechange) { |
| 529 |
< |
copystruct(&sameview, &odev.v); /* make 'em think new view */ |
| 530 |
< |
dev_view(&sameview); /* redraw */ |
| 531 |
< |
} |
| 532 |
< |
return(cn); |
| 532 |
> |
return(somechange); |
| 533 |
|
toomany: |
| 534 |
|
return(cmderror(cn, "too many arguments")); |
| 535 |
|
} |
| 538 |
|
dobj_load(oct, nam) /* create/load an octree object */ |
| 539 |
|
char *oct, *nam; |
| 540 |
|
{ |
| 541 |
– |
extern char *getlibpath(), *getpath(); |
| 541 |
|
char *fpp, fpath[128]; |
| 542 |
|
register DOBJECT *op; |
| 543 |
|
/* check arguments */ |
| 558 |
|
return(0); |
| 559 |
|
} |
| 560 |
|
/* get octree path */ |
| 561 |
< |
if ((fpp = getpath(oct, getlibpath(), R_OK)) == NULL) { |
| 561 |
> |
if ((fpp = getpath(oct, getrlibpath(), R_OK)) == NULL) { |
| 562 |
|
sprintf(errmsg, "cannot find octree \"%s\"", oct); |
| 563 |
|
error(COMMAND, errmsg); |
| 564 |
|
return(0); |
| 577 |
|
/* load octree into display list */ |
| 578 |
|
dolights = 0; |
| 579 |
|
domats = 1; |
| 580 |
< |
op->listid = rgl_octlist(fpath, op->center, &op->radius); |
| 580 |
> |
op->listid = rgl_octlist(fpath, op->center, &op->radius, &op->nlists); |
| 581 |
|
/* start rtrace */ |
| 582 |
|
rtargv[RTARGC-1] = fpath; |
| 583 |
|
rtargv[RTARGC] = NULL; |
| 584 |
< |
open_process(op->rtp, rtargv); |
| 584 |
> |
open_process(&(op->rtp), rtargv); |
| 585 |
|
/* insert into main list */ |
| 586 |
|
op->next = dobjects; |
| 587 |
|
curobj = dobjects = op; |
| 614 |
|
savedxf(curobj = NULL); |
| 615 |
|
while ((lp = dlightsets) != NULL) { |
| 616 |
|
dlightsets = lp->next; |
| 617 |
< |
free((char *)lp); |
| 617 |
> |
free((void *)lp); |
| 618 |
|
} |
| 619 |
|
return(1); |
| 620 |
|
} |
| 733 |
|
return(0); |
| 734 |
|
} |
| 735 |
|
/* hold last transform */ |
| 736 |
< |
bcopy((char *)lastxfav, (char *)txfav, |
| 736 |
> |
memcpy((void *)txfav, (void *)lastxfav, |
| 737 |
|
(txfac=lastxfac)*sizeof(char *)); |
| 738 |
|
/* save this transform */ |
| 739 |
< |
bcopy((char *)curobj->xfav, (char *)lastxfav, |
| 739 |
> |
memcpy((void *)lastxfav, (void *)curobj->xfav, |
| 740 |
|
(lastxfac=curobj->xfac)*sizeof(char *)); |
| 741 |
|
/* copy back last transform */ |
| 742 |
< |
bcopy((char *)txfav, (char *)curobj->xfav, |
| 742 |
> |
memcpy((void *)curobj->xfav, (void *)txfav, |
| 743 |
|
(curobj->xfac=txfac)*sizeof(char *)); |
| 744 |
|
/* set matrices */ |
| 745 |
|
fullxf(&curobj->xfb, curobj->xfac, curobj->xfav); |
| 862 |
|
VCOPY(darr, rorg); VCOPY(darr+3, rdir); |
| 863 |
|
} |
| 864 |
|
/* trace it */ |
| 865 |
< |
if (process(op->rtp, darr, darr, sizeof(double), |
| 865 |
> |
if (process(&(op->rtp), (char *)darr, (char *)darr, sizeof(double), |
| 866 |
|
6*sizeof(double)) != sizeof(double)) |
| 867 |
|
error(SYSTEM, "rtrace communication error"); |
| 868 |
|
/* return distance */ |