home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume21
/
rayshade
/
part07
(
.txt
)
< prev
next >
Wrap
LaTeX Document
|
1991-07-21
|
55KB
|
1,487 lines
Newsgroups: comp.sources.misc
From: Rayshade Construction Co. <rayshade@weedeater.math.YALE.EDU>
Subject: v21i010: rayshade - A raytracing package for UNIX, Part07/19
Message-ID: <1991Jul20.043518.11539@sparky.IMD.Sterling.COM>
X-Md4-Signature: 891ba98c5797ca603465455588656d8b
Date: Sat, 20 Jul 1991 04:35:18 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Rayshade Construction Co. <rayshade@weedeater.math.YALE.EDU>
Posting-number: Volume 21, Issue 10
Archive-name: rayshade/part07
Environment: UNIX, !16BIT
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 7 (of 19)."
# Contents: Doc/Guide/preface.tex Examples/pool.ray etc/nff2shade.awk
# libray/libcommon/sampling.c libray/libcommon/vecmath.c
# libray/liblight/spot.c libray/libobj/box.c libray/libobj/geom.h
# libray/libobj/intersect.c libray/libsurf/surface.c
# libshade/lightdef.c libshade/options.h libshade/symtab.c
# Wrapped by kolb@woody on Wed Jul 17 17:56:46 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Doc/Guide/preface.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Doc/Guide/preface.tex'\"
echo shar: Extracting \"'Doc/Guide/preface.tex'\" \(3168 characters\)
sed "s/^X//" >'Doc/Guide/preface.tex' <<'END_OF_FILE'
X\chapter*{Preface}
X\addcontentsline{toc}{chapter}{Preface}
X{\em Rayshade} is a program for creating ray-traced images.
XIt reads a description of a scene to be
Xrendered and produces a color image corresponding to the
Xdescription.
X{\em Rayshade} was designed to make it easy to
Xcreate nice pictures.
XIt was also meant to be flexible, easy to modify,
Xand relatively fast.
XThe first version of \rayshade was written in 1987-1998 at
XPrinceton University with help and encouragement from David Dobkin
Xand David Hoffman. That version was heavily based on a public-domain
X``introductory'' ray tracer written by Roman Kuchkuda.
XChanges to \rayshade from that point until version 4.0 were
Xevolutionary in nature.
XThe current version is to a large extent a re-write,
Xand an attempt has been made to remove some of the fundamental
Xproblems present in previous incarnations.
XI wish to thank the many people who have made
Xcontributions to the development of {\em rayshade} during the past four years.
XThanks to Marc Andreessen, Ray Bellis, Dominique Boisvert, William Bouma,
XAllen Braunsdorf, Jeff Butterworth, Nick Carriero, Nancy Everson, Tom Friedel,
XRobert Funchess, David Gelernter, Mike Gigante, Ed Herderick, John Knuston,
XRaphael Manfredi, Lee Moore, Dietmar Saupe, Brian Wyvill,
Xand everybody else for their bug-fixes, suggestions, input files,
Xencouragement, support, and other feedback.
XDavid Dobkin first suggested that an extensible
Xray tracer would be a worthwhile project. Gavin Bell, David
XHoffman, Lefteris Koutsofios, and Steven North
Xwere the first users of the original \rayshade, and their feedback
Xshowed that the project might indeed have a future.
XIn the Fall of 1988,
XPrzemyslaw Prusinkiewicz encouraged me
Xto develop \rayshade further, and was, as always, full of ``insanely
Xgreat'' ideas. The resulting version of \rayshade was released
Xon UseNet in 1989. Allan Snider was particularly helpful in
Xfinding bugs in version 3.0 and in making valuable suggestions
Xas to how the program might be improved.
X{\em Rashade} version 4.0
Xwas written by Craig Kolb and Rod Bogart during 1990-1991, with contributions
Xof ideas and code made by many others.
XPat Hanrahan's {\em OOGL} provided the spirit, if not the letter, of the
Xmodularity of the version 4.0. Thanks to Pat and to Mark VandeWettering
Xfor the ``net tracer'' conversations and for the inspiration to do something
Xto clean up {\em rayshade}.
XEric Haines saved the day on more than one occasion by suggesting
Ximprovements, finding bugs, and saying nice things about \rayshade
Xwhen I was all but ready to throw in the towel.
XRobert Skinner was kind enough to provide the {\em Noise()}, {\em DNoise()},
Xand other texturing functions and to allow them to be redistributed.
XMark Podlipec provided the blob object and torus object, which uses
XJochen Schwarze's cubic and quartic root-finding functions.
XMajor Thanks to Rod Bogart for being willing to take the plunge and
Xplay such a large role in the development of version 4.0.
XI am most grateful to Benoit Mandelbrot for his
Xcontinued support and inspiration.
X\begin{flushright}
X\parbox[t]{1.5in}{
XC. Kolb \\
XFebruary 13, 1991
X\end{flushright}
END_OF_FILE
if test 3168 -ne `wc -c <'Doc/Guide/preface.tex'`; then
echo shar: \"'Doc/Guide/preface.tex'\" unpacked with wrong size!
# end of 'Doc/Guide/preface.tex'
if test -f 'Examples/pool.ray' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Examples/pool.ray'\"
echo shar: Extracting \"'Examples/pool.ray'\" \(3791 characters\)
sed "s/^X//" >'Examples/pool.ray' <<'END_OF_FILE'
X/* Converted by rsconvert */
X * Example rayshade input file
X * pool table from "Reds' Nightmare"
X * C. Kolb 2/88
X * $Id: pool.ray,v 4.0 91/07/17 14:26:36 kolb Exp Locker: kolb $
X * $Log: pool.ray,v $
X * Revision 4.0 91/07/17 14:26:36 kolb
X * Initial version.
Xup 0 0 1
Xfov 45
Xscreen 512 512
Xmaxdepth 2
Xbackground 0 0 0
Xlight 1.4 point 20 0 66
Xsurface blacktile
X ambient 0.01 0.01 0.01
X diffuse 0.01 0.01 0.01
Xsurface s0
X ambient 0.862745 0.862745 0.862745
X diffuse 0.039216 0.039216 0.039216
Xsurface s1
X ambient 0.470588 0.156863 0.392157
X diffuse 0.470588 0.156863 0.392157
X specular 1 1 1
Xsurface s2
X ambient 0.117647 0.117647 0.392157
X diffuse 0.117647 0.117647 0.392157
Xsurface s3
X ambient 0.784314 0.078431 0.078431
X diffuse 0.470588 0.039216 0.039216
Xsurface s4
X ambient 0 0.2235 0.145
X diffuse 0 0.2235 0.145
Xsurface mirror
X ambient 0.04 0.04 0.04
X diffuse 0.05 0.05 0.05
X specular .8 .8 .8
X specpow 60
X reflect 1.
Xsurface s5
X ambient 0.196078 0.392157 0.117647
X diffuse 0.196078 0.392157 0.117647
X specular 0.156863 0.156863 0.156863
X specpow 7
X reflect 1.
Xsurface s6
X ambient 0.588235 0.392157 0.117647
X diffuse 0.196078 0.392157 0.117647
X specular 0.156863 0.156863 0.156863
X specpow 7
X reflect 1.
Xsurface s7
X ambient 0.196078 0.392157 0.509804
X diffuse 0.196078 0.392157 0.117647
X specular 0.156863 0.156863 0.156863
X specpow 7
X reflect 1.
Xsurface s8
X ambient 0.980392 0.196078 0.117647
X diffuse 0.196078 0.392157 0.117647
X specular 0.156863 0.156863 0.156863
X specpow 7
X reflect 1.
Xsurface s9
X ambient 0.196078 0.392157 0.901961
X diffuse 0.196078 0 0.117647
X specular 0.156863 0.156863 0.156863
X specpow 7
X reflect 1.
Xsurface s10
X ambient 0.411765 0.411765 0.176471
X diffuse 0.411765 0.411765 0.176471
Xsurface floor
X ambient 0.1 0.1 0.1
X diffuse 0.5 0.5 0.45
X specular 0.8 0.8 0.8
X specpow 18
Xsurface s12
X ambient 0.313725 0.313725 0.313725
X diffuse 0.745098 0.745098 0.745098
Xsurface s13
X ambient 0.078431 0.862745 0.078431
X diffuse 0.039216 0.039216 0.039216
X specular 0.156863 0.156863 0.156863
X specpow 7
Xsurface s14
X ambient 0.784314 0.078431 0.078431
X diffuse 0.470588 0.039216 0.039216
Xsurface s15
X ambient 0.392157 0.098039 0.047059
X diffuse 0.392157 0.098039 0.047059
X specular 0.039216 0.039216 0.039216
X specpow 3
Xsurface s16
X ambient 0.509804 0.509804 0.509804
X diffuse 0.509804 0.509804 0.509804
X specular 0.156863 0.156863 0.156863
X specpow 7
X reflect 1.
Xsphere s5 1.5 0 -21 1.5
X sphere s6 1.5 1.5 -23.598 1.5
X sphere s7 1.5 -1.5 -23.598 1.5
X sphere s8 1.5 3 -26.1962 1.5
X sphere s9 1.5 0 -26.1962 1.5
X sphere s5 1.5 -3 -26.1962 1.5
X sphere s6 1.5 4.5 -28.7942 1.5
X sphere s7 1.5 1.5 -28.7942 1.5
X sphere s8 1.5 -1.5 -28.7942 1.5
X sphere s9 1.5 -4.5 -28.7942 1.5
X sphere s5 1.5 6 -31.3923 1.5
X sphere s6 1.5 3 -31.3923 1.5
X sphere s7 1.5 0 -31.3923 1.5
X sphere s8 1.5 -3 -31.3923 1.5
X sphere s9 1.5 -6 -31.3923 1.5
X box s4 -30 -57 -2 30 57 0
X box s15 27 -54 -1.5 33 54 1.5 texture wood scale 15 10 15
X box s15 -33 -54 -1.5 -27 54 1.5 texture wood scale 15 10 15
X box s15 -33 54 -1.5 33 60 1.5 texture wood scale 10 15 15
X box s15 -33 -60 -1.5 33 -54 1.5 texture wood scale 10 15 15
X sphere s16 1.5 0 0 0 translate 0 21 1.5
X box mirror -11.3333 -144.1 10 31.3333 -143.9 50 /* was 40. -144 30. */
X * Walls
X */
X plane s10 0 -144 0 0 1 0
X plane s10 -180 0 0 1 0 0
X plane s10 180 0 0 -1 0 0
X plane s10 0 144 0 0 -1 0
X * Floor
X */
X plane floor 0 0 -30 0 0 1
X texture marble scale 6 6 6 rotate 1 0 0 90
X translate 0 0 -4.376
X texture checker blacktile scale 12.3 12.3 12.3
X * Ceiling
X */
X plane s12 0 0 72 0 0 -1
Xeyep 38 100 43
Xlookp 0 0 0
END_OF_FILE
if test 3791 -ne `wc -c <'Examples/pool.ray'`; then
echo shar: \"'Examples/pool.ray'\" unpacked with wrong size!
# end of 'Examples/pool.ray'
if test -f 'etc/nff2shade.awk' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'etc/nff2shade.awk'\"
echo shar: Extracting \"'etc/nff2shade.awk'\" \(3477 characters\)
sed "s/^X//" >'etc/nff2shade.awk' <<'END_OF_FILE'
X# This awk script will convert an NFF-format input file (as output by
X# Eric Haines' SPD) to something rayshade can understand.
X# The World object will be enclosed in a single grid of 22*22*22 voxels.
X# Example usage:
X# mount | awk -f sped2shade.awk | rayshade > mountains.rle
X# For best results, one should modify the output for all but the tetra
X# and mountain databases to provide a tighter bounding box around the
X# object of interest (tree, gears, etc.). This is done by moving
X# ground polygons and the like outside of the topmost grid object.
X# This will decrease ray-tracing time dramatically.
X# Note that we have to make sure that the viewing paramters are output
X# outside of the object definition block. We do this by printing
X# the eye position, etc., at the very end of the output.
XBEGIN{
X init = 0;
X lights = 0;
X print "maxdepth 4"
X print "sample 1 nojitter"
X print "cutoff 0."
X print "report verbose"
Xsubstr($1, 1, 1) == "#" { print "/* " $0 " */"; next;}
X$1 == "v" { next;}
X$1 == "from" { eyex = $2; eyey = $3; eyez = $4; next;}
X$1 == "at" { atx = $2; aty = $3; atz = $4; next;}
X$1 == "up" { upx = $2; upy = $3; upz = $4; next;}
X$1 == "angle" { fov = $2; next;}
X$1 == "hither" {next;}
X$1 == "resolution" {screenx = $2; screeny = $3; next;}
X$1 == "l" { lightd[lights] = $2 " "$3 " "$4; lights++; next; }
X$1 == "b" {print "background " $2 " "$3 " "$4; next; }
X$1 == "f" {
X if (init == 0) {
X print "grid 22 22 22";
X init = 1;
X printf("applysurf ");
X if (lights != 0)
X aintens = sqrt(lights) / (4*lights);
X else
X aintens = .1;
X dr = $2*$5;
X dg = $3*$5;
X db = $4*$5;
X# this is a good guess....
X ar = aintens*dr;
X ag = aintens*dg;
X ab = aintens*db;
X if (ar != 0 || ag != 0 || ab != 0)
X printf("\tambient %f %f %f\n", ar, ag, ab);
X if (dr != 0 || dg != 0 || db != 0)
X printf("\tdiffuse %f %f %f\n", dr, dg, db);
X# This gets a little strange. We're given a color, Ks, and T.
X# We need a specular color, a specular reflectivity (for reflected
X# rays), and a transparency (for transmitted rays).
X# In rayshade, reflected rays have intensity proportional to
X# specular_color*reflectivity, transmitted proportaional to
X# specular_color*transparency, and specular hilights to
X# specular_color. Also, Ks + T >1 for some SPDs.
X if ($6) {
X sr = $2*$6;
X sg = $3*$6;
X sb = $4*$6;
X printf("\tspecular %f %f %f specpow %f\n", sr, sg, sb, $7);
X if ($6 < 1. - $8)
X printf("\treflect 1.0\n");
X else
X printf("\treflect %f\n", 1. - $8);
X if ($8 || $9)
X printf("\ttransp %f index %f\n", $8, $9);
X next;
X$1 == "c" {
X getline;
X x1 = $1;
X y1 = $2;
X z1 = $3;
X br = $4;
X getline;
X printf("cone %f %f %f %f %f %f %f %f\n", \
X br, x1, y1, z1, $4, $1, $2, $3);
X next;
X$1 == "s" {
X print "sphere "$5 " "$2 " "$3 " "$4;
X next;
X$1 == "pp" {
X if ($2 == 3)
X print "triangle ";
X else
X print "poly ";
X next;
X$1 == "p" {
X# Polygon -- the vertices will print out in the default statement.
X# If there are three vertices, make it a triangle.
X if ($2 == 3)
X print "triangle ";
X else
X print "poly ";
X next;
X# Matched nothing (or is a vertex data) -- print it.
X print;
X next;
XEND{
X print "end"
X# Output light definitions.
X intens = sqrt(lights) / (lights);
X for (i = 0; i < lights; i++) {
X print "light " intens " point " lightd[i]
X printf("eyep %g %g %g\n", eyex, eyey, eyez);
X printf("lookp %g %g %g\n", atx, aty, atz);
X printf("up %g %g %g\n", upx, upy, upz);
X printf("fov %g\n", fov);
X printf("screen %d %d\n", screenx, screeny);
END_OF_FILE
if test 3477 -ne `wc -c <'etc/nff2shade.awk'`; then
echo shar: \"'etc/nff2shade.awk'\" unpacked with wrong size!
# end of 'etc/nff2shade.awk'
if test -f 'libray/libcommon/sampling.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libcommon/sampling.c'\"
echo shar: Extracting \"'libray/libcommon/sampling.c'\" \(3298 characters\)
sed "s/^X//" >'libray/libcommon/sampling.c' <<'END_OF_FILE'
X * sampling.c
X * Copyright (C) 1989, 1991, Craig E. Kolb, Rod G. Bogart
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: sampling.c,v 4.0 91/07/17 14:31:55 kolb Exp Locker: kolb $
X * $Log: sampling.c,v $
X * Revision 4.0 91/07/17 14:31:55 kolb
X * Initial version.
X#include "common.h"
X#include "sampling.h"
XSampleInfo Sampling; /* sampling information */
X * Set sampling options.
Xvoid
XSamplingSetOptions(n, gaussian, width)
Xint n, gaussian;
XFloat width;
X Float norm, u, v;
X int x, y;
X Sampling.sidesamples = n;
X Sampling.totsamples = n*n;
X Sampling.weight = 1. / (Float)Sampling.totsamples;
X Sampling.spacing = 1. / (Float)Sampling.sidesamples;
X Sampling.filterwidth = width;
X Sampling.filterdelta = Sampling.filterwidth * Sampling.spacing;
X Sampling.gaussian = gaussian;
X Sampling.filter = (Float **)Malloc(Sampling.sidesamples
X *sizeof(Float *));
X for (y = 0; y < Sampling.sidesamples; y++) {
X Sampling.filter[y] = (Float *)Malloc(Sampling.sidesamples *
X sizeof(Float));
X if (Sampling.gaussian) {
X norm = 0.;
X u = -0.5*Sampling.filterwidth +
X 0.5*Sampling.filterwidth*Sampling.spacing;
X for (x = 0; x < Sampling.sidesamples; x++) {
X v = -0.5*Sampling.filterwidth +
X 0.5*Sampling.filterwidth*Sampling.spacing;
X for (y = 0; y < Sampling.sidesamples; y++) {
X Sampling.filter[x][y] = exp(-0.5*(u*u+v*v));
X norm += Sampling.filter[x][y];
X v += Sampling.spacing *
X Sampling.filterwidth;
X }
X u += Sampling.spacing * Sampling.filterwidth;
X for (x = 0; x < Sampling.sidesamples; x++)
X for (y = 0; y < Sampling.sidesamples; y++)
X Sampling.filter[x][y] /= norm;
X } else {
X /* Box filter. Yawn. */
X for (x = 0; x < Sampling.sidesamples; x++)
X for (y = 0; y < Sampling.sidesamples; y++)
X Sampling.filter[x][y] = Sampling.weight;
X * Set start time and duration of frame.
Xvoid
XSamplingSetTime(starttime, shutter, frame)
XFloat starttime, shutter;
Xint frame;
X Sampling.starttime = starttime;
X Sampling.shutter = shutter;
X Sampling.framenum = frame;
X TimeSet(Sampling.starttime);
X FrameSet((Float)frame);
X * Find a point on a unit circle that is separated from other random
X * points by some jitter spacing.
X * It should do the above, but the temporary hack below just finds a
X * jittered point in a unit square.
Xvoid
XUnitCirclePoint(pnt, sample)
XVector *pnt;
X * This picks a random point on a -1 to 1 square. The jitter stuff
X * is correct enough to avoid excessive noise. An extremely blurry
X * bright highlight will look squarish, not roundish. Sorry.
X */
X Float jit;
X if (sample >= 0) {
X jit = 2. * Sampling.spacing;
X pnt->x = nrand()*jit - 1.0 +
X (sample % Sampling.sidesamples) * jit;
X pnt->y = nrand()*jit - 1.0 +
X (sample / Sampling.sidesamples) * jit;
X pnt->z = 0.0;
X } else {
X pnt->x = nrand() * 2.0 - 1.0;
X pnt->y = nrand() * 2.0 - 1.0;
X pnt->z = 0.0;
END_OF_FILE
if test 3298 -ne `wc -c <'libray/libcommon/sampling.c'`; then
echo shar: \"'libray/libcommon/sampling.c'\" unpacked with wrong size!
# end of 'libray/libcommon/sampling.c'
if test -f 'libray/libcommon/vecmath.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libcommon/vecmath.c'\"
echo shar: Extracting \"'libray/libcommon/vecmath.c'\" \(3640 characters\)
sed "s/^X//" >'libray/libcommon/vecmath.c' <<'END_OF_FILE'
X * vecmath.c
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: vecmath.c,v 4.0 91/07/17 14:33:02 kolb Exp Locker: kolb $
X * $Log: vecmath.c,v $
X * Revision 4.0 91/07/17 14:33:02 kolb
X * Initial version.
X#include "common.h"
X * Normalize a vector, return original length.
XFloat
XVecNormalize(a)
Xregister Vector *a;
X Float d;
X d = sqrt(a->x*a->x + a->y*a->y + a->z*a->z);
X if(d == 0.)
X return 0.;
X a->x /= d;
X a->y /= d;
X a->z /= d;
X#ifdef CRAY
X * The Cray Research Inc. math functional units don't work in the IEEE
X * standard way, so when we get here, we just might have an x,y or z
X * that is not in the range -1.0 <= J <= 1.0 Yes, I know that that
X * can't happen, but it does. So since we know we just normalized this
X * vector, we'll just force x,y and z into the range -1.0 to 1.0 O.K?
X */
X if (a->x >= 1.0) a->x = 1.0;
X else if (a->x <= -1.0) a->x = -1.0;
X if (a->y >= 1.0) a->y = 1.0;
X else if (a->y <= -1.0) a->y = -1.0;
X if (a->z >= 1.0) a->z = 1.0;
X else if (a->z <= -1.0) a->z = -1.0;
X#endif /* CRAY */
X return d;
X * Compute cross-product of a and b, place normalized result in o. Returns
X * length of result before normalization.
XFloat
XVecNormCross(a, b, r)
XVector *a, *b, *r;
X VecCross(a, b, r);
X return VecNormalize(r);
X * Compute cross-product of a and b, place result in o.
Xvoid
XVecCross(a, b, r)
XVector *a, *b, *r;
X r->x = (a->y * b->z) - (a->z * b->y);
X r->y = (a->z * b->x) - (a->x * b->z);
X r->z = (a->x * b->y) - (a->y * b->x);
X * Calculate direction of refracted ray using Heckbert's formula. Returns TRUE
X * if a total internal reflection occurs.
XRefract(dir, from_index, to_index, I, N, cos1)
XFloat from_index, to_index, cos1;
XVector *dir, *I, *N;
X Float kn, cos2, k;
X Vector nrm;
X if (cos1 < 0.) {
X /*
X * Hit the 'backside' of a surface -- flip the normal.
X */
X nrm.x = -N->x;
X nrm.y = -N->y;
X nrm.z = -N->z;
X cos1 = -cos1;
X } else
X nrm = *N;
X kn = from_index / to_index;
X cos2 = 1. - kn*kn*(1. - cos1*cos1);
X if (cos2 < 0.)
X return TRUE; /* Total internal reflection. */
X k = kn * cos1 - sqrt(cos2);
X VecComb(kn, *I, k, nrm, dir);
X return FALSE;
X * Given a vector, find two additional vectors such that all three
X * are mutually perpendicular and uaxis X vaxis = vector. The given
X * vector need not be normalized. uaxis and vaxis are normalized.
Xvoid
XVecCoordSys(vector, uaxis, vaxis)
XVector *vector, *uaxis, *vaxis;
X uaxis->x = -vector->y;
X uaxis->y = vector->x;
X uaxis->z = 0.;
X if (VecNormalize(uaxis) == 0.) {
X uaxis->x = vector->z;
X uaxis->y = 0.;
X uaxis->z = -vector->x;
X if (VecNormalize(uaxis) == 0.)
X RLerror(RL_WARN,
X "VecCoordSys passed degenerate vector.\n");
X (void)VecNormCross(vector, uaxis, vaxis);
X * Modify given normal by "bumping" it.
Xvoid
XMakeBump(norm, dpdu, dpdv, fu, fv)
XVector *norm, *dpdu, *dpdv; /* normal, surface derivatives */
XFloat fu, fv; /* bump function partial derivatives in uv */
X Vector tmp1, tmp2;
X VecCross(norm, dpdv, &tmp1);
X VecScale(fu, tmp1, &tmp1);
X VecCross(norm, dpdu, &tmp2);
X VecScale(fv, tmp2, &tmp2);
X VecSub(tmp1, tmp2, &tmp1);
X VecAdd(*norm, tmp1, norm);
X (void)VecNormalize(norm);
END_OF_FILE
if test 3640 -ne `wc -c <'libray/libcommon/vecmath.c'`; then
echo shar: \"'libray/libcommon/vecmath.c'\" unpacked with wrong size!
# end of 'libray/libcommon/vecmath.c'
if test -f 'libray/liblight/spot.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/liblight/spot.c'\"
echo shar: Extracting \"'libray/liblight/spot.c'\" \(3312 characters\)
sed "s/^X//" >'libray/liblight/spot.c' <<'END_OF_FILE'
X * spot.c
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: spot.c,v 4.0 91/07/17 14:35:42 kolb Exp Locker: kolb $
X * $Log: spot.c,v $
X * Revision 4.0 91/07/17 14:35:42 kolb
X * Initial version.
X#include "light.h"
X#include "spot.h"
Xstatic LightMethods *iSpotMethods = NULL;
XSpotlight *
XSpotCreate(from, to, coef, in, out)
XVector *from, *to;
XFloat coef, in, out;
X Spotlight *spot;
X spot = (Spotlight *)share_malloc(sizeof(Spotlight));
X spot->pos = *from;
X VecSub(*to, *from, &spot->dir);
X if (VecNormalize(&spot->dir) == 0. || in > out) {
X RLerror(RL_ABORT,"Invalid spotlight specification.\n");
X return (Spotlight *)NULL;
X spot->coef = coef;
X spot->radius = cos(deg2rad(in));
X spot->falloff = cos(deg2rad(out));
X return spot;
XLightMethods *
XSpotMethods()
X if (iSpotMethods == (LightMethods *)NULL) {
X iSpotMethods = LightMethodsCreate();
X iSpotMethods->intens = SpotIntens;
X iSpotMethods->dir = SpotDirection;
X return iSpotMethods;
X * Calculate intensity ('color') of light reaching 'pos' from light 'lp'.
X * The spotlight is 'dist' units from 'pos' along 'dir'.
X * Returns TRUE if non-zero illumination, FALSE otherwise.
XSpotIntens(spot, lcolor, cache, ray, dist, noshadow, color)
XSpotlight *spot;
XShadowCache *cache;
XRay *ray;
XColor *lcolor, *color;
Xint noshadow;
XFloat dist;
X Float atten;
X extern Float SpotAtten();
X * Compute spotlight color
X */
X atten = SpotAtten(spot, &ray->dir);
X * If outside of spot, return FALSE.
X */
X if (atten == 0.)
X return FALSE;
X if (Shadowed(color, lcolor, cache, ray, dist, noshadow))
X return FALSE;
X ColorScale(atten, *color, color);
X return TRUE;
X * Compute intensity of spotlight along 'dir'.
XFloat
XSpotAtten(lp, dir)
XSpotlight *lp;
XVector *dir;
X Float costheta, atten;
X extern Float rampup();
X costheta = -dotp(dir, &lp->dir);
X * Behind spotlight.
X */
X if (costheta <= 0.)
X return 0.;
X * Intensity is the product of costheta raised to lp->coef and
X * a function that smoothly interpolates from 0 at
X * costheta=lp->falloff to 1 at costheta=lp->radius.
X */
X atten = pow(costheta, lp->coef);
X if (lp->radius > 0.)
X atten *= rampup(lp->falloff, lp->radius, costheta);
X return atten;
X * Cubic interpolation between 0 at left and 1 at right, sampled at 'at'
X * It is assumed that right >= left.
XFloat
Xrampup(left, right, at)
XFloat left, right, at;
X if (at < left)
X return 0.;
X else if (at > right)
X return 1.;
X if (right == left)
X return 0.;
X at = (at - left) / (right - left);
X return (3 - 2*at)*at*at;
Xvoid
XSpotDirection(lp, pos, dir, dist)
XSpotlight *lp;
XVector *pos, *dir;
XFloat *dist;
X * Calculate dir from position to center of light source.
X */
X VecSub(lp->pos, *pos, dir);
X *dist = VecNormalize(dir);
XSpotMethodRegister(meth)
XUserMethodType meth;
X if (iSpotMethods)
X iSpotMethods->user = meth;
END_OF_FILE
if test 3312 -ne `wc -c <'libray/liblight/spot.c'`; then
echo shar: \"'libray/liblight/spot.c'\" unpacked with wrong size!
# end of 'libray/liblight/spot.c'
if test -f 'libray/libobj/box.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libobj/box.c'\"
echo shar: Extracting \"'libray/libobj/box.c'\" \(3201 characters\)
sed "s/^X//" >'libray/libobj/box.c' <<'END_OF_FILE'
X * box.c
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: box.c,v 4.0 91/07/17 14:36:32 kolb Exp Locker: kolb $
X * $Log: box.c,v $
X * Revision 4.0 91/07/17 14:36:32 kolb
X * Initial version.
X#include "geom.h"
X#include "box.h"
Xstatic Methods *iBoxMethods = NULL;
Xstatic char boxName[] = "box";
Xunsigned long BoxTests, BoxHits;
XBox *
XBoxCreate(v1, v2)
XVector *v1, *v2;
X Box *box;
X Vector size;
X VecSub(*v1, *v2, &size);
X if (equal(size.x, 0.) || equal(size.y, 0.) || equal(size.z, 0.)) {
X RLerror(RL_WARN, "Degenerate box.\n");
X return (Box *)NULL;
X box = (Box *)share_malloc(sizeof(Box));
X box->bounds[LOW][X] = min(v1->x, v2->x);
X box->bounds[HIGH][X] = max(v1->x, v2->x);
X box->bounds[LOW][Y] = min(v1->y, v2->y);
X box->bounds[HIGH][Y] = max(v1->y, v2->y);
X box->bounds[LOW][Z] = min(v1->z, v2->z);
X box->bounds[HIGH][Z] = max(v1->z, v2->z);
X return box;
XMethods *
XBoxMethods()
X if (iBoxMethods == (Methods *)NULL) {
X iBoxMethods = MethodsCreate();
X iBoxMethods->create = (GeomCreateFunc *)BoxCreate;
X iBoxMethods->methods = BoxMethods;
X iBoxMethods->name = BoxName;
X iBoxMethods->intersect = BoxIntersect;
X iBoxMethods->normal = BoxNormal;
X iBoxMethods->enter = BoxEnter;
X iBoxMethods->bounds = BoxBounds;
X iBoxMethods->stats = BoxStats;
X iBoxMethods->checkbounds = FALSE;
X iBoxMethods->closed = TRUE;
X return iBoxMethods;
XBoxIntersect(box, ray, mindist, maxdist)
XBox *box;
XRay *ray;
XFloat mindist, *maxdist;
X BoxTests++;
X if (BoundsIntersect(ray, box->bounds, mindist, maxdist)) {
X BoxHits++;
X return TRUE;
X return FALSE;
XBoxNormal(box, pos, nrm, gnrm)
XVector *pos, *nrm, *gnrm; /* point of intersection */
XBox *box;
X nrm->x = nrm->y = nrm->z = 0.;
X if (equal(pos->x, box->bounds[HIGH][X]))
X nrm->x = 1.;
X else if (equal(pos->x, box->bounds[LOW][X]))
X nrm->x = -1.;
X else if (equal(pos->y, box->bounds[HIGH][Y]))
X nrm->y = 1.;
X else if (equal(pos->y, box->bounds[LOW][Y]))
X nrm->y = -1.;
X else if (equal(pos->z, box->bounds[HIGH][Z]))
X nrm->z = 1.;
X else if (equal(pos->z, box->bounds[LOW][Z]))
X nrm->z = -1.;
X else
X RLerror(RL_WARN, "Confusion in nrmbox!\n");
X *gnrm = *nrm;
X return FALSE;
X * Determine if ray enters (TRUE) or leaves (FALSE) box at pos
XBoxEnter(box, ray, mind, hitd)
XBox *box;
XRay *ray;
XFloat mind, hitd;
X Vector pos;
X VecAddScaled(ray->pos, mind, ray->dir, &pos);
X return OutOfBounds(&pos, box->bounds);
Xvoid
XBoxBounds(box, bounds)
XBox *box;
XFloat bounds[2][3];
X BoundsCopy(box->bounds, bounds);
Xchar *
XBoxName()
X return boxName;
Xvoid
XBoxStats(tests, hits)
Xunsigned long *tests, *hits;
X *tests = BoxTests;
X *hits = BoxHits;
Xvoid
XBoxMethodRegister(meth)
XUserMethodType meth;
X if (iBoxMethods)
X iBoxMethods->user = meth;
END_OF_FILE
if test 3201 -ne `wc -c <'libray/libobj/box.c'`; then
echo shar: \"'libray/libobj/box.c'\" unpacked with wrong size!
# end of 'libray/libobj/box.c'
if test -f 'libray/libobj/geom.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libobj/geom.h'\"
echo shar: Extracting \"'libray/libobj/geom.h'\" \(3949 characters\)
sed "s/^X//" >'libray/libobj/geom.h' <<'END_OF_FILE'
X * geom.h
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: geom.h,v 4.0 91/07/17 14:37:52 kolb Exp Locker: kolb $
X * $Log: geom.h,v $
X * Revision 4.0 91/07/17 14:37:52 kolb
X * Initial version.
X#ifndef OBJECT_H
X#define OBJECT_H
X#include "libcommon/common.h"
X#include "libcommon/transform.h"
X#include "bounds.h"
X * Constants for enter flag in HitNode.
X#define EXITING 1
X#define ENTERING 2
X#define MAXMODELDEPTH 128 /* Maximum height of DAG. */
Xtypedef char * GeomRef;
Xtypedef GeomRef GeomCreateFunc();
X * If the object has a normal method, it's a primitive
X * otherwise it's an aggregate (or an instance)
X#define IsAggregate(o) ((o)->methods->normal == NULL)
X * Geom methods.
X * (p) means applies only to primitive objects
X * (a) means applies only to aggregate objects
Xtypedef struct Methods {
X char *(*name)(); /* Geom name */
X GeomRef (*create)(); /* Create and return ref */
X int (*intersect)(), /* Ray/obj intersection */
X (*normal)(), /* Geom normal (p) */
X (*enter)(), /* Ray enter or exit? (p) */
X (*convert)(); /* Convert from list (a) */
X void (*uv)(), /* 2D mapping (p) */
X (*stats)(), /* Statistics */
X (*bounds)(), /* Bounding volume */
X (*user)(); /* User-defined method */
X struct Methods *(*methods)(); /* object methods func. */
X char checkbounds, /* check bbox before int.? */
X closed; /* properly closed? */
X} Methods;
Xtypedef void (*UserMethodType)();
X * Geom definition
Xtypedef struct Geom {
X char *name; /* Geom name, if any. */
X GeomRef obj; /* Pointer to object info. */
X Methods *methods;
X unsigned long prims; /* sum of # primitive objects */
X Float bounds[2][3]; /* Bounding box */
X Float timenow; /* Geom's idea of what time it is */
X short int animtrans; /* transformation is animated */
X short int frame; /* frame for which obj is inited */
X struct Surface *surf; /* surface, if any */
X struct Trans *trans; /* Transformation information */
X struct Trans *transtail; /* Double linked list end */
X struct Texture *texture; /* Texture mapping info. */
X#ifdef SHAREDMEM
X unsigned long *counter; /* Geoms are shared, counters aren't */
X#else
X unsigned long counter; /* "mailbox" for grid intersection */
X#endif
X struct Geom *next; /* Next object. */
X} Geom;
X * Linked list of pointers to objects.
Xtypedef struct GeomList {
X Geom *obj;
X struct GeomList *next;
X} GeomList;
X * Array of hit information. Stores a path through an object DAG,
X * as well as the ray in 'model' (object) space and the distance from
X * the ray origin to the point of intersection.
Xtypedef struct HitNode {
X Geom *obj; /* Geom hit */
X Ray ray; /* Ray */
X Float mindist; /* Amount of ray to ignore */
X Float dist; /* Distance from ray origin to hit */
X short enter, /* Enter (TRUE) or Leave (FALSE) obj */
X dotrans; /* transformations non-identity? */
X Trans trans; /* parent-->obj and inverse trans */
X} HitNode;
X * Structure holding a list of HitNodes. A maximum of MAXMODELDEPTH
X * nodes can be referenced.
Xtypedef struct HitList {
X int nodes;
X HitNode data[MAXMODELDEPTH];
X} HitList;
Xextern char *GeomName();
Xextern Geom *GeomCreate(), *GeomCopy(), *GeomCopyNamed(),
X *GeomComputeAggregateBounds();
Xextern GeomList *GeomStackPush(), *GeomStackPop();
Xextern void PrimUV(), AggregatePrintInfo(),
X IntersectStats();
Xextern int AggregateConvert(), PrimNormal(),
X TraceRay(); /* application-provided */
Xextern Methods *MethodsCreate();
X#endif /* OBJECT_H */
END_OF_FILE
if test 3949 -ne `wc -c <'libray/libobj/geom.h'`; then
echo shar: \"'libray/libobj/geom.h'\" unpacked with wrong size!
# end of 'libray/libobj/geom.h'
if test -f 'libray/libobj/intersect.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libobj/intersect.c'\"
echo shar: Extracting \"'libray/libobj/intersect.c'\" \(3980 characters\)
sed "s/^X//" >'libray/libobj/intersect.c' <<'END_OF_FILE'
X * intersect.c
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: intersect.c,v 4.0 91/07/17 14:38:37 kolb Exp Locker: kolb $
X * $Log: intersect.c,v $
X * Revision 4.0 91/07/17 14:38:37 kolb
X * Initial version.
X#include "geom.h"
Xstatic void AddToHitList();
X * Number of bounding volume tests.
X * External modules have read access via IntersectStats().
Xstatic unsigned long BVTests;
X * Intersect object & ray. Return distance from "pos" along "ray" to
X * intersection point. Return value <= 0 indicates no intersection.
Xintersect(obj, ray, hitlist, mindist, maxdist)
XGeom *obj; /* Geom to be tested. */
XRay *ray; /* Ray origin, direction. */
XHitList *hitlist; /* Intersection path */
XFloat mindist, *maxdist;
X Ray newray;
X Vector vtmp;
X Trans *curtrans;
X Float distfact, nmindist, nmaxdist;
X * Check ray/bounding volume intersection, if required.
X */
X if (obj->methods->checkbounds) {
X VecAddScaled(ray->pos, mindist, ray->dir, &vtmp);
X if (OutOfBounds(&vtmp, obj->bounds)) {
X nmaxdist = *maxdist;
X BVTests++;
X if (!BoundsIntersect(ray, obj->bounds, mindist,
X &nmaxdist))
X return FALSE;
X newray = *ray;
X nmindist = mindist;
X nmaxdist = *maxdist;
X * Transform the ray if necessary.
X */
X if (obj->trans != (Trans *)0) {
X /*
X * If object's idea of the current time is wrong,
X * update the transformations.
X */
X if (obj->animtrans && !equal(obj->timenow, ray->time)) {
X TransResolveAssoc(obj->trans);
X
X /*
X * Transforming the ray can change the distance between
X * the ray origin and the point of intersection.
X * We save the amount the ray is "stretched" and later
X * divide the computed distance by this amount.
X */
X distfact = 1.;
X for (curtrans = obj->transtail; curtrans;
X curtrans = curtrans->prev)
X distfact *= RayTransform(&newray, &curtrans->itrans);
X nmindist *= distfact;
X nmaxdist *= distfact;
X * Geom has been updated to current time.
X */
X obj->timenow = ray->time;
X * Call correct intersection routine.
X */
X if (IsAggregate(obj)) {
X /*
X * Aggregate
X */
X if (!(*obj->methods->intersect)
X (obj->obj, &newray, hitlist, nmindist, &nmaxdist))
X return FALSE;
X } else {
X /*
X * Primitive
X */
X if (!(*obj->methods->intersect)
X (obj->obj, &newray, nmindist, &nmaxdist))
X return FALSE;
X hitlist->nodes = 0;
X * Had a hit -- add ray, distance and object to tail of hitlist.
X */
X AddToHitList(hitlist, &newray, nmindist, nmaxdist, obj);
X * Set dist to distance to intersection point from the origin
X * of the untransformed ray.
X */
X if (obj->trans != (Trans *)0)
X *maxdist = nmaxdist / distfact;
X else
X *maxdist = nmaxdist;
X return TRUE;
Xstatic void
XAddToHitList(hitlist, ray, mind, dist, obj)
XHitList *hitlist;
XRay *ray;
XFloat mind, dist;
XGeom *obj;
X HitNode *np;
X Trans *list;
X np = &hitlist->data[hitlist->nodes++];
X np->ray = *ray;
X np->obj = obj;
X np->mindist = mind;
X np->dist = dist;
X np->enter = 0;
X if (obj->trans) {
X /*
X * Compute total transformation, forward and inverse,
X * for this object, and store in hitlist for use later.
X */
X TransCopy(obj->trans, &np->trans);
X for (list = obj->trans->next; list; list = list->next)
X TransCompose(&np->trans, list, &np->trans);
X np->dotrans = TRUE;
X } else
X np->dotrans = FALSE;
X * Return intersection statistics.
X * Currently, this is limited to the # of bounding volume test performed.
Xvoid
XIntersectStats(bvtests)
Xunsigned long *bvtests;
X *bvtests = BVTests;
END_OF_FILE
if test 3980 -ne `wc -c <'libray/libobj/intersect.c'`; then
echo shar: \"'libray/libobj/intersect.c'\" unpacked with wrong size!
# end of 'libray/libobj/intersect.c'
if test -f 'libray/libsurf/surface.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libsurf/surface.c'\"
echo shar: Extracting \"'libray/libsurf/surface.c'\" \(3304 characters\)
sed "s/^X//" >'libray/libsurf/surface.c' <<'END_OF_FILE'
X * surface.c
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: surface.c,v 4.0 91/07/17 14:40:55 kolb Exp Locker: kolb $
X * $Log: surface.c,v $
X * Revision 4.0 91/07/17 14:40:55 kolb
X * Initial version.
X#include "atmosphere.h"
X#include "surface.h"
X#define blend(a, b, p, q) (a * p + b * q)
XColor Black = {0., 0., 0.},
X White = {1., 1., 1.};
X * Create and return pointer to surface with given properties.
XSurface *
XSurfaceCreate()
X Surface *stmp;
X stmp = (Surface *)Malloc(sizeof(Surface));
X stmp->amb = stmp->diff = stmp->spec =
X stmp->translu = Black;
X stmp->body = White;
X stmp->srexp = stmp->stexp = DEFAULT_PHONGPOW;
X stmp->statten = 1.; /* No attenuation by default */
X stmp->reflect = stmp->transp = 0.;
X stmp->noshadow = FALSE;
X stmp->index = DEFAULT_INDEX;
X stmp->name = (char *)NULL;
X stmp->next = (Surface *)NULL;
X return stmp;
XSurface *
XSurfaceCopy(surf)
XSurface *surf;
X Surface *res;
X if (!surf)
X return (Surface *)NULL;
X res = SurfaceCreate();
X *res = *surf;
X res->next = (Surface *)NULL;
X res->name = (char *)NULL;
X return res;
X * Compute combination of two surfaces. Resulting surface is copied into surf1.
Xvoid
XSurfaceBlend(surf1, surf2, p, q)
XSurface *surf1, *surf2;
XFloat p, q;
X * P is weight of surf1. q is weight of surf2.
X * Result is placed in surf1.
X */
X if (q < EPSILON)
X return; /* keep surf1 as-is */
X ColorBlend(&surf1->amb, &surf2->amb, p, q);
X ColorBlend(&surf1->diff, &surf2->diff, p, q);
X ColorBlend(&surf1->spec, &surf2->spec, p, q);
X ColorBlend(&surf1->translu, &surf2->translu, p, q);
X ColorBlend(&surf1->body, &surf2->body, p, q);
X surf1->srexp = blend(surf1->srexp, surf2->srexp, p, q);
X surf1->stexp = blend(surf1->stexp, surf2->stexp, p, q);
X surf1->reflect = blend(surf1->reflect, surf2->reflect, p, q);
X surf1->transp = blend(surf1->transp, surf2->transp, p, q);
X surf1->translucency = blend(surf1->translucency, surf2->translucency,
X p, q);
X * Questionable...
X */
X surf1->statten = blend(surf1->statten, surf2->statten, p, q);
X surf1->index = blend(surf1->index, surf2->index, p, q);
X if (p < EPSILON) {
X surf1->noshadow = surf2->noshadow;
X } else {
X /* else there's a blend of some kind... */
X surf1->noshadow = (surf1->noshadow && surf2->noshadow);
X * Blend two colors. Result is placed in color1.
Xvoid
XColorBlend(color1, color2, p, q)
XColor *color1, *color2;
XFloat p, q;
X color1->r = blend(color1->r, color2->r, p, q);
X color1->g = blend(color1->g, color2->g, p, q);
X color1->b = blend(color1->b, color2->b, p, q);
XSurfList *
XSurfPop(list)
XSurfList *list;
X SurfList *stmp = list->next;
X free((voidstar)list);
X return stmp;
XSurfList *
XSurfPush(surf, list)
XSurface *surf;
XSurfList *list;
X SurfList *stmp;
X stmp = (SurfList *)Malloc(sizeof(SurfList));
X stmp->surf = surf;
X stmp->next = list;
X return stmp;
END_OF_FILE
if test 3304 -ne `wc -c <'libray/libsurf/surface.c'`; then
echo shar: \"'libray/libsurf/surface.c'\" unpacked with wrong size!
# end of 'libray/libsurf/surface.c'
if test -f 'libshade/lightdef.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libshade/lightdef.c'\"
echo shar: Extracting \"'libshade/lightdef.c'\" \(3547 characters\)
sed "s/^X//" >'libshade/lightdef.c' <<'END_OF_FILE'
X * lightdef.c
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: lightdef.c,v 4.0 91/07/17 14:46:25 kolb Exp Locker: kolb $
X * $Log: lightdef.c,v $
X * Revision 4.0 91/07/17 14:46:25 kolb
X * Initial version.
X#include "rayshade.h"
X#include "options.h"
X#include "liblight/light.h"
X#include "liblight/infinite.h" /* to create default infinite light */
X#include "liblight/jittered.h" /* to create jittered light sources */
XLight *Lights = NULL; /* Linked list of defined lights */
Xvoid
XLightAddToDefined(light)
XLight *light;
X if (light) {
X light->next = Lights;
X Lights = light;
Xvoid
XLightSetup()
X long shadowopts;
X Light *ltmp;
X * Set shadowing options.
X */
X shadowopts = 0;
X if (Options.no_shadows)
X shadowopts |= SHADOW_NONE;
X if (Options.shadowtransp)
X shadowopts |= SHADOW_TRANSP;
X if (Options.csg)
X shadowopts |= SHADOW_CSG;
X if (Options.cache)
X shadowopts |= SHADOW_CACHE;
X if (Options.shutterspeed > 0.)
X shadowopts |= SHADOW_BLUR;
X ShadowSetOptions(shadowopts);
X * If no light sources were defined, add a default.
X */
X if (Lights == (Light *)NULL) {
X Color ctmp;
X Vector vtmp;
X vtmp.x = vtmp.z = 1.;
X vtmp.y = -1;
X ctmp.r = ctmp.g = ctmp.b = 1.;
X LightAddToDefined(LightInfiniteCreate(&ctmp, &vtmp));
X * Now that we've parsed the input file, we know what
X * maxlevel is, and we can allocate the correct amount of
X * space for each light source's cache.
X */
X for (ltmp = Lights; ltmp; ltmp = ltmp->next) {
X ltmp->cache = (ShadowCache *)Calloc(
X (unsigned)Options.maxdepth + 1, sizeof(ShadowCache));
Xvoid
XAreaLightCreate(color, corner, u, usamp, v, vsamp, shadow)
XColor *color;
XVector *corner, *u, *v;
Xint usamp, vsamp, shadow;
X Vector vpos, curpos;
X int i, j, numlight;
X Float ulen, vlen;
X Color intens;
X Light *ltmp;
X if (usamp < 1 || vsamp < 1)
X RLerror(RL_ABORT, "Invalid area light specification.\n");
X numlight = usamp * vsamp; /* Total number of jittered sources */
X * Sum of all intensities is equal to specified intensity.
X */
X intens.r = color->r / (Float)numlight;
X intens.g = color->g / (Float)numlight;
X intens.b = color->b / (Float)numlight;
X VecSub(*u, *corner, u);
X VecSub(*v, *corner, v);
X * Make sure that u and v are not degenerate.
X */
X ulen = VecNormalize(u);
X vlen = VecNormalize(v);
X if (ulen < EPSILON || vlen < EPSILON)
X RLerror(RL_ABORT, "Degenerate area light source.\n");
X * Scale u and v such that they define the area covered by a
X * single sample.
X */
X VecScale(ulen / (Float)usamp, *u, u);
X VecScale(vlen / (Float)vsamp, *v, v);
X * For each sample...
X */
X vpos = *corner;
X for (i = 0; i < vsamp; i++) {
X curpos = vpos;
X for (j = 0; j < usamp; j++) {
X /*
X * current pos is the "corner" of a new light
X * source. A jittered position based on
X * the "corner" and the two edge vectors
X * is used as the position for the
X * light source in lighting calculations.
X */
X ltmp = LightJitteredCreate(&intens, &curpos, u, v);
X ltmp->shadow = shadow;
X LightAddToDefined(ltmp);
X VecAdd(curpos, *u, &curpos);
X VecAdd(vpos, *v, &vpos);
END_OF_FILE
if test 3547 -ne `wc -c <'libshade/lightdef.c'`; then
echo shar: \"'libshade/lightdef.c'\" unpacked with wrong size!
# end of 'libshade/lightdef.c'
if test -f 'libshade/options.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libshade/options.h'\"
echo shar: Extracting \"'libshade/options.h'\" \(3167 characters\)
sed "s/^X//" >'libshade/options.h' <<'END_OF_FILE'
X * options.h
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: options.h,v 4.0 91/07/17 14:46:54 kolb Exp Locker: kolb $
X * $Log: options.h,v $
X * Revision 4.0 91/07/17 14:46:54 kolb
X * Initial version.
X#ifndef OPTIONS_H
X#define OPTIONS_H
X * Constants for Stereo mode
X#define LEFT 1
X#define RIGHT 2
X * Options
Xtypedef struct RSOptions {
X int stereo, /* Stereo mode? */
X verbose, /* Babbling mode? */
X quiet, /* Don't complain? */
X jitter, /* use jittered sampling? */
X samples, /* Sqrt of # of samples */
X maxdepth, /* Maximum ray tree depth */
X report_freq, /* Frequency, in lines, of report */
X no_shadows, /* Trace shadow rays? */
X shadowtransp, /* ... through transparent objects? */
X cache, /* Cache shadowing info? */
X appending, /* Append to image file? */
X resolution_set, /* resolution set on command line */
X contrast_set, /* contrast overridden ... */
X samples_set, /* samples overridden ... */
X cutoff_set, /* cutoff ... */
X maxdepth_set, /* adaptive depth ... */
X window_set, /* window ... */
X freq_set, /* report frequency ... */
X jitter_set, /* use jittering */
X eyesep_set, /* eye separation ... */
X csg, /* CSG object someplace in world */
X flipnorm, /* flip normals of polygonal objs */
X samplemap, /* output sample map? */
X gaussian, /* Use gaussian pixel filter? */
X framenum, /* current frame number */
X startframe, /* Starting frame number. */
X endframe, /* ending frame number */
X totalframes, /* total # of frames */
X totalframes_set; /* set on command line? */
X#ifdef URT
X int alpha; /* Write alpha channel? */
X int exp_output; /* Write exponential RLE file? */
X#endif
X Float eyesep, /* Eye separation (for Stereo mode) */
X gamma, /* Gamma value (0 == no correction) */
X xmin, xmax, ymin, ymax, /* Window range */
X starttime, /* Think about it ... */
X shutterspeed, /* time shutter is open */
X framestart, /* start time of the current frame */
X framelength, /* length of the current frame */
X filterwidth; /* Pixel filter width. */
X Color contrast, /* Max. allowable contrast */
X cutoff, /* Ray tree depth control */
X ambient; /* Ambient light multiplier */
X char *progname, /* argv[0] */
X *statsname, /* Name of stats file. */
X *imgname, /* Name of output image file */
X *inputname, /* Name of input file, NULL == stdin */
X *cppargs; /* arguments to pass to cpp */
X#ifdef LINDA
X int workers, /* # of worker processes */
X workernum, /* worker #, 0 == supervisor */
X verbose_worker; /* Babble while you work? */
X#endif
X FILE *pictfile; /* output file pointer */
X} RSOptions;
Xextern RSOptions Options;
Xextern void OptionsList(), OptionsSet();
X#endif /* OPTIONS_H */
END_OF_FILE
if test 3167 -ne `wc -c <'libshade/options.h'`; then
echo shar: \"'libshade/options.h'\" unpacked with wrong size!
# end of 'libshade/options.h'
if test -f 'libshade/symtab.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libshade/symtab.c'\"
echo shar: Extracting \"'libshade/symtab.c'\" \(3608 characters\)
sed "s/^X//" >'libshade/symtab.c' <<'END_OF_FILE'
X * symtab.c
X * Copyright (C) 1989, 1991, Craig E. Kolb, Rod G. Bogart
X * All rights reserved.
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X * You may not distribute this software, in whole or in part, as part of
X * any commercial product without the express consent of the authors.
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X * $Id: symtab.c,v 4.0 91/07/17 14:48:02 kolb Exp Locker: kolb $
X * $Log: symtab.c,v $
X * Revision 4.0 91/07/17 14:48:02 kolb
X * Initial version.
X#include "rayshade.h"
X#include "symtab.h"
X#include "builtin.h"
Xstatic struct SymtabPredefinedEntry SymtabPredefined[] = {
X {"pi", 3.141592, NULL, FLOAT_EXPR, FALSE, 0},
X {"dtor", 0.017453, NULL, FLOAT_EXPR, FALSE, 0},
X {"rtod", 57.29578, NULL, FLOAT_EXPR, FALSE, 0},
X {"cos", 0.0, cos, BUILTIN_EXPR, FALSE, 1},
X {"sin", 0.0, sin, BUILTIN_EXPR, FALSE, 1},
X {"tan", 0.0, tan, BUILTIN_EXPR, FALSE, 1},
X {"sqrt", 0.0, sqrt, BUILTIN_EXPR, FALSE, 1},
X {"acos", 0.0, acos, BUILTIN_EXPR, FALSE, 1},
X {"asin", 0.0, asin, BUILTIN_EXPR, FALSE, 1},
X {"atan", 0.0, atan, BUILTIN_EXPR, FALSE, 1},
X {"hypot", 0.0, hypot, BUILTIN_EXPR, FALSE, 2},
X {"time", 0.0, NULL, FLOAT_EXPR, TRUE, 0},
X {"frame", 0.0, NULL, FLOAT_EXPR, TRUE, 0},
X {"linear", 0.0, LinearTime, BUILTIN_EXPR, TRUE, 4},
X {NULL, 0.0, NULL, 0, 0}
XSymtabEntry *Symtab = (SymtabEntry *) NULL;
Xvoid SymtabAddEntry();
Xvoid
XSymtabInit()
X int i;
X for(i=0; SymtabPredefined[i].name; i++) {
X if (SymtabPredefined[i].type == BUILTIN_EXPR)
X SymtabAddEntry(SymtabPredefined[i].name,
X SymtabPredefined[i].type,
X NULL,
X SymtabPredefined[i].fp,
X SymtabPredefined[i].timevary,
X SymtabPredefined[i].params);
X else
X SymtabAddEntry(SymtabPredefined[i].name,
X SymtabPredefined[i].type,
X ExprFloatCreate(SymtabPredefined[i].f,
X SymtabPredefined[i].timevary),
X NULL, SymtabPredefined[i].timevary, 0);
X TimeExpr = ExprFloatSymtabFind("time");
X FrameExpr = ExprFloatSymtabFind("frame");
Xvoid
XSymtabAddEntry(name, type, expr, fp, timevary, params)
Xchar *name;
XExpr *expr;
XFloat (*fp)();
Xint type, timevary, params;
X SymtabEntry *res;
X if (SymtabFind(name) != (SymtabEntry *)NULL)
X RLerror(RL_ABORT, "Symbol %s redefined.\n", name);
X res = (SymtabEntry *) Malloc( sizeof(SymtabEntry));
X res->name = strsave(name);
X res->type = type;
X res->timevary = timevary;
X switch (type) {
X case FLOAT_EXPR:
X res->value.expr = expr;
X expr->symtab = TRUE;
X break;
X case BUILTIN_EXPR:
X res->value.fp = fp;
X break;
X default:
X RLerror(RL_WARN,
X "Type %d not implemented!!!",type);
X res->params = params;
X res->next = Symtab;
X Symtab = res;
XSymtabEntry *
XSymtabFind(name)
Xchar *name;
X SymtabEntry *res;
X for(res=Symtab; res; res=res->next) {
X if (!strcmp(res->name,name))
X return res;
X /*error*/
X return NULL;
XExpr *
XExprFloatSymtabFind(name)
Xchar *name;
X SymtabEntry *res;
X if ((res = SymtabFind(name)) == NULL)
X RLerror(RL_PANIC,
X "Symbol %s not defined!\n", name);
X if (res->type != FLOAT_EXPR)
X RLerror(RL_PANIC,
X "Symbol %s is not a float expression!\n", name);
X return res->value.expr;
XSymtabEntry *
XSymtabBuiltinFind(name)
Xchar *name;
X SymtabEntry *res;
X if ((res = SymtabFind(name)) == NULL)
X RLerror(RL_PANIC,
X "Symbol %s not defined!\n", name);
X if (res->type != BUILTIN_EXPR)
X RLerror(RL_PANIC,
X "Symbol %s is not a built in function!\n", name);
X return res;
END_OF_FILE
if test 3608 -ne `wc -c <'libshade/symtab.c'`; then
echo shar: \"'libshade/symtab.c'\" unpacked with wrong size!
# end of 'libshade/symtab.c'
echo shar: End of archive 7 \(of 19\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
if test "${MISSING}" = "" ; then
echo You have unpacked all 19 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
echo You still need to unpack the following archives:
echo " " ${MISSING}
## End of shell archive.
exit 0
exit 0 # Just in case...