| 1 |
greg |
1.1 |
/* Copyright (c) 1987 Regents of the University of California */ |
| 2 |
|
|
|
| 3 |
|
|
#ifndef lint |
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
|
#endif |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* rv2.c - command routines used in tracing a view. |
| 9 |
|
|
* |
| 10 |
|
|
* 3/24/87 |
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
|
|
#include "ray.h" |
| 14 |
|
|
|
| 15 |
|
|
#include "octree.h" |
| 16 |
|
|
|
| 17 |
|
|
#include "otypes.h" |
| 18 |
|
|
|
| 19 |
|
|
#include "rpaint.h" |
| 20 |
|
|
|
| 21 |
|
|
#include <ctype.h> |
| 22 |
|
|
|
| 23 |
|
|
#define CTRL(c) ('c'-'@') |
| 24 |
|
|
|
| 25 |
|
|
extern char *progname; |
| 26 |
|
|
|
| 27 |
|
|
|
| 28 |
|
|
getframe(s) /* get a new frame */ |
| 29 |
|
|
char *s; |
| 30 |
|
|
{ |
| 31 |
greg |
1.12 |
if (getrect(s, &pframe) < 0) |
| 32 |
greg |
1.1 |
return; |
| 33 |
|
|
pdepth = 0; |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
|
| 37 |
greg |
1.12 |
getrepaint(s) /* get area and repaint */ |
| 38 |
|
|
char *s; |
| 39 |
|
|
{ |
| 40 |
|
|
RECT box; |
| 41 |
|
|
|
| 42 |
|
|
if (getrect(s, &box) < 0) |
| 43 |
|
|
return; |
| 44 |
|
|
paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, &box); |
| 45 |
|
|
} |
| 46 |
|
|
|
| 47 |
|
|
|
| 48 |
greg |
1.1 |
getview(s) /* get/show view parameters */ |
| 49 |
|
|
char *s; |
| 50 |
|
|
{ |
| 51 |
|
|
FILE *fp; |
| 52 |
|
|
char buf[128]; |
| 53 |
greg |
1.10 |
char *fname; |
| 54 |
greg |
1.3 |
int change = 0; |
| 55 |
greg |
1.1 |
VIEW nv; |
| 56 |
|
|
|
| 57 |
|
|
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
| 58 |
greg |
1.10 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
| 59 |
greg |
1.1 |
(fp = fopen(fname, "a")) == NULL) { |
| 60 |
|
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
| 61 |
|
|
error(COMMAND, errmsg); |
| 62 |
|
|
return; |
| 63 |
|
|
} |
| 64 |
greg |
1.2 |
fputs(progname, fp); |
| 65 |
greg |
1.1 |
fprintview(&ourview, fp); |
| 66 |
|
|
fputs("\n", fp); |
| 67 |
|
|
fclose(fp); |
| 68 |
|
|
return; |
| 69 |
|
|
} |
| 70 |
|
|
sprintf(buf, "view type (%c): ", ourview.type); |
| 71 |
|
|
(*dev->comout)(buf); |
| 72 |
|
|
(*dev->comin)(buf); |
| 73 |
|
|
if (buf[0] == CTRL(C)) return; |
| 74 |
greg |
1.3 |
if (buf[0] && buf[0] != ourview.type) { |
| 75 |
greg |
1.1 |
nv.type = buf[0]; |
| 76 |
greg |
1.3 |
change++; |
| 77 |
|
|
} else |
| 78 |
greg |
1.1 |
nv.type = ourview.type; |
| 79 |
|
|
sprintf(buf, "view point (%.6g %.6g %.6g): ", |
| 80 |
|
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
| 81 |
|
|
(*dev->comout)(buf); |
| 82 |
|
|
(*dev->comin)(buf); |
| 83 |
|
|
if (buf[0] == CTRL(C)) return; |
| 84 |
greg |
1.3 |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) |
| 85 |
|
|
change++; |
| 86 |
|
|
else |
| 87 |
greg |
1.1 |
VCOPY(nv.vp, ourview.vp); |
| 88 |
|
|
sprintf(buf, "view direction (%.6g %.6g %.6g): ", |
| 89 |
|
|
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
| 90 |
|
|
(*dev->comout)(buf); |
| 91 |
|
|
(*dev->comin)(buf); |
| 92 |
|
|
if (buf[0] == CTRL(C)) return; |
| 93 |
greg |
1.3 |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) |
| 94 |
|
|
change++; |
| 95 |
|
|
else |
| 96 |
greg |
1.1 |
VCOPY(nv.vdir, ourview.vdir); |
| 97 |
|
|
sprintf(buf, "view up (%.6g %.6g %.6g): ", |
| 98 |
|
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
| 99 |
|
|
(*dev->comout)(buf); |
| 100 |
|
|
(*dev->comin)(buf); |
| 101 |
|
|
if (buf[0] == CTRL(C)) return; |
| 102 |
greg |
1.3 |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) |
| 103 |
|
|
change++; |
| 104 |
|
|
else |
| 105 |
greg |
1.1 |
VCOPY(nv.vup, ourview.vup); |
| 106 |
|
|
sprintf(buf, "view horiz and vert size (%.6g %.6g): ", |
| 107 |
|
|
ourview.horiz, ourview.vert); |
| 108 |
|
|
(*dev->comout)(buf); |
| 109 |
|
|
(*dev->comin)(buf); |
| 110 |
|
|
if (buf[0] == CTRL(C)) return; |
| 111 |
greg |
1.3 |
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
| 112 |
|
|
change++; |
| 113 |
|
|
else { |
| 114 |
greg |
1.1 |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
| 115 |
|
|
} |
| 116 |
|
|
sprintf(buf, "x and y resolution (%d %d): ", |
| 117 |
|
|
ourview.hresolu, ourview.vresolu); |
| 118 |
|
|
(*dev->comout)(buf); |
| 119 |
|
|
(*dev->comin)(buf); |
| 120 |
|
|
if (buf[0] == CTRL(C)) return; |
| 121 |
greg |
1.3 |
if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2) |
| 122 |
|
|
change++; |
| 123 |
|
|
else { |
| 124 |
greg |
1.1 |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 125 |
|
|
} |
| 126 |
greg |
1.3 |
if (change) |
| 127 |
|
|
newview(&nv); |
| 128 |
greg |
1.1 |
} |
| 129 |
|
|
|
| 130 |
|
|
|
| 131 |
|
|
lastview(s) /* return to a previous view */ |
| 132 |
|
|
char *s; |
| 133 |
|
|
{ |
| 134 |
|
|
char buf[128]; |
| 135 |
greg |
1.10 |
char *fname; |
| 136 |
greg |
1.1 |
int success; |
| 137 |
|
|
VIEW nv; |
| 138 |
|
|
|
| 139 |
|
|
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
| 140 |
|
|
bcopy(&stdview, &nv, sizeof(VIEW)); |
| 141 |
greg |
1.10 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
| 142 |
greg |
1.1 |
(success = viewfile(fname, &nv)) == -1) { |
| 143 |
|
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
| 144 |
|
|
error(COMMAND, errmsg); |
| 145 |
|
|
return; |
| 146 |
|
|
} |
| 147 |
|
|
if (!success) |
| 148 |
|
|
error(COMMAND, "wrong file format"); |
| 149 |
|
|
else |
| 150 |
|
|
newview(&nv); |
| 151 |
|
|
return; |
| 152 |
|
|
} |
| 153 |
|
|
if (oldview.hresolu == 0) { /* no old view! */ |
| 154 |
|
|
error(COMMAND, "no previous view"); |
| 155 |
|
|
return; |
| 156 |
|
|
} |
| 157 |
|
|
bcopy(&ourview, &nv, sizeof(VIEW)); |
| 158 |
|
|
bcopy(&oldview, &ourview, sizeof(VIEW)); |
| 159 |
|
|
bcopy(&nv, &oldview, sizeof(VIEW)); |
| 160 |
|
|
newimage(); |
| 161 |
|
|
} |
| 162 |
|
|
|
| 163 |
|
|
|
| 164 |
|
|
getaim(s) /* aim camera */ |
| 165 |
|
|
char *s; |
| 166 |
|
|
{ |
| 167 |
|
|
extern double tan(), atan(); |
| 168 |
|
|
double zfact; |
| 169 |
|
|
VIEW nv; |
| 170 |
|
|
|
| 171 |
|
|
if (getinterest(s, 1, nv.vdir, &zfact) < 0) |
| 172 |
|
|
return; |
| 173 |
|
|
VCOPY(nv.vp, ourview.vp); |
| 174 |
|
|
VCOPY(nv.vup, ourview.vup); |
| 175 |
|
|
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 176 |
|
|
if ((nv.type = ourview.type) == VT_PAR) { |
| 177 |
|
|
nv.horiz = ourview.horiz / zfact; |
| 178 |
|
|
nv.vert = ourview.vert / zfact; |
| 179 |
|
|
} else { |
| 180 |
|
|
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
| 181 |
|
|
(PI/180./2.); |
| 182 |
|
|
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
| 183 |
|
|
(PI/180./2.); |
| 184 |
|
|
} |
| 185 |
|
|
newview(&nv); |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
|
|
| 189 |
|
|
getmove(s) /* move camera */ |
| 190 |
|
|
char *s; |
| 191 |
|
|
{ |
| 192 |
|
|
FVECT vc; |
| 193 |
|
|
double mag; |
| 194 |
|
|
|
| 195 |
|
|
if (getinterest(s, 0, vc, &mag) < 0) |
| 196 |
|
|
return; |
| 197 |
greg |
1.4 |
moveview(0.0, 0.0, mag, vc); |
| 198 |
greg |
1.1 |
} |
| 199 |
|
|
|
| 200 |
|
|
|
| 201 |
|
|
getrotate(s) /* rotate camera */ |
| 202 |
|
|
char *s; |
| 203 |
|
|
{ |
| 204 |
greg |
1.4 |
extern double normalize(), tan(), atan(); |
| 205 |
greg |
1.1 |
VIEW nv; |
| 206 |
|
|
FVECT v1; |
| 207 |
greg |
1.4 |
double angle, elev, zfact; |
| 208 |
greg |
1.1 |
|
| 209 |
greg |
1.4 |
elev = 0.0; zfact = 1.0; |
| 210 |
|
|
if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) { |
| 211 |
greg |
1.1 |
error(COMMAND, "missing angle"); |
| 212 |
|
|
return; |
| 213 |
|
|
} |
| 214 |
|
|
VCOPY(nv.vp, ourview.vp); |
| 215 |
|
|
VCOPY(nv.vup, ourview.vup); |
| 216 |
|
|
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 217 |
|
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 218 |
|
|
if (elev != 0.0) { |
| 219 |
|
|
fcross(v1, nv.vdir, ourview.vup); |
| 220 |
|
|
normalize(v1); |
| 221 |
|
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 222 |
|
|
} |
| 223 |
greg |
1.4 |
if ((nv.type = ourview.type) == VT_PAR) { |
| 224 |
|
|
nv.horiz = ourview.horiz / zfact; |
| 225 |
|
|
nv.vert = ourview.vert / zfact; |
| 226 |
|
|
} else { |
| 227 |
|
|
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
| 228 |
|
|
(PI/180./2.); |
| 229 |
|
|
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
| 230 |
|
|
(PI/180./2.); |
| 231 |
|
|
} |
| 232 |
greg |
1.1 |
newview(&nv); |
| 233 |
|
|
} |
| 234 |
|
|
|
| 235 |
|
|
|
| 236 |
|
|
getpivot(s) /* pivot viewpoint */ |
| 237 |
|
|
register char *s; |
| 238 |
|
|
{ |
| 239 |
|
|
FVECT vc; |
| 240 |
greg |
1.4 |
double angle, elev, mag; |
| 241 |
greg |
1.1 |
|
| 242 |
greg |
1.4 |
elev = 0.0; |
| 243 |
|
|
if (sscanf(s, "%lf %lf", &angle, &elev) < 1) { |
| 244 |
greg |
1.1 |
error(COMMAND, "missing angle"); |
| 245 |
|
|
return; |
| 246 |
|
|
} |
| 247 |
greg |
1.4 |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
| 248 |
greg |
1.1 |
return; |
| 249 |
greg |
1.4 |
moveview(angle, elev, mag, vc); |
| 250 |
greg |
1.1 |
} |
| 251 |
|
|
|
| 252 |
|
|
|
| 253 |
|
|
getexposure(s) /* get new exposure */ |
| 254 |
|
|
char *s; |
| 255 |
|
|
{ |
| 256 |
|
|
double atof(), pow(), fabs(); |
| 257 |
|
|
char buf[128]; |
| 258 |
|
|
register char *cp; |
| 259 |
|
|
register PNODE *p; |
| 260 |
|
|
RECT r; |
| 261 |
|
|
int x, y; |
| 262 |
|
|
double e; |
| 263 |
|
|
|
| 264 |
|
|
for (cp = s; isspace(*cp); cp++) |
| 265 |
|
|
; |
| 266 |
|
|
if (*cp == '\0') { /* normalize to point */ |
| 267 |
|
|
if (dev->getcur == NULL) |
| 268 |
|
|
return; |
| 269 |
|
|
(*dev->comout)("Pick point for exposure\n"); |
| 270 |
|
|
if ((*dev->getcur)(&x, &y) == ABORT) |
| 271 |
|
|
return; |
| 272 |
|
|
r.l = r.d = 0; |
| 273 |
|
|
r.r = ourview.hresolu; r.u = ourview.vresolu; |
| 274 |
|
|
p = findrect(x, y, &ptrunk, &r, -1); |
| 275 |
|
|
e = 1.0; |
| 276 |
|
|
} else { |
| 277 |
|
|
if (*cp == '=') { /* absolute setting */ |
| 278 |
|
|
p = NULL; |
| 279 |
|
|
e = 1.0/exposure; |
| 280 |
|
|
for (cp++; isspace(*cp); cp++) |
| 281 |
|
|
; |
| 282 |
|
|
if (*cp == '\0') { /* interactive */ |
| 283 |
|
|
sprintf(buf, "exposure (%lf): ", exposure); |
| 284 |
|
|
(*dev->comout)(buf); |
| 285 |
|
|
(*dev->comin)(buf); |
| 286 |
|
|
for (cp = buf; isspace(*cp); cp++) |
| 287 |
|
|
; |
| 288 |
|
|
if (*cp == '\0') |
| 289 |
|
|
return; |
| 290 |
|
|
} |
| 291 |
|
|
} else { /* normalize to average */ |
| 292 |
|
|
p = &ptrunk; |
| 293 |
|
|
e = 1.0; |
| 294 |
|
|
} |
| 295 |
|
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
| 296 |
|
|
e *= pow(2.0, atof(cp)); |
| 297 |
|
|
else /* multiplier */ |
| 298 |
|
|
e *= atof(cp); |
| 299 |
|
|
} |
| 300 |
|
|
if (p != NULL) { /* relative setting */ |
| 301 |
greg |
1.6 |
if (bright(p->v) <= FTINY) { |
| 302 |
greg |
1.1 |
error(COMMAND, "cannot normalize to zero"); |
| 303 |
|
|
return; |
| 304 |
|
|
} |
| 305 |
greg |
1.6 |
e *= 0.5 / bright(p->v); |
| 306 |
greg |
1.1 |
} |
| 307 |
|
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
| 308 |
|
|
return; |
| 309 |
|
|
scalepict(&ptrunk, e); |
| 310 |
|
|
exposure *= e; |
| 311 |
|
|
redraw(); |
| 312 |
|
|
} |
| 313 |
|
|
|
| 314 |
|
|
|
| 315 |
|
|
setparam(s) /* get/set program parameter */ |
| 316 |
|
|
register char *s; |
| 317 |
|
|
{ |
| 318 |
|
|
extern int psample; |
| 319 |
|
|
extern double maxdiff; |
| 320 |
|
|
extern double minweight; |
| 321 |
|
|
extern int maxdepth; |
| 322 |
|
|
extern double dstrsrc; |
| 323 |
greg |
1.5 |
extern double shadthresh; |
| 324 |
greg |
1.9 |
extern double shadcert; |
| 325 |
greg |
1.1 |
extern COLOR ambval; |
| 326 |
|
|
extern double ambacc; |
| 327 |
|
|
extern double minarad; |
| 328 |
|
|
extern int ambres; |
| 329 |
|
|
extern int ambdiv; |
| 330 |
|
|
extern int ambssamp; |
| 331 |
|
|
extern int ambounce; |
| 332 |
|
|
int i0; |
| 333 |
|
|
double d0, d1, d2; |
| 334 |
|
|
char buf[128]; |
| 335 |
|
|
|
| 336 |
|
|
if (s[0] == '\0') { |
| 337 |
greg |
1.9 |
(*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); |
| 338 |
greg |
1.1 |
(*dev->comin)(buf); |
| 339 |
|
|
s = buf; |
| 340 |
|
|
} |
| 341 |
|
|
switch (s[0]) { |
| 342 |
|
|
case 'l': /* limit */ |
| 343 |
|
|
switch (s[1]) { |
| 344 |
|
|
case 'w': /* weight */ |
| 345 |
|
|
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 346 |
|
|
sprintf(buf, "limit weight (%.6g): ", |
| 347 |
|
|
minweight); |
| 348 |
|
|
(*dev->comout)(buf); |
| 349 |
|
|
(*dev->comin)(buf); |
| 350 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
| 351 |
|
|
break; |
| 352 |
|
|
} |
| 353 |
|
|
minweight = d0; |
| 354 |
|
|
break; |
| 355 |
|
|
case 'r': /* reflection */ |
| 356 |
|
|
if (sscanf(s+2, "%d", &i0) != 1) { |
| 357 |
|
|
sprintf(buf, "limit reflection (%d): ", |
| 358 |
|
|
maxdepth); |
| 359 |
|
|
(*dev->comout)(buf); |
| 360 |
|
|
(*dev->comin)(buf); |
| 361 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
| 362 |
|
|
break; |
| 363 |
|
|
} |
| 364 |
|
|
maxdepth = i0; |
| 365 |
|
|
break; |
| 366 |
|
|
default: |
| 367 |
|
|
goto badparam; |
| 368 |
|
|
} |
| 369 |
|
|
break; |
| 370 |
greg |
1.5 |
case 'd': /* direct */ |
| 371 |
|
|
switch (s[1]) { |
| 372 |
|
|
case 'j': /* jitter */ |
| 373 |
|
|
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 374 |
|
|
sprintf(buf, "direct jitter (%.6g): ", |
| 375 |
|
|
dstrsrc); |
| 376 |
|
|
(*dev->comout)(buf); |
| 377 |
|
|
(*dev->comin)(buf); |
| 378 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
| 379 |
|
|
break; |
| 380 |
|
|
} |
| 381 |
|
|
dstrsrc = d0; |
| 382 |
greg |
1.9 |
break; |
| 383 |
|
|
case 'c': /* certainty */ |
| 384 |
|
|
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 385 |
|
|
sprintf(buf, "direct certainty (%.6g): ", |
| 386 |
|
|
shadcert); |
| 387 |
|
|
(*dev->comout)(buf); |
| 388 |
|
|
(*dev->comin)(buf); |
| 389 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
| 390 |
|
|
break; |
| 391 |
|
|
} |
| 392 |
|
|
shadcert = d0; |
| 393 |
greg |
1.5 |
break; |
| 394 |
greg |
1.8 |
case 't': /* threshold */ |
| 395 |
greg |
1.5 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 396 |
greg |
1.8 |
sprintf(buf, "direct threshold (%.6g): ", |
| 397 |
greg |
1.5 |
shadthresh); |
| 398 |
|
|
(*dev->comout)(buf); |
| 399 |
|
|
(*dev->comin)(buf); |
| 400 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
| 401 |
|
|
break; |
| 402 |
|
|
} |
| 403 |
|
|
shadthresh = d0; |
| 404 |
|
|
break; |
| 405 |
|
|
default: |
| 406 |
greg |
1.1 |
goto badparam; |
| 407 |
|
|
} |
| 408 |
|
|
break; |
| 409 |
|
|
case 'a': /* ambient */ |
| 410 |
|
|
switch (s[1]) { |
| 411 |
|
|
case 'v': /* value */ |
| 412 |
|
|
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
| 413 |
|
|
sprintf(buf, |
| 414 |
|
|
"ambient value (%.6g %.6g %.6g): ", |
| 415 |
|
|
colval(ambval,RED), |
| 416 |
|
|
colval(ambval,GRN), |
| 417 |
|
|
colval(ambval,BLU)); |
| 418 |
|
|
(*dev->comout)(buf); |
| 419 |
|
|
(*dev->comin)(buf); |
| 420 |
|
|
if (sscanf(buf, "%lf %lf %lf", |
| 421 |
|
|
&d0, &d1, &d2) != 3) |
| 422 |
|
|
break; |
| 423 |
|
|
} |
| 424 |
|
|
setcolor(ambval, d0, d1, d2); |
| 425 |
|
|
break; |
| 426 |
|
|
case 'a': /* accuracy */ |
| 427 |
|
|
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 428 |
|
|
sprintf(buf, "ambient accuracy (%.6g): ", |
| 429 |
|
|
ambacc); |
| 430 |
|
|
(*dev->comout)(buf); |
| 431 |
|
|
(*dev->comin)(buf); |
| 432 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
| 433 |
|
|
break; |
| 434 |
|
|
} |
| 435 |
|
|
ambacc = d0; |
| 436 |
|
|
break; |
| 437 |
|
|
case 'd': /* divisions */ |
| 438 |
|
|
if (sscanf(s+2, "%d", &i0) != 1) { |
| 439 |
|
|
sprintf(buf, "ambient divisions (%d): ", |
| 440 |
|
|
ambdiv); |
| 441 |
|
|
(*dev->comout)(buf); |
| 442 |
|
|
(*dev->comin)(buf); |
| 443 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
| 444 |
|
|
break; |
| 445 |
|
|
} |
| 446 |
|
|
ambdiv = i0; |
| 447 |
|
|
break; |
| 448 |
|
|
case 's': /* samples */ |
| 449 |
|
|
if (sscanf(s+2, "%d", &i0) != 1) { |
| 450 |
|
|
sprintf(buf, "ambient super-samples (%d): ", |
| 451 |
|
|
ambssamp); |
| 452 |
|
|
(*dev->comout)(buf); |
| 453 |
|
|
(*dev->comin)(buf); |
| 454 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
| 455 |
|
|
break; |
| 456 |
|
|
} |
| 457 |
|
|
ambssamp = i0; |
| 458 |
|
|
break; |
| 459 |
|
|
case 'b': /* bounces */ |
| 460 |
|
|
if (sscanf(s+2, "%d", &i0) != 1) { |
| 461 |
|
|
sprintf(buf, "ambient bounces (%d): ", |
| 462 |
|
|
ambounce); |
| 463 |
|
|
(*dev->comout)(buf); |
| 464 |
|
|
(*dev->comin)(buf); |
| 465 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
| 466 |
|
|
break; |
| 467 |
|
|
} |
| 468 |
|
|
ambounce = i0; |
| 469 |
|
|
break; |
| 470 |
|
|
case 'r': |
| 471 |
|
|
if (sscanf(s+2, "%d", &i0) != 1) { |
| 472 |
|
|
sprintf(buf, "ambient resolution (%d): ", |
| 473 |
|
|
ambres); |
| 474 |
|
|
(*dev->comout)(buf); |
| 475 |
|
|
(*dev->comin)(buf); |
| 476 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
| 477 |
|
|
break; |
| 478 |
|
|
} |
| 479 |
|
|
ambres = i0; |
| 480 |
|
|
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
| 481 |
|
|
break; |
| 482 |
|
|
default: |
| 483 |
|
|
goto badparam; |
| 484 |
|
|
} |
| 485 |
|
|
break; |
| 486 |
|
|
case 's': /* sample */ |
| 487 |
|
|
switch (s[1]) { |
| 488 |
|
|
case 'p': /* pixel */ |
| 489 |
|
|
if (sscanf(s+2, "%d", &i0) != 1) { |
| 490 |
|
|
sprintf(buf, "sample pixel (%d): ", psample); |
| 491 |
|
|
(*dev->comout)(buf); |
| 492 |
|
|
(*dev->comin)(buf); |
| 493 |
|
|
if (sscanf(buf, "%d", &i0) != 1) |
| 494 |
|
|
break; |
| 495 |
|
|
} |
| 496 |
|
|
psample = i0; |
| 497 |
|
|
pdepth = 0; |
| 498 |
|
|
break; |
| 499 |
greg |
1.8 |
case 't': /* threshold */ |
| 500 |
greg |
1.1 |
if (sscanf(s+2, "%lf", &d0) != 1) { |
| 501 |
greg |
1.8 |
sprintf(buf, "sample threshold (%.6g): ", |
| 502 |
greg |
1.1 |
maxdiff); |
| 503 |
|
|
(*dev->comout)(buf); |
| 504 |
|
|
(*dev->comin)(buf); |
| 505 |
|
|
if (sscanf(buf, "%lf", &d0) != 1) |
| 506 |
|
|
break; |
| 507 |
|
|
} |
| 508 |
|
|
maxdiff = d0; |
| 509 |
|
|
pdepth = 0; |
| 510 |
|
|
break; |
| 511 |
|
|
default: |
| 512 |
|
|
goto badparam; |
| 513 |
|
|
} |
| 514 |
|
|
break; |
| 515 |
|
|
case '\0': /* nothing */ |
| 516 |
|
|
break; |
| 517 |
|
|
default:; |
| 518 |
|
|
badparam: |
| 519 |
|
|
sprintf(errmsg, "%s: unknown variable", s); |
| 520 |
|
|
error(COMMAND, errmsg); |
| 521 |
|
|
break; |
| 522 |
|
|
} |
| 523 |
|
|
} |
| 524 |
|
|
|
| 525 |
|
|
|
| 526 |
|
|
traceray(s) /* trace a single ray */ |
| 527 |
|
|
char *s; |
| 528 |
|
|
{ |
| 529 |
|
|
char buf[128]; |
| 530 |
|
|
int x, y; |
| 531 |
|
|
RAY thisray; |
| 532 |
|
|
|
| 533 |
|
|
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
| 534 |
|
|
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
| 535 |
|
|
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
| 536 |
|
|
|
| 537 |
|
|
if (dev->getcur == NULL) |
| 538 |
|
|
return; |
| 539 |
|
|
(*dev->comout)("Pick ray\n"); |
| 540 |
|
|
if ((*dev->getcur)(&x, &y) == ABORT) |
| 541 |
|
|
return; |
| 542 |
|
|
|
| 543 |
|
|
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
| 544 |
|
|
|
| 545 |
|
|
} else if (normalize(thisray.rdir) == 0.0) { |
| 546 |
|
|
error(COMMAND, "zero ray direction"); |
| 547 |
|
|
return; |
| 548 |
|
|
} |
| 549 |
|
|
|
| 550 |
|
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 551 |
|
|
|
| 552 |
|
|
rayvalue(&thisray); |
| 553 |
|
|
|
| 554 |
|
|
if (thisray.ro == NULL) |
| 555 |
|
|
(*dev->comout)("ray hit nothing"); |
| 556 |
|
|
else { |
| 557 |
|
|
sprintf(buf, "ray hit %s %s \"%s\"", |
| 558 |
|
|
objptr(thisray.ro->omod)->oname, |
| 559 |
|
|
ofun[thisray.ro->otype].funame, |
| 560 |
|
|
thisray.ro->oname); |
| 561 |
|
|
(*dev->comout)(buf); |
| 562 |
|
|
(*dev->comin)(buf); |
| 563 |
|
|
if (thisray.rot >= FHUGE) |
| 564 |
|
|
(*dev->comout)("at infinity"); |
| 565 |
|
|
else { |
| 566 |
|
|
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
| 567 |
|
|
thisray.rop[1], thisray.rop[2]); |
| 568 |
|
|
(*dev->comout)(buf); |
| 569 |
|
|
} |
| 570 |
|
|
(*dev->comin)(buf); |
| 571 |
|
|
sprintf(buf, "with value (%.6g %.6g %.6g)", |
| 572 |
|
|
colval(thisray.rcol,RED), |
| 573 |
|
|
colval(thisray.rcol,GRN), |
| 574 |
|
|
colval(thisray.rcol,BLU)); |
| 575 |
|
|
(*dev->comout)(buf); |
| 576 |
|
|
} |
| 577 |
|
|
(*dev->comin)(buf); |
| 578 |
|
|
} |
| 579 |
|
|
|
| 580 |
|
|
|
| 581 |
|
|
writepict(s) /* write the picture to a file */ |
| 582 |
|
|
char *s; |
| 583 |
|
|
{ |
| 584 |
|
|
static char buf[128]; |
| 585 |
greg |
1.10 |
char *fname; |
| 586 |
greg |
1.1 |
FILE *fp; |
| 587 |
|
|
COLR *scanline; |
| 588 |
|
|
int y; |
| 589 |
|
|
|
| 590 |
|
|
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
| 591 |
|
|
error(COMMAND, "no file"); |
| 592 |
|
|
return; |
| 593 |
|
|
} |
| 594 |
greg |
1.10 |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
| 595 |
greg |
1.1 |
(fp = fopen(fname, "w")) == NULL) { |
| 596 |
|
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
| 597 |
|
|
error(COMMAND, errmsg); |
| 598 |
|
|
return; |
| 599 |
|
|
} |
| 600 |
|
|
(*dev->comout)("writing \""); |
| 601 |
|
|
(*dev->comout)(fname); |
| 602 |
|
|
(*dev->comout)("\"...\n"); |
| 603 |
|
|
/* write header */ |
| 604 |
|
|
fputs(progname, fp); |
| 605 |
|
|
fprintview(&ourview, fp); |
| 606 |
greg |
1.11 |
putc('\n', fp); |
| 607 |
greg |
1.1 |
if (exposure != 1.0) |
| 608 |
|
|
fprintf(fp, "EXPOSURE=%e\n", exposure); |
| 609 |
greg |
1.11 |
putc('\n', fp); |
| 610 |
|
|
fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, fp); |
| 611 |
greg |
1.1 |
|
| 612 |
|
|
scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR)); |
| 613 |
|
|
if (scanline == NULL) |
| 614 |
|
|
error(SYSTEM, "out of memory in writepict"); |
| 615 |
|
|
for (y = ourview.vresolu-1; y >= 0; y--) { |
| 616 |
|
|
getpictcolrs(y, scanline, &ptrunk, |
| 617 |
|
|
ourview.hresolu, ourview.vresolu); |
| 618 |
|
|
if (fwritecolrs(scanline, ourview.hresolu, fp) < 0) |
| 619 |
|
|
break; |
| 620 |
|
|
} |
| 621 |
|
|
if (fclose(fp) < 0) |
| 622 |
|
|
error(COMMAND, "write error"); |
| 623 |
|
|
free((char *)scanline); |
| 624 |
|
|
} |