home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / rayshade / part07 (.txt) < prev    next >
LaTeX Document  |  1991-07-21  |  55KB  |  1,487 lines

  1. Newsgroups: comp.sources.misc
  2. From: Rayshade Construction Co. <rayshade@weedeater.math.YALE.EDU>
  3. Subject:  v21i010:  rayshade - A raytracing package for UNIX, Part07/19
  4. Message-ID: <1991Jul20.043518.11539@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 891ba98c5797ca603465455588656d8b
  6. Date: Sat, 20 Jul 1991 04:35:18 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8. Submitted-by: Rayshade Construction Co. <rayshade@weedeater.math.YALE.EDU>
  9. Posting-number: Volume 21, Issue 10
  10. Archive-name: rayshade/part07
  11. Environment: UNIX, !16BIT
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 7 (of 19)."
  19. # Contents:  Doc/Guide/preface.tex Examples/pool.ray etc/nff2shade.awk
  20. #   libray/libcommon/sampling.c libray/libcommon/vecmath.c
  21. #   libray/liblight/spot.c libray/libobj/box.c libray/libobj/geom.h
  22. #   libray/libobj/intersect.c libray/libsurf/surface.c
  23. #   libshade/lightdef.c libshade/options.h libshade/symtab.c
  24. # Wrapped by kolb@woody on Wed Jul 17 17:56:46 1991
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'Doc/Guide/preface.tex' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Doc/Guide/preface.tex'\"
  28. echo shar: Extracting \"'Doc/Guide/preface.tex'\" \(3168 characters\)
  29. sed "s/^X//" >'Doc/Guide/preface.tex' <<'END_OF_FILE'
  30. X\chapter*{Preface}
  31. X\addcontentsline{toc}{chapter}{Preface}
  32. X{\em Rayshade} is a program for creating ray-traced images.
  33. XIt reads a description of a scene to be
  34. Xrendered and produces a color image corresponding to the
  35. Xdescription.
  36. X{\em Rayshade} was designed to make it easy to
  37. Xcreate nice pictures.
  38. XIt was also meant to be flexible, easy to modify,
  39. Xand relatively fast.
  40. XThe first version of \rayshade was written in 1987-1998 at
  41. XPrinceton University with help and encouragement from David Dobkin
  42. Xand David Hoffman.  That version was heavily based on a public-domain
  43. X``introductory'' ray tracer written by Roman Kuchkuda.
  44. XChanges to \rayshade from that point until version 4.0 were
  45. Xevolutionary in nature.
  46. XThe current version is to a large extent a re-write,
  47. Xand an attempt has been made to remove some of the fundamental
  48. Xproblems present in previous incarnations.
  49. XI wish to thank the many people who have made
  50. Xcontributions to the development of {\em rayshade} during the past four years.
  51. XThanks to Marc Andreessen, Ray Bellis, Dominique Boisvert, William Bouma,
  52. XAllen Braunsdorf, Jeff Butterworth, Nick Carriero, Nancy Everson, Tom Friedel,
  53. XRobert Funchess, David Gelernter, Mike Gigante, Ed Herderick, John Knuston,
  54. XRaphael Manfredi, Lee Moore, Dietmar Saupe, Brian Wyvill,
  55. Xand everybody else for their bug-fixes, suggestions, input files,
  56. Xencouragement, support, and other feedback.
  57. XDavid Dobkin first suggested that an extensible
  58. Xray tracer would be a worthwhile project.  Gavin Bell, David
  59. XHoffman, Lefteris Koutsofios, and Steven North
  60. Xwere the first users of the original \rayshade, and their feedback
  61. Xshowed that the project might indeed have a future.
  62. XIn the Fall of 1988,
  63. XPrzemyslaw Prusinkiewicz encouraged me
  64. Xto develop \rayshade further, and was, as always, full of ``insanely
  65. Xgreat'' ideas.  The resulting version of \rayshade was released
  66. Xon UseNet in 1989.  Allan Snider was particularly helpful in
  67. Xfinding bugs in version 3.0 and in making valuable suggestions
  68. Xas to how the program might be improved.
  69. X{\em Rashade} version 4.0
  70. Xwas written by Craig Kolb and Rod Bogart during 1990-1991, with contributions
  71. Xof ideas and code made by many others.
  72. XPat Hanrahan's {\em OOGL} provided the spirit, if not the letter, of the
  73. Xmodularity of the version 4.0.  Thanks to Pat and to Mark VandeWettering
  74. Xfor the ``net tracer'' conversations and for the inspiration to do something
  75. Xto clean up {\em rayshade}.
  76. XEric Haines saved the day on more than one occasion by suggesting
  77. Ximprovements, finding bugs, and saying nice things about \rayshade
  78. Xwhen I was all but ready to throw in the towel.
  79. XRobert Skinner was kind enough to provide the {\em Noise()}, {\em DNoise()},
  80. Xand other texturing functions and to allow them to be redistributed.
  81. XMark Podlipec provided the blob object and torus object, which uses
  82. XJochen Schwarze's cubic and quartic root-finding functions.
  83. XMajor Thanks to Rod Bogart for being willing to take the plunge and
  84. Xplay such a large role in the development of version 4.0.
  85. XI am most grateful to Benoit Mandelbrot for his
  86. Xcontinued support and inspiration.
  87. X\begin{flushright}
  88. X\parbox[t]{1.5in}{
  89. XC. Kolb \\
  90. XFebruary 13, 1991
  91. X\end{flushright}
  92. END_OF_FILE
  93. if test 3168 -ne `wc -c <'Doc/Guide/preface.tex'`; then
  94.     echo shar: \"'Doc/Guide/preface.tex'\" unpacked with wrong size!
  95. # end of 'Doc/Guide/preface.tex'
  96. if test -f 'Examples/pool.ray' -a "${1}" != "-c" ; then 
  97.   echo shar: Will not clobber existing file \"'Examples/pool.ray'\"
  98. echo shar: Extracting \"'Examples/pool.ray'\" \(3791 characters\)
  99. sed "s/^X//" >'Examples/pool.ray' <<'END_OF_FILE'
  100. X/* Converted by rsconvert */
  101. X * Example rayshade input file
  102. X * pool table from "Reds' Nightmare"
  103. X * C. Kolb 2/88
  104. X * $Id: pool.ray,v 4.0 91/07/17 14:26:36 kolb Exp Locker: kolb $
  105. X * $Log:    pool.ray,v $
  106. X * Revision 4.0  91/07/17  14:26:36  kolb
  107. X * Initial version.
  108. Xup 0 0 1 
  109. Xfov 45 
  110. Xscreen 512 512 
  111. Xmaxdepth 2 
  112. Xbackground 0 0 0 
  113. Xlight 1.4 point 20 0 66 
  114. Xsurface blacktile 
  115. X    ambient 0.01 0.01 0.01 
  116. X    diffuse 0.01 0.01 0.01 
  117. Xsurface s0 
  118. X    ambient 0.862745 0.862745 0.862745 
  119. X    diffuse 0.039216 0.039216 0.039216 
  120. Xsurface s1 
  121. X    ambient 0.470588 0.156863 0.392157 
  122. X    diffuse 0.470588 0.156863 0.392157 
  123. X    specular 1 1 1
  124. Xsurface s2 
  125. X    ambient 0.117647 0.117647 0.392157 
  126. X    diffuse 0.117647 0.117647 0.392157 
  127. Xsurface s3 
  128. X    ambient 0.784314 0.078431 0.078431 
  129. X    diffuse 0.470588 0.039216 0.039216 
  130. Xsurface s4 
  131. X    ambient 0 0.2235 0.145 
  132. X    diffuse 0 0.2235 0.145 
  133. Xsurface mirror 
  134. X    ambient 0.04 0.04 0.04 
  135. X    diffuse 0.05 0.05 0.05 
  136. X    specular .8 .8 .8
  137. X    specpow 60 
  138. X    reflect 1.
  139. Xsurface s5 
  140. X    ambient 0.196078 0.392157 0.117647 
  141. X    diffuse 0.196078 0.392157 0.117647 
  142. X    specular 0.156863 0.156863 0.156863 
  143. X    specpow 7 
  144. X    reflect 1.
  145. Xsurface s6 
  146. X    ambient 0.588235 0.392157 0.117647 
  147. X    diffuse 0.196078 0.392157 0.117647 
  148. X    specular 0.156863 0.156863 0.156863 
  149. X    specpow 7 
  150. X    reflect 1.
  151. Xsurface s7 
  152. X    ambient 0.196078 0.392157 0.509804 
  153. X    diffuse 0.196078 0.392157 0.117647 
  154. X    specular 0.156863 0.156863 0.156863 
  155. X    specpow 7 
  156. X    reflect 1.
  157. Xsurface s8 
  158. X    ambient 0.980392 0.196078 0.117647 
  159. X    diffuse 0.196078 0.392157 0.117647 
  160. X    specular 0.156863 0.156863 0.156863 
  161. X    specpow 7 
  162. X    reflect 1.
  163. Xsurface s9 
  164. X    ambient 0.196078 0.392157 0.901961 
  165. X    diffuse 0.196078 0 0.117647 
  166. X    specular 0.156863 0.156863 0.156863 
  167. X    specpow 7 
  168. X    reflect 1.
  169. Xsurface s10 
  170. X    ambient 0.411765 0.411765 0.176471 
  171. X    diffuse 0.411765 0.411765 0.176471 
  172. Xsurface floor 
  173. X    ambient 0.1 0.1 0.1 
  174. X    diffuse 0.5 0.5 0.45 
  175. X    specular 0.8 0.8 0.8 
  176. X    specpow 18 
  177. Xsurface s12 
  178. X    ambient 0.313725 0.313725 0.313725 
  179. X    diffuse 0.745098 0.745098 0.745098 
  180. Xsurface s13 
  181. X    ambient 0.078431 0.862745 0.078431 
  182. X    diffuse 0.039216 0.039216 0.039216 
  183. X    specular 0.156863 0.156863 0.156863 
  184. X    specpow 7 
  185. Xsurface s14 
  186. X    ambient 0.784314 0.078431 0.078431 
  187. X    diffuse 0.470588 0.039216 0.039216 
  188. Xsurface s15 
  189. X    ambient 0.392157 0.098039 0.047059 
  190. X    diffuse 0.392157 0.098039 0.047059 
  191. X    specular 0.039216 0.039216 0.039216 
  192. X    specpow 3 
  193. Xsurface s16 
  194. X    ambient 0.509804 0.509804 0.509804 
  195. X    diffuse 0.509804 0.509804 0.509804 
  196. X    specular 0.156863 0.156863 0.156863 
  197. X    specpow 7 
  198. X    reflect 1.
  199. Xsphere s5 1.5 0     -21         1.5 
  200. X    sphere s6 1.5 1.5     -23.598     1.5 
  201. X    sphere s7 1.5 -1.5     -23.598     1.5 
  202. X    sphere s8 1.5 3     -26.1962     1.5 
  203. X    sphere s9 1.5 0     -26.1962     1.5 
  204. X    sphere s5 1.5 -3     -26.1962     1.5 
  205. X    sphere s6 1.5 4.5     -28.7942     1.5 
  206. X    sphere s7 1.5 1.5     -28.7942     1.5 
  207. X    sphere s8 1.5 -1.5     -28.7942     1.5 
  208. X    sphere s9 1.5 -4.5     -28.7942     1.5 
  209. X    sphere s5 1.5 6     -31.3923     1.5 
  210. X    sphere s6 1.5 3     -31.3923     1.5 
  211. X    sphere s7 1.5 0     -31.3923     1.5 
  212. X    sphere s8 1.5 -3     -31.3923     1.5 
  213. X    sphere s9 1.5 -6     -31.3923     1.5 
  214. X    box s4 -30 -57 -2 30 57 0 
  215. X    box s15 27 -54 -1.5 33 54 1.5 texture wood scale 15 10 15 
  216. X    box s15 -33 -54 -1.5 -27 54 1.5 texture wood scale 15 10 15 
  217. X    box s15 -33 54 -1.5 33 60 1.5 texture wood scale 10 15 15 
  218. X    box s15 -33 -60 -1.5 33 -54 1.5 texture wood scale 10 15 15 
  219. X    sphere s16 1.5 0 0 0 translate 0 21 1.5 
  220. X    box mirror -11.3333 -144.1 10 31.3333 -143.9 50     /* was 40. -144 30. */
  221. X     * Walls
  222. X     */
  223. X    plane s10                     0 -144 0 0 1 0 
  224. X    plane s10                 -180 0 0 1 0 0 
  225. X    plane s10             180 0 0 -1 0 0 
  226. X    plane s10             0 144 0 0 -1 0 
  227. X     * Floor
  228. X     */
  229. X    plane floor                 0 0 -30 0 0 1 
  230. X        texture marble scale 6 6 6 rotate 1 0 0 90 
  231. X                translate 0 0 -4.376 
  232. X        texture checker blacktile scale 12.3 12.3 12.3 
  233. X     * Ceiling
  234. X     */
  235. X    plane s12         0 0 72 0 0 -1 
  236. Xeyep 38 100 43 
  237. Xlookp 0 0 0 
  238. END_OF_FILE
  239. if test 3791 -ne `wc -c <'Examples/pool.ray'`; then
  240.     echo shar: \"'Examples/pool.ray'\" unpacked with wrong size!
  241. # end of 'Examples/pool.ray'
  242. if test -f 'etc/nff2shade.awk' -a "${1}" != "-c" ; then 
  243.   echo shar: Will not clobber existing file \"'etc/nff2shade.awk'\"
  244. echo shar: Extracting \"'etc/nff2shade.awk'\" \(3477 characters\)
  245. sed "s/^X//" >'etc/nff2shade.awk' <<'END_OF_FILE'
  246. X# This awk script will convert an NFF-format input file (as output by
  247. X# Eric Haines' SPD) to something rayshade can understand.
  248. X# The World object will be enclosed in a single grid of 22*22*22 voxels.
  249. X# Example usage:
  250. X#    mount | awk -f sped2shade.awk | rayshade > mountains.rle
  251. X# For best results, one should modify the output for all but the tetra
  252. X# and mountain databases to provide a tighter bounding box around the
  253. X# object of interest (tree, gears, etc.).  This is done by moving
  254. X# ground polygons and the like outside of the topmost grid object.
  255. X# This will decrease ray-tracing time dramatically.
  256. X# Note that we have to make sure that the viewing paramters are output
  257. X# outside of the object definition block.  We do this by printing
  258. X# the eye position, etc., at the very end of the output.
  259. XBEGIN{
  260. X    init = 0;
  261. X    lights = 0;
  262. X    print "maxdepth 4"
  263. X    print "sample 1 nojitter"
  264. X    print "cutoff 0."
  265. X    print "report verbose"
  266. Xsubstr($1, 1, 1) == "#" { print "/* " $0 " */"; next;}
  267. X$1 == "v" { next;}
  268. X$1 == "from" { eyex = $2; eyey = $3; eyez = $4; next;}
  269. X$1 == "at" { atx = $2; aty = $3; atz = $4; next;}
  270. X$1 == "up" { upx = $2; upy = $3; upz = $4; next;}
  271. X$1 == "angle" { fov = $2; next;}
  272. X$1 == "hither" {next;}
  273. X$1 == "resolution" {screenx = $2; screeny = $3; next;}
  274. X$1 == "l" { lightd[lights] = $2 " "$3 " "$4; lights++; next; }
  275. X$1 == "b" {print "background " $2 " "$3 " "$4; next; }
  276. X$1 == "f" {
  277. X    if (init == 0) {
  278. X        print "grid 22 22 22";
  279. X        init = 1;
  280. X    printf("applysurf ");
  281. X    if (lights != 0)
  282. X        aintens = sqrt(lights) / (4*lights);
  283. X    else
  284. X        aintens = .1;
  285. X    dr = $2*$5;
  286. X    dg = $3*$5;
  287. X    db = $4*$5;
  288. X# this is a good guess....
  289. X    ar = aintens*dr;
  290. X    ag = aintens*dg;
  291. X    ab = aintens*db;
  292. X    if (ar != 0 || ag != 0 || ab != 0)
  293. X        printf("\tambient %f %f %f\n", ar, ag, ab);
  294. X    if (dr != 0 || dg != 0 || db != 0)
  295. X        printf("\tdiffuse %f %f %f\n", dr, dg, db);
  296. X# This gets a little strange.  We're given a color, Ks, and T.
  297. X# We need a specular color, a specular reflectivity (for reflected
  298. X# rays), and a transparency (for transmitted rays).
  299. X# In rayshade, reflected rays have intensity proportional to
  300. X# specular_color*reflectivity, transmitted proportaional to
  301. X# specular_color*transparency, and specular hilights to
  302. X# specular_color.  Also, Ks + T >1 for some SPDs.
  303. X    if ($6) {
  304. X        sr = $2*$6;
  305. X        sg = $3*$6;
  306. X        sb = $4*$6;
  307. X        printf("\tspecular %f %f %f specpow %f\n", sr, sg, sb, $7);
  308. X    if ($6 < 1. - $8)
  309. X        printf("\treflect 1.0\n");
  310. X    else
  311. X        printf("\treflect %f\n", 1. - $8);
  312. X    if ($8 || $9)
  313. X        printf("\ttransp %f index %f\n", $8, $9);
  314. X    next;
  315. X$1 == "c" {
  316. X    getline;
  317. X    x1 = $1;
  318. X    y1 = $2;
  319. X    z1 = $3;
  320. X    br = $4;
  321. X    getline;
  322. X    printf("cone %f %f %f %f %f %f %f %f\n", \
  323. X        br, x1, y1, z1, $4, $1, $2, $3);
  324. X    next;
  325. X$1 == "s" {
  326. X    print "sphere "$5 " "$2 " "$3 " "$4;
  327. X    next;
  328. X$1 == "pp" {
  329. X    if ($2 == 3)
  330. X        print "triangle ";
  331. X    else
  332. X        print "poly ";
  333. X    next;
  334. X$1 == "p" {
  335. X# Polygon -- the vertices will print out in the default statement.
  336. X# If there are three vertices, make it a triangle.
  337. X    if ($2 == 3)
  338. X        print "triangle ";
  339. X    else
  340. X        print "poly ";
  341. X    next;
  342. X# Matched nothing (or is a vertex data) -- print it.
  343. X    print;
  344. X    next;
  345. XEND{
  346. X    print "end"
  347. X# Output light definitions.
  348. X    intens = sqrt(lights) / (lights);
  349. X    for (i = 0; i < lights; i++) {
  350. X        print "light " intens " point " lightd[i]
  351. X    printf("eyep %g %g %g\n", eyex, eyey, eyez);
  352. X    printf("lookp %g %g %g\n", atx, aty, atz);
  353. X    printf("up %g %g %g\n", upx, upy, upz);
  354. X    printf("fov %g\n", fov);
  355. X    printf("screen %d %d\n", screenx, screeny);
  356. END_OF_FILE
  357. if test 3477 -ne `wc -c <'etc/nff2shade.awk'`; then
  358.     echo shar: \"'etc/nff2shade.awk'\" unpacked with wrong size!
  359. # end of 'etc/nff2shade.awk'
  360. if test -f 'libray/libcommon/sampling.c' -a "${1}" != "-c" ; then 
  361.   echo shar: Will not clobber existing file \"'libray/libcommon/sampling.c'\"
  362. echo shar: Extracting \"'libray/libcommon/sampling.c'\" \(3298 characters\)
  363. sed "s/^X//" >'libray/libcommon/sampling.c' <<'END_OF_FILE'
  364. X * sampling.c
  365. X * Copyright (C) 1989, 1991, Craig E. Kolb, Rod G. Bogart
  366. X * All rights reserved.
  367. X * This software may be freely copied, modified, and redistributed
  368. X * provided that this copyright notice is preserved on all copies.
  369. X * You may not distribute this software, in whole or in part, as part of
  370. X * any commercial product without the express consent of the authors.
  371. X * There is no warranty or other guarantee of fitness of this software
  372. X * for any purpose.  It is provided solely "as is".
  373. X * $Id: sampling.c,v 4.0 91/07/17 14:31:55 kolb Exp Locker: kolb $
  374. X * $Log:    sampling.c,v $
  375. X * Revision 4.0  91/07/17  14:31:55  kolb
  376. X * Initial version.
  377. X#include "common.h"
  378. X#include "sampling.h"
  379. XSampleInfo    Sampling;    /* sampling information */
  380. X * Set sampling options.
  381. Xvoid
  382. XSamplingSetOptions(n, gaussian, width)
  383. Xint n, gaussian;
  384. XFloat width;
  385. X    Float norm, u, v;
  386. X    int x, y;
  387. X    Sampling.sidesamples = n;
  388. X    Sampling.totsamples = n*n;
  389. X    Sampling.weight = 1. / (Float)Sampling.totsamples;
  390. X    Sampling.spacing = 1. / (Float)Sampling.sidesamples;
  391. X    Sampling.filterwidth = width;
  392. X    Sampling.filterdelta = Sampling.filterwidth * Sampling.spacing;
  393. X    Sampling.gaussian = gaussian;
  394. X    Sampling.filter = (Float **)Malloc(Sampling.sidesamples
  395. X        *sizeof(Float *));
  396. X    for (y = 0; y < Sampling.sidesamples; y++) {
  397. X        Sampling.filter[y] = (Float *)Malloc(Sampling.sidesamples *
  398. X            sizeof(Float));
  399. X    if (Sampling.gaussian) {
  400. X        norm = 0.;
  401. X        u = -0.5*Sampling.filterwidth + 
  402. X             0.5*Sampling.filterwidth*Sampling.spacing;
  403. X        for (x = 0; x < Sampling.sidesamples; x++) {
  404. X            v = -0.5*Sampling.filterwidth +
  405. X                 0.5*Sampling.filterwidth*Sampling.spacing;
  406. X            for (y = 0; y < Sampling.sidesamples; y++) {
  407. X                Sampling.filter[x][y] = exp(-0.5*(u*u+v*v));
  408. X                norm += Sampling.filter[x][y];
  409. X                v += Sampling.spacing *
  410. X                    Sampling.filterwidth;
  411. X            }
  412. X            u += Sampling.spacing * Sampling.filterwidth;
  413. X        for (x = 0; x < Sampling.sidesamples; x++)
  414. X            for (y = 0; y < Sampling.sidesamples; y++)
  415. X                Sampling.filter[x][y] /= norm;
  416. X    } else {
  417. X        /* Box filter.  Yawn. */
  418. X        for (x = 0; x < Sampling.sidesamples; x++)
  419. X            for (y = 0; y < Sampling.sidesamples; y++)
  420. X                Sampling.filter[x][y] = Sampling.weight;
  421. X * Set start time and duration of frame.
  422. Xvoid
  423. XSamplingSetTime(starttime, shutter, frame)
  424. XFloat starttime, shutter;
  425. Xint frame;
  426. X    Sampling.starttime = starttime;
  427. X    Sampling.shutter = shutter;
  428. X    Sampling.framenum = frame;
  429. X    TimeSet(Sampling.starttime);
  430. X    FrameSet((Float)frame);
  431. X * Find a point on a unit circle that is separated from other random
  432. X * points by some jitter spacing.
  433. X * It should do the above, but the temporary hack below just finds a
  434. X * jittered point in a unit square.
  435. Xvoid
  436. XUnitCirclePoint(pnt, sample)
  437. XVector *pnt;
  438. X     * This picks a random point on a -1 to 1 square.  The jitter stuff
  439. X     * is correct enough to avoid excessive noise.  An extremely blurry
  440. X     * bright highlight will look squarish, not roundish.  Sorry.
  441. X     */
  442. X    Float jit;
  443. X    if (sample >= 0) {
  444. X        jit = 2. * Sampling.spacing;
  445. X        pnt->x = nrand()*jit - 1.0 +
  446. X            (sample % Sampling.sidesamples) * jit;
  447. X        pnt->y = nrand()*jit - 1.0 +
  448. X            (sample / Sampling.sidesamples) * jit;
  449. X        pnt->z = 0.0;
  450. X    } else {
  451. X        pnt->x = nrand() * 2.0 - 1.0;
  452. X        pnt->y = nrand() * 2.0 - 1.0;
  453. X        pnt->z = 0.0;
  454. END_OF_FILE
  455. if test 3298 -ne `wc -c <'libray/libcommon/sampling.c'`; then
  456.     echo shar: \"'libray/libcommon/sampling.c'\" unpacked with wrong size!
  457. # end of 'libray/libcommon/sampling.c'
  458. if test -f 'libray/libcommon/vecmath.c' -a "${1}" != "-c" ; then 
  459.   echo shar: Will not clobber existing file \"'libray/libcommon/vecmath.c'\"
  460. echo shar: Extracting \"'libray/libcommon/vecmath.c'\" \(3640 characters\)
  461. sed "s/^X//" >'libray/libcommon/vecmath.c' <<'END_OF_FILE'
  462. X * vecmath.c
  463. X * Copyright (C) 1989, 1991, Craig E. Kolb
  464. X * All rights reserved.
  465. X * This software may be freely copied, modified, and redistributed
  466. X * provided that this copyright notice is preserved on all copies.
  467. X * You may not distribute this software, in whole or in part, as part of
  468. X * any commercial product without the express consent of the authors.
  469. X * There is no warranty or other guarantee of fitness of this software
  470. X * for any purpose.  It is provided solely "as is".
  471. X * $Id: vecmath.c,v 4.0 91/07/17 14:33:02 kolb Exp Locker: kolb $
  472. X * $Log:    vecmath.c,v $
  473. X * Revision 4.0  91/07/17  14:33:02  kolb
  474. X * Initial version.
  475. X#include "common.h"
  476. X * Normalize a vector, return original length.
  477. XFloat
  478. XVecNormalize(a)
  479. Xregister Vector *a;
  480. X    Float d;
  481. X    d = sqrt(a->x*a->x + a->y*a->y + a->z*a->z);
  482. X    if(d == 0.)
  483. X        return 0.;
  484. X    a->x /= d;
  485. X    a->y /= d;
  486. X    a->z /= d;
  487. X#ifdef CRAY
  488. X     * The Cray Research Inc. math functional units don't work in the IEEE
  489. X     * standard way, so when we get here, we just might have an x,y or z
  490. X     * that is not in the range  -1.0 <= J <= 1.0 Yes, I know that that
  491. X     * can't happen, but it does. So since we know we just normalized this
  492. X     * vector, we'll just force x,y and z into the range -1.0 to 1.0 O.K?
  493. X     */
  494. X    if (a->x >= 1.0) a->x = 1.0;
  495. X    else if (a->x <= -1.0) a->x = -1.0;
  496. X    if (a->y >= 1.0) a->y = 1.0;
  497. X    else if (a->y <= -1.0) a->y = -1.0;
  498. X    if (a->z >= 1.0) a->z = 1.0;
  499. X    else if (a->z <= -1.0) a->z = -1.0;
  500. X#endif /* CRAY */
  501. X    return d;
  502. X * Compute cross-product of a and b, place normalized result in o.  Returns
  503. X * length of result before normalization.
  504. XFloat
  505. XVecNormCross(a, b, r)
  506. XVector *a, *b, *r;
  507. X    VecCross(a, b, r);
  508. X    return VecNormalize(r);
  509. X * Compute cross-product of a and b, place result in o.
  510. Xvoid
  511. XVecCross(a, b, r)
  512. XVector *a, *b, *r;
  513. X    r->x = (a->y * b->z) - (a->z * b->y);
  514. X    r->y = (a->z * b->x) - (a->x * b->z);
  515. X    r->z = (a->x * b->y) - (a->y * b->x);
  516. X * Calculate direction of refracted ray using Heckbert's formula.  Returns TRUE
  517. X * if a total internal reflection occurs.
  518. XRefract(dir, from_index, to_index, I, N, cos1)
  519. XFloat from_index, to_index, cos1;
  520. XVector *dir, *I, *N;
  521. X    Float kn, cos2, k;
  522. X    Vector nrm;
  523. X    if (cos1 < 0.) {
  524. X        /*
  525. X         * Hit the 'backside' of a surface -- flip the normal.
  526. X         */
  527. X        nrm.x = -N->x;
  528. X        nrm.y = -N->y;
  529. X        nrm.z = -N->z;
  530. X        cos1 = -cos1;
  531. X    } else
  532. X        nrm = *N;
  533. X    kn = from_index / to_index;
  534. X    cos2 = 1. - kn*kn*(1. - cos1*cos1);
  535. X    if (cos2 < 0.)
  536. X        return TRUE;        /* Total internal reflection. */
  537. X    k = kn * cos1 - sqrt(cos2);
  538. X    VecComb(kn, *I, k, nrm, dir);
  539. X    return FALSE;
  540. X * Given a vector, find two additional vectors such that all three
  541. X * are mutually perpendicular and uaxis X vaxis = vector.  The given
  542. X * vector need not be normalized. uaxis and vaxis are normalized.
  543. Xvoid
  544. XVecCoordSys(vector, uaxis, vaxis)
  545. XVector *vector, *uaxis, *vaxis;
  546. X    uaxis->x = -vector->y;
  547. X    uaxis->y = vector->x;
  548. X    uaxis->z = 0.;
  549. X    if (VecNormalize(uaxis) == 0.) {
  550. X        uaxis->x = vector->z;
  551. X        uaxis->y = 0.;
  552. X        uaxis->z = -vector->x;
  553. X        if (VecNormalize(uaxis) == 0.)
  554. X            RLerror(RL_WARN,
  555. X                "VecCoordSys passed degenerate vector.\n");
  556. X    (void)VecNormCross(vector, uaxis, vaxis);
  557. X * Modify given normal by "bumping" it.
  558. Xvoid
  559. XMakeBump(norm, dpdu, dpdv, fu, fv)
  560. XVector *norm, *dpdu, *dpdv;    /* normal, surface derivatives */
  561. XFloat fu, fv;            /* bump function partial derivatives in uv */
  562. X    Vector tmp1, tmp2;
  563. X    VecCross(norm, dpdv, &tmp1);
  564. X    VecScale(fu, tmp1, &tmp1);
  565. X    VecCross(norm, dpdu, &tmp2);
  566. X    VecScale(fv, tmp2, &tmp2);
  567. X    VecSub(tmp1, tmp2, &tmp1);
  568. X    VecAdd(*norm, tmp1, norm);
  569. X    (void)VecNormalize(norm);
  570. END_OF_FILE
  571. if test 3640 -ne `wc -c <'libray/libcommon/vecmath.c'`; then
  572.     echo shar: \"'libray/libcommon/vecmath.c'\" unpacked with wrong size!
  573. # end of 'libray/libcommon/vecmath.c'
  574. if test -f 'libray/liblight/spot.c' -a "${1}" != "-c" ; then 
  575.   echo shar: Will not clobber existing file \"'libray/liblight/spot.c'\"
  576. echo shar: Extracting \"'libray/liblight/spot.c'\" \(3312 characters\)
  577. sed "s/^X//" >'libray/liblight/spot.c' <<'END_OF_FILE'
  578. X * spot.c
  579. X * Copyright (C) 1989, 1991, Craig E. Kolb
  580. X * All rights reserved.
  581. X * This software may be freely copied, modified, and redistributed
  582. X * provided that this copyright notice is preserved on all copies.
  583. X * You may not distribute this software, in whole or in part, as part of
  584. X * any commercial product without the express consent of the authors.
  585. X * There is no warranty or other guarantee of fitness of this software
  586. X * for any purpose.  It is provided solely "as is".
  587. X * $Id: spot.c,v 4.0 91/07/17 14:35:42 kolb Exp Locker: kolb $
  588. X * $Log:    spot.c,v $
  589. X * Revision 4.0  91/07/17  14:35:42  kolb
  590. X * Initial version.
  591. X#include "light.h"
  592. X#include "spot.h"
  593. Xstatic LightMethods *iSpotMethods = NULL;
  594. XSpotlight *
  595. XSpotCreate(from, to, coef, in, out)
  596. XVector *from, *to;
  597. XFloat coef, in, out;
  598. X    Spotlight *spot;
  599. X    spot = (Spotlight *)share_malloc(sizeof(Spotlight));
  600. X    spot->pos = *from;
  601. X    VecSub(*to, *from, &spot->dir);
  602. X    if (VecNormalize(&spot->dir) == 0. || in > out) {
  603. X        RLerror(RL_ABORT,"Invalid spotlight specification.\n");
  604. X        return (Spotlight *)NULL;
  605. X    spot->coef = coef;
  606. X    spot->radius = cos(deg2rad(in));
  607. X    spot->falloff = cos(deg2rad(out));
  608. X    return spot;
  609. XLightMethods *
  610. XSpotMethods()
  611. X    if (iSpotMethods == (LightMethods *)NULL) {
  612. X        iSpotMethods = LightMethodsCreate();
  613. X        iSpotMethods->intens = SpotIntens;
  614. X        iSpotMethods->dir = SpotDirection;
  615. X    return iSpotMethods;
  616. X * Calculate intensity ('color') of light reaching 'pos' from light 'lp'.
  617. X * The spotlight is 'dist' units from 'pos' along 'dir'.
  618. X * Returns TRUE if non-zero illumination, FALSE otherwise.
  619. XSpotIntens(spot, lcolor, cache, ray, dist, noshadow, color)
  620. XSpotlight *spot;
  621. XShadowCache *cache;
  622. XRay *ray;
  623. XColor *lcolor, *color;
  624. Xint noshadow;
  625. XFloat dist;
  626. X    Float atten;
  627. X    extern Float SpotAtten();
  628. X     * Compute spotlight color
  629. X     */
  630. X    atten = SpotAtten(spot, &ray->dir);
  631. X     * If outside of spot, return FALSE.
  632. X     */
  633. X    if (atten == 0.)
  634. X        return FALSE;
  635. X    if (Shadowed(color, lcolor, cache, ray, dist, noshadow))
  636. X        return FALSE;
  637. X    ColorScale(atten, *color, color);
  638. X    return TRUE;
  639. X * Compute intensity of spotlight along 'dir'.
  640. XFloat
  641. XSpotAtten(lp, dir)
  642. XSpotlight *lp;
  643. XVector *dir;
  644. X    Float costheta, atten;
  645. X    extern Float rampup();
  646. X    costheta = -dotp(dir, &lp->dir);
  647. X     * Behind spotlight.
  648. X     */
  649. X    if (costheta <= 0.)
  650. X        return 0.;
  651. X     * Intensity is the product of costheta raised to lp->coef and
  652. X     * a function that smoothly interpolates from 0 at
  653. X     * costheta=lp->falloff to 1 at costheta=lp->radius.
  654. X     */
  655. X    atten = pow(costheta, lp->coef);
  656. X    if (lp->radius > 0.)
  657. X        atten *= rampup(lp->falloff, lp->radius, costheta);
  658. X    return atten;
  659. X * Cubic interpolation between 0 at left and 1 at right, sampled at 'at'
  660. X * It is assumed that right >= left.
  661. XFloat
  662. Xrampup(left, right, at)
  663. XFloat left, right, at;
  664. X    if (at < left)
  665. X        return 0.;
  666. X    else if (at > right)
  667. X        return 1.;
  668. X    if (right == left)
  669. X        return 0.;
  670. X    at = (at - left) / (right - left);
  671. X    return (3 - 2*at)*at*at;
  672. Xvoid
  673. XSpotDirection(lp, pos, dir, dist)
  674. XSpotlight *lp;
  675. XVector *pos, *dir;
  676. XFloat *dist;
  677. X     * Calculate dir from position to center of light source.
  678. X     */
  679. X    VecSub(lp->pos, *pos, dir);
  680. X    *dist = VecNormalize(dir);
  681. XSpotMethodRegister(meth)
  682. XUserMethodType meth;
  683. X    if (iSpotMethods)
  684. X        iSpotMethods->user = meth;
  685. END_OF_FILE
  686. if test 3312 -ne `wc -c <'libray/liblight/spot.c'`; then
  687.     echo shar: \"'libray/liblight/spot.c'\" unpacked with wrong size!
  688. # end of 'libray/liblight/spot.c'
  689. if test -f 'libray/libobj/box.c' -a "${1}" != "-c" ; then 
  690.   echo shar: Will not clobber existing file \"'libray/libobj/box.c'\"
  691. echo shar: Extracting \"'libray/libobj/box.c'\" \(3201 characters\)
  692. sed "s/^X//" >'libray/libobj/box.c' <<'END_OF_FILE'
  693. X * box.c
  694. X * Copyright (C) 1989, 1991, Craig E. Kolb
  695. X * All rights reserved.
  696. X * This software may be freely copied, modified, and redistributed
  697. X * provided that this copyright notice is preserved on all copies.
  698. X * You may not distribute this software, in whole or in part, as part of
  699. X * any commercial product without the express consent of the authors.
  700. X * There is no warranty or other guarantee of fitness of this software
  701. X * for any purpose.  It is provided solely "as is".
  702. X * $Id: box.c,v 4.0 91/07/17 14:36:32 kolb Exp Locker: kolb $
  703. X * $Log:    box.c,v $
  704. X * Revision 4.0  91/07/17  14:36:32  kolb
  705. X * Initial version.
  706. X#include "geom.h"
  707. X#include "box.h"
  708. Xstatic Methods *iBoxMethods = NULL;
  709. Xstatic char boxName[] = "box";
  710. Xunsigned long BoxTests, BoxHits;
  711. XBox *
  712. XBoxCreate(v1, v2)
  713. XVector *v1, *v2;
  714. X    Box *box;
  715. X    Vector size;
  716. X    VecSub(*v1, *v2, &size);
  717. X    if (equal(size.x, 0.) || equal(size.y, 0.) || equal(size.z, 0.)) {
  718. X        RLerror(RL_WARN, "Degenerate box.\n");
  719. X        return (Box *)NULL;
  720. X    box = (Box *)share_malloc(sizeof(Box));
  721. X    box->bounds[LOW][X] = min(v1->x, v2->x);
  722. X    box->bounds[HIGH][X] = max(v1->x, v2->x);
  723. X    box->bounds[LOW][Y] = min(v1->y, v2->y);
  724. X    box->bounds[HIGH][Y] = max(v1->y, v2->y);
  725. X    box->bounds[LOW][Z] = min(v1->z, v2->z);
  726. X    box->bounds[HIGH][Z] = max(v1->z, v2->z);
  727. X    return box;
  728. XMethods *
  729. XBoxMethods()
  730. X    if (iBoxMethods == (Methods *)NULL) {
  731. X        iBoxMethods = MethodsCreate();
  732. X        iBoxMethods->create = (GeomCreateFunc *)BoxCreate;
  733. X        iBoxMethods->methods = BoxMethods;
  734. X        iBoxMethods->name = BoxName;
  735. X        iBoxMethods->intersect = BoxIntersect;
  736. X        iBoxMethods->normal = BoxNormal;
  737. X        iBoxMethods->enter = BoxEnter;
  738. X        iBoxMethods->bounds = BoxBounds;
  739. X        iBoxMethods->stats = BoxStats;
  740. X        iBoxMethods->checkbounds = FALSE;
  741. X        iBoxMethods->closed = TRUE;
  742. X    return iBoxMethods;
  743. XBoxIntersect(box, ray, mindist, maxdist)
  744. XBox *box;
  745. XRay *ray;
  746. XFloat mindist, *maxdist;
  747. X    BoxTests++;
  748. X    if (BoundsIntersect(ray, box->bounds, mindist, maxdist)) {
  749. X        BoxHits++;
  750. X        return TRUE;
  751. X    return FALSE;
  752. XBoxNormal(box, pos, nrm, gnrm)
  753. XVector *pos, *nrm, *gnrm;    /* point of intersection */
  754. XBox *box;
  755. X    nrm->x = nrm->y = nrm->z = 0.;
  756. X    if (equal(pos->x, box->bounds[HIGH][X]))
  757. X        nrm->x = 1.;
  758. X    else if (equal(pos->x, box->bounds[LOW][X]))
  759. X        nrm->x = -1.;
  760. X    else if (equal(pos->y, box->bounds[HIGH][Y]))
  761. X        nrm->y = 1.;
  762. X    else if (equal(pos->y, box->bounds[LOW][Y]))
  763. X        nrm->y = -1.;
  764. X    else if (equal(pos->z, box->bounds[HIGH][Z]))
  765. X        nrm->z = 1.;
  766. X    else if (equal(pos->z, box->bounds[LOW][Z]))
  767. X        nrm->z = -1.;
  768. X    else
  769. X        RLerror(RL_WARN, "Confusion in nrmbox!\n");
  770. X    *gnrm = *nrm;
  771. X    return FALSE;
  772. X * Determine if ray enters (TRUE) or leaves (FALSE) box at pos
  773. XBoxEnter(box, ray, mind, hitd)
  774. XBox *box;
  775. XRay *ray;
  776. XFloat mind, hitd;
  777. X    Vector pos;
  778. X    VecAddScaled(ray->pos, mind, ray->dir, &pos);
  779. X    return OutOfBounds(&pos, box->bounds);
  780. Xvoid
  781. XBoxBounds(box, bounds)
  782. XBox *box;
  783. XFloat bounds[2][3];
  784. X    BoundsCopy(box->bounds, bounds);
  785. Xchar *
  786. XBoxName()
  787. X    return boxName;
  788. Xvoid
  789. XBoxStats(tests, hits)
  790. Xunsigned long *tests, *hits;
  791. X    *tests = BoxTests;
  792. X    *hits = BoxHits;
  793. Xvoid
  794. XBoxMethodRegister(meth)
  795. XUserMethodType meth;
  796. X    if (iBoxMethods)
  797. X        iBoxMethods->user = meth;
  798. END_OF_FILE
  799. if test 3201 -ne `wc -c <'libray/libobj/box.c'`; then
  800.     echo shar: \"'libray/libobj/box.c'\" unpacked with wrong size!
  801. # end of 'libray/libobj/box.c'
  802. if test -f 'libray/libobj/geom.h' -a "${1}" != "-c" ; then 
  803.   echo shar: Will not clobber existing file \"'libray/libobj/geom.h'\"
  804. echo shar: Extracting \"'libray/libobj/geom.h'\" \(3949 characters\)
  805. sed "s/^X//" >'libray/libobj/geom.h' <<'END_OF_FILE'
  806. X * geom.h
  807. X * Copyright (C) 1989, 1991, Craig E. Kolb
  808. X * All rights reserved.
  809. X * This software may be freely copied, modified, and redistributed
  810. X * provided that this copyright notice is preserved on all copies.
  811. X * You may not distribute this software, in whole or in part, as part of
  812. X * any commercial product without the express consent of the authors.
  813. X * There is no warranty or other guarantee of fitness of this software
  814. X * for any purpose.  It is provided solely "as is".
  815. X * $Id: geom.h,v 4.0 91/07/17 14:37:52 kolb Exp Locker: kolb $
  816. X * $Log:    geom.h,v $
  817. X * Revision 4.0  91/07/17  14:37:52  kolb
  818. X * Initial version.
  819. X#ifndef OBJECT_H
  820. X#define OBJECT_H
  821. X#include "libcommon/common.h"
  822. X#include "libcommon/transform.h"
  823. X#include "bounds.h"
  824. X * Constants for enter flag in HitNode.
  825. X#define EXITING        1
  826. X#define ENTERING    2
  827. X#define MAXMODELDEPTH    128        /* Maximum height of DAG. */
  828. Xtypedef char * GeomRef;
  829. Xtypedef GeomRef GeomCreateFunc();
  830. X * If the object has a normal method, it's a primitive
  831. X * otherwise it's an aggregate (or an instance)
  832. X#define IsAggregate(o)        ((o)->methods->normal == NULL)
  833. X * Geom methods.
  834. X * (p) means applies only to primitive objects
  835. X * (a) means applies only to aggregate objects
  836. Xtypedef struct Methods {
  837. X    char        *(*name)();        /* Geom name */
  838. X    GeomRef        (*create)();        /* Create and return ref */
  839. X    int        (*intersect)(),        /* Ray/obj intersection */
  840. X            (*normal)(),        /* Geom normal (p) */
  841. X            (*enter)(),        /* Ray enter or exit? (p) */
  842. X            (*convert)();        /* Convert from list (a) */
  843. X    void        (*uv)(),        /* 2D mapping (p) */
  844. X            (*stats)(),        /* Statistics */
  845. X            (*bounds)(),        /* Bounding volume */
  846. X            (*user)();        /* User-defined method */
  847. X    struct Methods    *(*methods)();        /* object methods func. */
  848. X    char        checkbounds,        /* check bbox before int.? */
  849. X            closed;            /* properly closed? */
  850. X} Methods;
  851. Xtypedef void (*UserMethodType)();
  852. X * Geom definition
  853. Xtypedef struct Geom {
  854. X    char *name;            /* Geom name, if any. */
  855. X    GeomRef obj;            /* Pointer to object info. */
  856. X    Methods *methods;
  857. X    unsigned long prims;        /* sum of # primitive objects */
  858. X    Float bounds[2][3];        /* Bounding box */
  859. X    Float timenow;            /* Geom's idea of what time it is */
  860. X    short int animtrans;        /* transformation is animated */
  861. X    short int frame;        /* frame for which obj is inited */
  862. X    struct Surface *surf;        /* surface, if any */
  863. X    struct Trans *trans;        /* Transformation information */
  864. X    struct Trans *transtail;    /* Double linked list end */
  865. X    struct Texture *texture;    /* Texture mapping info. */
  866. X#ifdef SHAREDMEM
  867. X    unsigned long *counter;        /* Geoms are shared, counters aren't */
  868. X#else
  869. X    unsigned long counter;        /* "mailbox" for grid intersection */
  870. X#endif
  871. X    struct Geom *next;        /* Next object. */
  872. X} Geom;
  873. X * Linked list of pointers to objects.
  874. Xtypedef struct GeomList {
  875. X    Geom *obj;
  876. X    struct GeomList *next;
  877. X} GeomList;
  878. X * Array of hit information.  Stores a path through an object DAG,
  879. X * as well as the ray in 'model' (object) space and the distance from
  880. X * the ray origin to the point of intersection.
  881. Xtypedef struct HitNode {
  882. X    Geom *obj;            /* Geom hit */
  883. X    Ray    ray;            /* Ray */
  884. X    Float    mindist;        /* Amount of ray to ignore */
  885. X    Float    dist;            /* Distance from ray origin to hit */
  886. X    short    enter,            /* Enter (TRUE) or Leave (FALSE) obj */
  887. X        dotrans;        /* transformations non-identity? */
  888. X    Trans    trans;            /* parent-->obj and inverse trans */
  889. X} HitNode;
  890. X * Structure holding a list of HitNodes.  A maximum of MAXMODELDEPTH
  891. X * nodes can be referenced.
  892. Xtypedef struct HitList {
  893. X    int nodes;
  894. X    HitNode data[MAXMODELDEPTH];
  895. X} HitList;
  896. Xextern char    *GeomName();
  897. Xextern Geom    *GeomCreate(), *GeomCopy(), *GeomCopyNamed(),
  898. X        *GeomComputeAggregateBounds();
  899. Xextern GeomList    *GeomStackPush(), *GeomStackPop();
  900. Xextern void     PrimUV(), AggregatePrintInfo(),
  901. X        IntersectStats();
  902. Xextern int    AggregateConvert(), PrimNormal(),
  903. X        TraceRay();    /* application-provided */
  904. Xextern Methods    *MethodsCreate();
  905. X#endif /* OBJECT_H */
  906. END_OF_FILE
  907. if test 3949 -ne `wc -c <'libray/libobj/geom.h'`; then
  908.     echo shar: \"'libray/libobj/geom.h'\" unpacked with wrong size!
  909. # end of 'libray/libobj/geom.h'
  910. if test -f 'libray/libobj/intersect.c' -a "${1}" != "-c" ; then 
  911.   echo shar: Will not clobber existing file \"'libray/libobj/intersect.c'\"
  912. echo shar: Extracting \"'libray/libobj/intersect.c'\" \(3980 characters\)
  913. sed "s/^X//" >'libray/libobj/intersect.c' <<'END_OF_FILE'
  914. X * intersect.c
  915. X * Copyright (C) 1989, 1991, Craig E. Kolb
  916. X * All rights reserved.
  917. X * This software may be freely copied, modified, and redistributed
  918. X * provided that this copyright notice is preserved on all copies.
  919. X * You may not distribute this software, in whole or in part, as part of
  920. X * any commercial product without the express consent of the authors.
  921. X * There is no warranty or other guarantee of fitness of this software
  922. X * for any purpose.  It is provided solely "as is".
  923. X * $Id: intersect.c,v 4.0 91/07/17 14:38:37 kolb Exp Locker: kolb $
  924. X * $Log:    intersect.c,v $
  925. X * Revision 4.0  91/07/17  14:38:37  kolb
  926. X * Initial version.
  927. X#include "geom.h"
  928. Xstatic void AddToHitList();
  929. X * Number of bounding volume tests.
  930. X * External modules have read access via IntersectStats().
  931. Xstatic unsigned long BVTests;
  932. X * Intersect object & ray.  Return distance from "pos" along "ray" to
  933. X * intersection point.  Return value <= 0 indicates no intersection.
  934. Xintersect(obj, ray, hitlist, mindist, maxdist)
  935. XGeom *obj;                /* Geom to be tested. */
  936. XRay *ray;                /* Ray origin, direction. */
  937. XHitList *hitlist;            /* Intersection path */
  938. XFloat mindist, *maxdist;
  939. X    Ray newray;
  940. X    Vector vtmp;
  941. X    Trans *curtrans;    
  942. X    Float distfact, nmindist, nmaxdist;
  943. X     * Check ray/bounding volume intersection, if required.
  944. X     */
  945. X    if (obj->methods->checkbounds) {
  946. X        VecAddScaled(ray->pos, mindist, ray->dir, &vtmp);
  947. X        if (OutOfBounds(&vtmp, obj->bounds)) {
  948. X            nmaxdist = *maxdist;
  949. X            BVTests++;
  950. X            if (!BoundsIntersect(ray, obj->bounds, mindist,
  951. X                            &nmaxdist))
  952. X                return FALSE;
  953. X    newray = *ray;
  954. X    nmindist = mindist;
  955. X    nmaxdist = *maxdist;
  956. X     * Transform the ray if necessary.
  957. X     */
  958. X    if (obj->trans != (Trans *)0) {
  959. X        /*
  960. X         * If object's idea of the current time is wrong,
  961. X         * update the transformations.
  962. X         */
  963. X        if (obj->animtrans && !equal(obj->timenow, ray->time)) {
  964. X            TransResolveAssoc(obj->trans);
  965. X                
  966. X        /*
  967. X         * Transforming the ray can change the distance between
  968. X         * the ray origin and the point of intersection.
  969. X         * We save the amount the ray is "stretched" and later
  970. X         * divide the computed distance by this amount.
  971. X         */
  972. X        distfact = 1.;
  973. X        for (curtrans = obj->transtail; curtrans; 
  974. X             curtrans = curtrans->prev)
  975. X            distfact *= RayTransform(&newray, &curtrans->itrans);
  976. X        nmindist *= distfact;
  977. X        nmaxdist *= distfact;
  978. X     * Geom has been updated to current time.
  979. X     */
  980. X    obj->timenow = ray->time;
  981. X     * Call correct intersection routine.
  982. X     */
  983. X    if (IsAggregate(obj)) {
  984. X        /*
  985. X         * Aggregate
  986. X         */
  987. X        if (!(*obj->methods->intersect)
  988. X             (obj->obj, &newray, hitlist, nmindist, &nmaxdist))
  989. X        return FALSE;
  990. X    } else {
  991. X        /*
  992. X         * Primitive
  993. X         */
  994. X        if (!(*obj->methods->intersect)
  995. X              (obj->obj, &newray, nmindist, &nmaxdist))
  996. X            return FALSE;
  997. X        hitlist->nodes = 0;
  998. X     * Had a hit -- add ray, distance and object to tail of hitlist.
  999. X     */
  1000. X    AddToHitList(hitlist, &newray, nmindist, nmaxdist, obj);
  1001. X     * Set dist to distance to intersection point from the origin
  1002. X     * of the untransformed ray.
  1003. X     */
  1004. X    if (obj->trans != (Trans *)0)
  1005. X        *maxdist = nmaxdist / distfact;
  1006. X    else
  1007. X        *maxdist = nmaxdist;
  1008. X    return TRUE;
  1009. Xstatic void
  1010. XAddToHitList(hitlist, ray, mind, dist, obj)
  1011. XHitList *hitlist;
  1012. XRay *ray;
  1013. XFloat mind, dist;
  1014. XGeom *obj;
  1015. X    HitNode *np;
  1016. X    Trans *list;
  1017. X    np = &hitlist->data[hitlist->nodes++];
  1018. X    np->ray = *ray;
  1019. X    np->obj = obj;
  1020. X    np->mindist = mind;
  1021. X    np->dist = dist;
  1022. X    np->enter = 0;
  1023. X    if (obj->trans) {
  1024. X        /*
  1025. X         * Compute total transformation, forward and inverse,
  1026. X         * for this object, and store in hitlist for use later.
  1027. X         */
  1028. X        TransCopy(obj->trans, &np->trans);
  1029. X        for (list = obj->trans->next; list; list = list->next)
  1030. X            TransCompose(&np->trans, list, &np->trans);
  1031. X        np->dotrans = TRUE;
  1032. X    } else
  1033. X        np->dotrans = FALSE;
  1034. X * Return intersection statistics.
  1035. X * Currently, this is limited to the # of bounding volume test performed.
  1036. Xvoid
  1037. XIntersectStats(bvtests)
  1038. Xunsigned long *bvtests;
  1039. X    *bvtests = BVTests;
  1040. END_OF_FILE
  1041. if test 3980 -ne `wc -c <'libray/libobj/intersect.c'`; then
  1042.     echo shar: \"'libray/libobj/intersect.c'\" unpacked with wrong size!
  1043. # end of 'libray/libobj/intersect.c'
  1044. if test -f 'libray/libsurf/surface.c' -a "${1}" != "-c" ; then 
  1045.   echo shar: Will not clobber existing file \"'libray/libsurf/surface.c'\"
  1046. echo shar: Extracting \"'libray/libsurf/surface.c'\" \(3304 characters\)
  1047. sed "s/^X//" >'libray/libsurf/surface.c' <<'END_OF_FILE'
  1048. X * surface.c
  1049. X * Copyright (C) 1989, 1991, Craig E. Kolb
  1050. X * All rights reserved.
  1051. X * This software may be freely copied, modified, and redistributed
  1052. X * provided that this copyright notice is preserved on all copies.
  1053. X * You may not distribute this software, in whole or in part, as part of
  1054. X * any commercial product without the express consent of the authors.
  1055. X * There is no warranty or other guarantee of fitness of this software
  1056. X * for any purpose.  It is provided solely "as is".
  1057. X * $Id: surface.c,v 4.0 91/07/17 14:40:55 kolb Exp Locker: kolb $
  1058. X * $Log:    surface.c,v $
  1059. X * Revision 4.0  91/07/17  14:40:55  kolb
  1060. X * Initial version.
  1061. X#include "atmosphere.h"
  1062. X#include "surface.h"
  1063. X#define blend(a, b, p, q)    (a * p + b * q)
  1064. XColor    Black = {0., 0., 0.},
  1065. X    White = {1., 1., 1.};
  1066. X * Create and return pointer to surface with given properties.
  1067. XSurface *
  1068. XSurfaceCreate()
  1069. X    Surface *stmp;
  1070. X    stmp = (Surface *)Malloc(sizeof(Surface));
  1071. X    stmp->amb = stmp->diff = stmp->spec =
  1072. X        stmp->translu = Black;
  1073. X    stmp->body = White;
  1074. X    stmp->srexp = stmp->stexp = DEFAULT_PHONGPOW;
  1075. X    stmp->statten = 1.;    /* No attenuation by default */
  1076. X    stmp->reflect = stmp->transp = 0.;
  1077. X    stmp->noshadow = FALSE;
  1078. X    stmp->index = DEFAULT_INDEX;
  1079. X    stmp->name = (char *)NULL;
  1080. X    stmp->next = (Surface *)NULL;
  1081. X    return stmp;
  1082. XSurface *
  1083. XSurfaceCopy(surf)
  1084. XSurface *surf;
  1085. X    Surface *res;
  1086. X    if (!surf)
  1087. X        return (Surface *)NULL;
  1088. X    res = SurfaceCreate();
  1089. X    *res = *surf;
  1090. X    res->next = (Surface *)NULL;
  1091. X    res->name = (char *)NULL;
  1092. X    return res;
  1093. X * Compute combination of two surfaces. Resulting surface is copied into surf1.
  1094. Xvoid
  1095. XSurfaceBlend(surf1, surf2, p, q)
  1096. XSurface *surf1, *surf2;
  1097. XFloat p, q;
  1098. X      * P is weight of surf1.  q is weight of surf2.
  1099. X     * Result is placed in surf1.
  1100. X     */
  1101. X    if (q < EPSILON)
  1102. X        return;    /* keep surf1 as-is */
  1103. X    ColorBlend(&surf1->amb, &surf2->amb, p, q);
  1104. X    ColorBlend(&surf1->diff, &surf2->diff, p, q);
  1105. X    ColorBlend(&surf1->spec, &surf2->spec, p, q);
  1106. X    ColorBlend(&surf1->translu, &surf2->translu, p, q);
  1107. X    ColorBlend(&surf1->body, &surf2->body, p, q);
  1108. X    surf1->srexp = blend(surf1->srexp, surf2->srexp, p, q);
  1109. X    surf1->stexp = blend(surf1->stexp, surf2->stexp, p, q);
  1110. X    surf1->reflect = blend(surf1->reflect, surf2->reflect, p, q);
  1111. X    surf1->transp  = blend(surf1->transp,  surf2->transp,  p, q);
  1112. X    surf1->translucency = blend(surf1->translucency, surf2->translucency,
  1113. X            p, q);
  1114. X     * Questionable...
  1115. X     */
  1116. X    surf1->statten = blend(surf1->statten, surf2->statten, p, q);
  1117. X    surf1->index = blend(surf1->index, surf2->index, p, q);
  1118. X    if (p < EPSILON) {
  1119. X        surf1->noshadow = surf2->noshadow;
  1120. X    } else {
  1121. X        /* else there's a blend of some kind... */
  1122. X        surf1->noshadow = (surf1->noshadow && surf2->noshadow);
  1123. X * Blend two colors.  Result is placed in color1.
  1124. Xvoid
  1125. XColorBlend(color1, color2, p, q)
  1126. XColor *color1, *color2;
  1127. XFloat p, q;
  1128. X    color1->r = blend(color1->r, color2->r, p, q);
  1129. X    color1->g = blend(color1->g, color2->g, p, q);
  1130. X    color1->b = blend(color1->b, color2->b, p, q);
  1131. XSurfList *
  1132. XSurfPop(list)
  1133. XSurfList *list;
  1134. X    SurfList *stmp = list->next;
  1135. X    free((voidstar)list);
  1136. X    return stmp;
  1137. XSurfList *
  1138. XSurfPush(surf, list)
  1139. XSurface *surf;
  1140. XSurfList *list;
  1141. X    SurfList *stmp;
  1142. X    stmp = (SurfList *)Malloc(sizeof(SurfList));
  1143. X    stmp->surf = surf;
  1144. X    stmp->next = list;
  1145. X    return stmp;
  1146. END_OF_FILE
  1147. if test 3304 -ne `wc -c <'libray/libsurf/surface.c'`; then
  1148.     echo shar: \"'libray/libsurf/surface.c'\" unpacked with wrong size!
  1149. # end of 'libray/libsurf/surface.c'
  1150. if test -f 'libshade/lightdef.c' -a "${1}" != "-c" ; then 
  1151.   echo shar: Will not clobber existing file \"'libshade/lightdef.c'\"
  1152. echo shar: Extracting \"'libshade/lightdef.c'\" \(3547 characters\)
  1153. sed "s/^X//" >'libshade/lightdef.c' <<'END_OF_FILE'
  1154. X * lightdef.c
  1155. X * Copyright (C) 1989, 1991, Craig E. Kolb
  1156. X * All rights reserved.
  1157. X * This software may be freely copied, modified, and redistributed
  1158. X * provided that this copyright notice is preserved on all copies.
  1159. X * You may not distribute this software, in whole or in part, as part of
  1160. X * any commercial product without the express consent of the authors.
  1161. X * There is no warranty or other guarantee of fitness of this software
  1162. X * for any purpose.  It is provided solely "as is".
  1163. X * $Id: lightdef.c,v 4.0 91/07/17 14:46:25 kolb Exp Locker: kolb $
  1164. X * $Log:    lightdef.c,v $
  1165. X * Revision 4.0  91/07/17  14:46:25  kolb
  1166. X * Initial version.
  1167. X#include "rayshade.h"
  1168. X#include "options.h"
  1169. X#include "liblight/light.h"
  1170. X#include "liblight/infinite.h"    /* to create default infinite light */
  1171. X#include "liblight/jittered.h"    /* to create jittered light sources */
  1172. XLight *Lights = NULL;        /* Linked list of defined lights */
  1173. Xvoid
  1174. XLightAddToDefined(light)
  1175. XLight *light;
  1176. X    if (light) {
  1177. X        light->next = Lights;
  1178. X        Lights = light;
  1179. Xvoid
  1180. XLightSetup()
  1181. X    long shadowopts;
  1182. X    Light *ltmp;
  1183. X     * Set shadowing options.
  1184. X     */
  1185. X    shadowopts = 0;
  1186. X    if (Options.no_shadows)
  1187. X        shadowopts |= SHADOW_NONE;
  1188. X    if (Options.shadowtransp)
  1189. X        shadowopts |= SHADOW_TRANSP;
  1190. X    if (Options.csg)
  1191. X        shadowopts |= SHADOW_CSG;
  1192. X    if (Options.cache)
  1193. X        shadowopts |= SHADOW_CACHE;
  1194. X    if (Options.shutterspeed > 0.)
  1195. X        shadowopts |= SHADOW_BLUR;
  1196. X    ShadowSetOptions(shadowopts);
  1197. X     * If no light sources were defined, add a default.
  1198. X     */
  1199. X    if (Lights == (Light *)NULL) {
  1200. X        Color ctmp;
  1201. X        Vector vtmp;
  1202. X        vtmp.x = vtmp.z = 1.;
  1203. X        vtmp.y = -1;
  1204. X        ctmp.r = ctmp.g = ctmp.b = 1.;
  1205. X        LightAddToDefined(LightInfiniteCreate(&ctmp, &vtmp));
  1206. X     * Now that we've parsed the input file, we know what
  1207. X     * maxlevel is, and we can allocate the correct amount of
  1208. X     * space for each light source's cache.
  1209. X     */
  1210. X    for (ltmp = Lights; ltmp; ltmp = ltmp->next) {
  1211. X        ltmp->cache = (ShadowCache *)Calloc(
  1212. X            (unsigned)Options.maxdepth + 1, sizeof(ShadowCache));
  1213. Xvoid
  1214. XAreaLightCreate(color, corner, u, usamp, v, vsamp, shadow)
  1215. XColor *color;
  1216. XVector *corner, *u, *v;
  1217. Xint usamp, vsamp, shadow;
  1218. X    Vector vpos, curpos;
  1219. X    int i, j, numlight;
  1220. X    Float ulen, vlen;
  1221. X    Color intens;
  1222. X    Light *ltmp;
  1223. X    if (usamp < 1 || vsamp < 1)
  1224. X        RLerror(RL_ABORT, "Invalid area light specification.\n");
  1225. X    numlight = usamp * vsamp;    /* Total number of jittered sources */
  1226. X     * Sum of all intensities is equal to specified intensity.
  1227. X     */
  1228. X    intens.r = color->r / (Float)numlight;
  1229. X    intens.g = color->g / (Float)numlight;
  1230. X    intens.b = color->b / (Float)numlight;
  1231. X    VecSub(*u, *corner, u);
  1232. X    VecSub(*v, *corner, v);
  1233. X     * Make sure that u and v are not degenerate.
  1234. X     */
  1235. X    ulen = VecNormalize(u);
  1236. X    vlen = VecNormalize(v);
  1237. X    if (ulen < EPSILON || vlen < EPSILON)
  1238. X        RLerror(RL_ABORT, "Degenerate area light source.\n");
  1239. X     * Scale u and v such that they define the area covered by a
  1240. X     * single sample.
  1241. X     */
  1242. X    VecScale(ulen / (Float)usamp, *u, u); 
  1243. X    VecScale(vlen / (Float)vsamp, *v, v);
  1244. X     * For each sample...
  1245. X     */
  1246. X    vpos = *corner;
  1247. X    for (i = 0; i < vsamp; i++) {
  1248. X        curpos = vpos;
  1249. X        for (j = 0; j < usamp; j++) {
  1250. X            /*
  1251. X             * current pos is the "corner" of a new light
  1252. X             * source.  A jittered position based on
  1253. X             * the "corner" and the two edge vectors
  1254. X             * is used as the position for the
  1255. X             * light source in lighting calculations.
  1256. X             */
  1257. X            ltmp = LightJitteredCreate(&intens, &curpos, u, v);
  1258. X            ltmp->shadow = shadow;
  1259. X            LightAddToDefined(ltmp);
  1260. X            VecAdd(curpos, *u, &curpos);
  1261. X        VecAdd(vpos, *v, &vpos);
  1262. END_OF_FILE
  1263. if test 3547 -ne `wc -c <'libshade/lightdef.c'`; then
  1264.     echo shar: \"'libshade/lightdef.c'\" unpacked with wrong size!
  1265. # end of 'libshade/lightdef.c'
  1266. if test -f 'libshade/options.h' -a "${1}" != "-c" ; then 
  1267.   echo shar: Will not clobber existing file \"'libshade/options.h'\"
  1268. echo shar: Extracting \"'libshade/options.h'\" \(3167 characters\)
  1269. sed "s/^X//" >'libshade/options.h' <<'END_OF_FILE'
  1270. X * options.h
  1271. X * Copyright (C) 1989, 1991, Craig E. Kolb
  1272. X * All rights reserved.
  1273. X * This software may be freely copied, modified, and redistributed
  1274. X * provided that this copyright notice is preserved on all copies.
  1275. X * You may not distribute this software, in whole or in part, as part of
  1276. X * any commercial product without the express consent of the authors.
  1277. X * There is no warranty or other guarantee of fitness of this software
  1278. X * for any purpose.  It is provided solely "as is".
  1279. X * $Id: options.h,v 4.0 91/07/17 14:46:54 kolb Exp Locker: kolb $
  1280. X * $Log:    options.h,v $
  1281. X * Revision 4.0  91/07/17  14:46:54  kolb
  1282. X * Initial version.
  1283. X#ifndef OPTIONS_H
  1284. X#define OPTIONS_H
  1285. X * Constants for Stereo mode
  1286. X#define LEFT        1
  1287. X#define RIGHT        2
  1288. X * Options
  1289. Xtypedef struct RSOptions {
  1290. X    int    stereo,            /* Stereo mode? */
  1291. X        verbose,        /* Babbling mode? */
  1292. X        quiet,            /* Don't complain? */
  1293. X        jitter,            /* use jittered sampling? */
  1294. X        samples,        /* Sqrt of # of samples */
  1295. X        maxdepth,        /* Maximum ray tree depth */
  1296. X        report_freq,        /* Frequency, in lines, of report */
  1297. X        no_shadows,        /* Trace shadow rays? */
  1298. X        shadowtransp,        /* ... through transparent objects? */
  1299. X        cache,            /* Cache shadowing info? */
  1300. X        appending,        /* Append to image file? */
  1301. X        resolution_set,        /* resolution set on command line */
  1302. X        contrast_set,        /* contrast overridden ... */
  1303. X        samples_set,        /* samples overridden ... */
  1304. X        cutoff_set,        /* cutoff ... */
  1305. X        maxdepth_set,        /* adaptive depth ... */
  1306. X        window_set,        /* window ... */
  1307. X        freq_set,        /* report frequency ... */
  1308. X        jitter_set,        /* use jittering */
  1309. X        eyesep_set,        /* eye separation ... */
  1310. X        csg,            /* CSG object someplace in world */
  1311. X        flipnorm,        /* flip normals of polygonal objs */
  1312. X        samplemap,        /* output sample map? */
  1313. X        gaussian,        /* Use gaussian pixel filter? */
  1314. X        framenum,        /* current frame number */
  1315. X        startframe,        /* Starting frame number. */
  1316. X        endframe,        /* ending frame number */
  1317. X        totalframes,        /* total # of frames */
  1318. X        totalframes_set;    /* set on command line? */
  1319. X#ifdef URT
  1320. X    int    alpha;            /* Write alpha channel? */
  1321. X    int    exp_output;        /* Write exponential RLE file? */
  1322. X#endif
  1323. X    Float    eyesep,            /* Eye separation (for Stereo mode) */
  1324. X        gamma,            /* Gamma value (0 == no correction) */
  1325. X        xmin, xmax, ymin, ymax, /* Window range */
  1326. X        starttime,        /* Think about it ... */
  1327. X        shutterspeed,        /* time shutter is open */
  1328. X        framestart,        /* start time of the current frame */
  1329. X        framelength,        /* length of the current frame */
  1330. X        filterwidth;        /* Pixel filter width. */
  1331. X    Color    contrast,        /* Max. allowable contrast */
  1332. X        cutoff,            /* Ray tree depth control */
  1333. X        ambient;        /* Ambient light multiplier */
  1334. X    char    *progname,        /* argv[0] */
  1335. X        *statsname,        /* Name of stats file. */
  1336. X        *imgname,        /* Name of output image file */
  1337. X        *inputname,        /* Name of input file, NULL == stdin */
  1338. X        *cppargs;        /* arguments to pass to cpp */
  1339. X#ifdef LINDA
  1340. X    int    workers,        /* # of worker processes */
  1341. X        workernum,        /* worker #, 0 == supervisor */
  1342. X        verbose_worker;        /* Babble while you work? */
  1343. X#endif
  1344. X    FILE    *pictfile;        /* output file pointer */
  1345. X} RSOptions;
  1346. Xextern RSOptions Options;
  1347. Xextern void OptionsList(), OptionsSet();
  1348. X#endif /* OPTIONS_H */
  1349. END_OF_FILE
  1350. if test 3167 -ne `wc -c <'libshade/options.h'`; then
  1351.     echo shar: \"'libshade/options.h'\" unpacked with wrong size!
  1352. # end of 'libshade/options.h'
  1353. if test -f 'libshade/symtab.c' -a "${1}" != "-c" ; then 
  1354.   echo shar: Will not clobber existing file \"'libshade/symtab.c'\"
  1355. echo shar: Extracting \"'libshade/symtab.c'\" \(3608 characters\)
  1356. sed "s/^X//" >'libshade/symtab.c' <<'END_OF_FILE'
  1357. X * symtab.c
  1358. X * Copyright (C) 1989, 1991, Craig E. Kolb, Rod G. Bogart
  1359. X * All rights reserved.
  1360. X * This software may be freely copied, modified, and redistributed
  1361. X * provided that this copyright notice is preserved on all copies.
  1362. X * You may not distribute this software, in whole or in part, as part of
  1363. X * any commercial product without the express consent of the authors.
  1364. X * There is no warranty or other guarantee of fitness of this software
  1365. X * for any purpose.  It is provided solely "as is".
  1366. X * $Id: symtab.c,v 4.0 91/07/17 14:48:02 kolb Exp Locker: kolb $
  1367. X * $Log:    symtab.c,v $
  1368. X * Revision 4.0  91/07/17  14:48:02  kolb
  1369. X * Initial version.
  1370. X#include "rayshade.h"
  1371. X#include "symtab.h"
  1372. X#include "builtin.h"
  1373. Xstatic struct SymtabPredefinedEntry SymtabPredefined[] = {
  1374. X    {"pi", 3.141592, NULL, FLOAT_EXPR, FALSE, 0},
  1375. X    {"dtor", 0.017453, NULL, FLOAT_EXPR, FALSE, 0},
  1376. X    {"rtod", 57.29578, NULL, FLOAT_EXPR, FALSE, 0},
  1377. X    {"cos", 0.0, cos, BUILTIN_EXPR, FALSE, 1},
  1378. X    {"sin", 0.0, sin, BUILTIN_EXPR, FALSE, 1},
  1379. X    {"tan", 0.0, tan, BUILTIN_EXPR, FALSE, 1},
  1380. X    {"sqrt", 0.0, sqrt, BUILTIN_EXPR, FALSE, 1},
  1381. X    {"acos", 0.0, acos, BUILTIN_EXPR, FALSE, 1},
  1382. X    {"asin", 0.0, asin, BUILTIN_EXPR, FALSE, 1},
  1383. X    {"atan", 0.0, atan, BUILTIN_EXPR, FALSE, 1},
  1384. X    {"hypot", 0.0, hypot, BUILTIN_EXPR, FALSE, 2},
  1385. X    {"time", 0.0, NULL, FLOAT_EXPR, TRUE, 0},
  1386. X    {"frame", 0.0, NULL, FLOAT_EXPR, TRUE, 0},
  1387. X    {"linear", 0.0, LinearTime, BUILTIN_EXPR, TRUE, 4},
  1388. X    {NULL, 0.0, NULL, 0, 0}
  1389. XSymtabEntry *Symtab = (SymtabEntry *) NULL;
  1390. Xvoid SymtabAddEntry();
  1391. Xvoid
  1392. XSymtabInit()
  1393. X    int i;
  1394. X    for(i=0; SymtabPredefined[i].name; i++) {
  1395. X        if (SymtabPredefined[i].type == BUILTIN_EXPR)
  1396. X            SymtabAddEntry(SymtabPredefined[i].name,
  1397. X                       SymtabPredefined[i].type,
  1398. X                       NULL,
  1399. X                       SymtabPredefined[i].fp,
  1400. X                    SymtabPredefined[i].timevary,    
  1401. X                       SymtabPredefined[i].params);
  1402. X        else
  1403. X            SymtabAddEntry(SymtabPredefined[i].name,
  1404. X                       SymtabPredefined[i].type,
  1405. X                       ExprFloatCreate(SymtabPredefined[i].f,
  1406. X                        SymtabPredefined[i].timevary),
  1407. X                       NULL, SymtabPredefined[i].timevary, 0);
  1408. X    TimeExpr = ExprFloatSymtabFind("time");
  1409. X    FrameExpr = ExprFloatSymtabFind("frame");
  1410. Xvoid
  1411. XSymtabAddEntry(name, type, expr, fp, timevary, params)
  1412. Xchar *name;
  1413. XExpr *expr;
  1414. XFloat (*fp)();
  1415. Xint type, timevary, params;
  1416. X    SymtabEntry *res;
  1417. X    if (SymtabFind(name) != (SymtabEntry *)NULL)
  1418. X        RLerror(RL_ABORT, "Symbol %s redefined.\n", name);
  1419. X    res = (SymtabEntry *) Malloc( sizeof(SymtabEntry));
  1420. X    res->name = strsave(name);
  1421. X    res->type = type;
  1422. X    res->timevary = timevary;
  1423. X    switch (type) {
  1424. X    case FLOAT_EXPR:
  1425. X        res->value.expr = expr;
  1426. X        expr->symtab = TRUE;
  1427. X        break;
  1428. X    case BUILTIN_EXPR:
  1429. X        res->value.fp = fp;
  1430. X        break;
  1431. X    default:
  1432. X        RLerror(RL_WARN,
  1433. X            "Type %d not implemented!!!",type);
  1434. X    res->params = params;
  1435. X    res->next = Symtab;
  1436. X    Symtab = res;
  1437. XSymtabEntry *
  1438. XSymtabFind(name)
  1439. Xchar *name;
  1440. X    SymtabEntry *res;
  1441. X    for(res=Symtab; res; res=res->next) {
  1442. X        if (!strcmp(res->name,name))
  1443. X            return res;
  1444. X    /*error*/
  1445. X    return NULL;
  1446. XExpr *
  1447. XExprFloatSymtabFind(name)
  1448. Xchar *name;
  1449. X    SymtabEntry *res;
  1450. X    if ((res = SymtabFind(name)) == NULL) 
  1451. X        RLerror(RL_PANIC,
  1452. X            "Symbol %s not defined!\n", name);
  1453. X    if (res->type != FLOAT_EXPR)
  1454. X        RLerror(RL_PANIC,
  1455. X            "Symbol %s is not a float expression!\n", name);
  1456. X    return res->value.expr;
  1457. XSymtabEntry *
  1458. XSymtabBuiltinFind(name)
  1459. Xchar *name;
  1460. X    SymtabEntry *res;
  1461. X    if ((res = SymtabFind(name)) == NULL) 
  1462. X        RLerror(RL_PANIC,
  1463. X            "Symbol %s not defined!\n", name);
  1464. X    if (res->type != BUILTIN_EXPR)
  1465. X        RLerror(RL_PANIC,
  1466. X            "Symbol %s is not a built in function!\n", name);
  1467. X    return res;
  1468. END_OF_FILE
  1469. if test 3608 -ne `wc -c <'libshade/symtab.c'`; then
  1470.     echo shar: \"'libshade/symtab.c'\" unpacked with wrong size!
  1471. # end of 'libshade/symtab.c'
  1472. echo shar: End of archive 7 \(of 19\).
  1473. cp /dev/null ark7isdone
  1474. MISSING=""
  1475. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  1476.     if test ! -f ark${I}isdone ; then
  1477.     MISSING="${MISSING} ${I}"
  1478.     fi
  1479. if test "${MISSING}" = "" ; then
  1480.     echo You have unpacked all 19 archives.
  1481.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1482.     echo You still need to unpack the following archives:
  1483.     echo "        " ${MISSING}
  1484. ##  End of shell archive.
  1485. exit 0
  1486. exit 0 # Just in case...
  1487.