home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume21
/
rayshade
/
part05
< prev
next >
Wrap
Text File
|
1991-07-21
|
54KB
|
1,973 lines
Newsgroups: comp.sources.misc
From: Rayshade Construction Co. <rayshade@weedeater.math.YALE.EDU>
Subject: v21i008: rayshade - A raytracing package for UNIX, Part05/19
Message-ID: <1991Jul20.043430.11415@sparky.IMD.Sterling.COM>
X-Md4-Signature: f8e80c4adced6288998ca8b3585df340
Date: Sat, 20 Jul 1991 04:34:30 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Rayshade Construction Co. <rayshade@weedeater.math.YALE.EDU>
Posting-number: Volume 21, Issue 8
Archive-name: rayshade/part05
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 5 (of 19)."
# Contents: Doc/Globals Doc/Guide/height.tex Examples/csg.ray
# Examples/mtv.ray etc/malloc.sgi libray/libcommon/common.h
# libray/libcommon/rotate.c libray/libcommon/transform.h
# libray/libcommon/vector.h libray/liblight/jittered.c
# libray/liblight/light.c libray/liblight/light.h
# libray/libobj/instance.c libray/libsurf/atmosphere.c
# libray/libsurf/surface.h libray/libtext/fbm.c
# libray/libtext/texture.h libray/libtext/wood.c libshade/objdef.c
# rayshade/main.c
# Wrapped by kolb@woody on Wed Jul 17 17:56:44 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Doc/Globals' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Doc/Globals'\"
else
echo shar: Extracting \"'Doc/Globals'\" \(1927 characters\)
sed "s/^X//" >'Doc/Globals' <<'END_OF_FILE'
X/*
X * Variables shared by the various libraries:
X */
X
XFloat
XRSAbstmp
X
X Temporary variable used by the fabs() macro to keep
X expressions from being evaluated twice (e.g.,
X fabs(cos(x)) is expanded to ((x=cos(x) < 0 ? -x : x)
X rather than ((x=cos(x) < 0 ? -cos(x) : cos(x)) ).
X Could be removed by making fabs a function or not minding
X if expressions are evaluated twice.
X
XSampleInfo
XSampling
X
X Variables used to control sampling.
X Used in conjunction with a ray's sample number
X (ray->sample) to determine how to sample, for example,
X extended light sources.
X
X/*
X * Variables shared by modules in the rayshade application:
X */
XRSCamera
XCamera
X Camera definition. Used in viewing, setup, and parsing.
X
XRSScreen
XScreen
X Screen information. Used in viewing, setup, and parsing.
X
XRSOptions
XOptions
X
X Options of all sorts.
X
XRSStats
XStats
X
X Statistical information.
X
XMedium
XTopMedium
X
X "Air" description (index of refraction and atmospheric effects).
X Used in viewing, parsing, and ShadeRay.
X
XLight *
XLights
X
X Array of defined lights. Used in parsing and in shade().
X
X/*
X * Application-provided functions:
X */
XSurface *
XGetShadingSurf(hitlist)
XHitList *hitlist
X
X Given a hitlist, return the surface to be used in shading.
X
Xint
XTraceRay(ray, hitlist, mindist, maxdist)
XRay *ray;
XHitList *hitlist;
XFloat mindist, *maxdist;
X
X Intersect the top-level object with the given ray.
X Probably as simple as:
X return intersect(World, ray, hitlist, mindist, maxdist)
X
Xvoid
XRLerror(level, pattern, arg1, arg2, arg3)
Xint level;
Xchar *pattern, *arg1, *arg2, *arg3;
X
X Error-reporting function. 'level' indicates the severity of
X the error (see libcommon/error.h). 'pattern' and the
X args are suitable for printing via:
X fprintf(stderr, patter, arg1, arg2, arg3);
X Note that as the args are cast to char *'s, printing, for
X example, several doubles, will not work. (Being more
X rigorous about it would require varargs or something similar.)
END_OF_FILE
if test 1927 -ne `wc -c <'Doc/Globals'`; then
echo shar: \"'Doc/Globals'\" unpacked with wrong size!
fi
# end of 'Doc/Globals'
fi
if test -f 'Doc/Guide/height.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Doc/Guide/height.tex'\"
else
echo shar: Extracting \"'Doc/Guide/height.tex'\" \(1846 characters\)
sed "s/^X//" >'Doc/Guide/height.tex' <<'END_OF_FILE'
X\chapter{Height Field Files}
X
XThis appendix describes the format of the files that store data
Xfor the height field primitive.
XThe format is an historical relic; a better format is needed.
X
XHeight field data is stored in binary form.
XThe first record in the file is a
X32-bit integer giving the square root of number of data
Xpoints in the file.
XWe'll call this number
Xthe size of the height field.
X
XThe size is
Xfollowed by altitude ($z$) values stored as 32-bit
Xfloating point values. The 0th value in the file specifies the $z$
Xcoordinate
Xof the lower-left corner of the height field (0, 0).
XThe next
Xspecifies the Z coordinate for $(1/(size-1), 0)$. The last specifies the
Xcoordinate for $(1., 1.)$. In other words, the $i^{th}$ value
Xin the heightfield file specifies the $z$ coordinate for the point
Xwhose $x$ coordinate is
X$(i \% size) / (size -1)$, and whose
X$y$ coordinate is $(i / size) / (size -1)$.
XNon-square height fields may be rendered by specifying altitude values
Xless than or equal to the magic value
X$-1000$. Triangles that have any vertex less than
Xor equal in altitude to this value are not rendered.
X
XWhile this file format is compact, it sacrifices portability for
Xease of use. While creating and handling height field files is
Xsimple, transporting a height field from one machine to another
Xis problematical due to the fact that differences in byte order
Xand floating-point format between machines is not taken into
Xaccount.
X
XThese problems could be circumvented by writing the height field file
Xin a fixed-point format, taking care to write the bytes that
Xencode a given value in a consistent way from machine to machine.
XAn even better idea would be to write a set of tools for
Xmanipulating arbitrary 2D arrays of floating-point values in a compact,
Xportable way, allowing for comments and the like in the file\ldots
END_OF_FILE
if test 1846 -ne `wc -c <'Doc/Guide/height.tex'`; then
echo shar: \"'Doc/Guide/height.tex'\" unpacked with wrong size!
fi
# end of 'Doc/Guide/height.tex'
fi
if test -f 'Examples/csg.ray' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Examples/csg.ray'\"
else
echo shar: Extracting \"'Examples/csg.ray'\" \(2330 characters\)
sed "s/^X//" >'Examples/csg.ray' <<'END_OF_FILE'
X/*
X * csg wood block (apologies to Hofstadter)
X *
X * Eric Haines
X *
X */
Xname letter_c
Xdifference
X list
X cylinder 1 0 0 -1.0 0 0 1.0
X disc 1 0 0 -1.0 0 0 -1
X disc 1 0 0 1.0 0 0 1
X end
X union
X list
X cylinder 0.55 0 0 -1.2 0 0 1.2
X disc 0.55 0 0 -1.2 0 0 -1
X disc 0.55 0 0 1.2 0 0 1
X end
X box 0. -.3 -1.2 1.2 0.3 1.2
X end
Xend
X
X
Xname s1 /* outer top part of s */
Xlist
X cylinder 0.6125 -0.3875 0.3875 -1.0 -0.3875 0.3875 1.0
X disc 0.6125 -0.3875 0.3875 -1.0 0 0 -1
X disc 0.6125 -0.3875 0.3875 1.0 0 0 1
X cylinder 0.6125 0.3875 -0.3875 -1.0 0.3875 -0.3875 1.0
X disc 0.6125 0.3875 -0.3875 -1.0 0 0 -1
X disc 0.6125 0.3875 -0.3875 1.0 0 0 1
Xend
X
Xname s3 /* all inner part of s */
Xunion
X list
X cylinder 0.1625 -0.3875 0.3875 -1.2 -0.3875 0.3875 1.2
X disc 0.1625 -0.3875 0.3875 -1.2 0 0 -1
X disc 0.1625 -0.3875 0.3875 1.2 0 0 1
X cylinder 0.1625 0.3875 -0.3875 -1.2 0.3875 -0.3875 1.2
X disc 0.1625 0.3875 -0.3875 -1.2 0 0 -1
X disc 0.1625 0.3875 -0.3875 1.2 0 0 1
X end
X box -.3875 -1.2 -1.2 .3875 1.2 1.2
Xend
X
Xname letter_s
Xunion
X union
X union
X difference
X object s1
X object s3
X end
X
X box -0.3875 0.55 -1 1 1 1
X end
X box -0.3875 -0.225 -1 0.3875 0.225 1
X end
X box -1 -1 -1 0.3875 -0.55 1
Xend
X
X
Xname g3 /*all inner of g */
Xunion
X list
X cylinder 0.55 0 0 -1.2 0 0 1.2
X disc 0.55 0 0 -1.2 0 0 -1
X disc 0.55 0 0 1.2 0 0 1
X end
X box 0. 0. -1.2 1.2 0.425 1.2
Xend
X
Xname letter_g
Xunion
X difference
X list /* outer part of g */
X cylinder 1.0 0 0 -1.0 0 0 1.0
X disc 1 0 0 -1.0 0 0 -1
X disc 1 0 0 1.0 0 0 1
X end
X object g3
X end
X box 0.25 -0.3375 -1.2 1.05 0.1125 1.2
Xend
X
Xname csg
Xdifference
X difference
X object letter_s rotate 1 0 0 90
X object letter_c rotate 1 0 0 90 rotate 0 0 1 90
X scale 1.2 0.8 0.8
X end
X object letter_g scale 0.8 0.8 1.2
X /* scaling here is to avoid coincident surfaces */
Xend
X
Xsurface white ambient .1 .1 .1 diffuse .5 .5 .5
X
Xsurface s1 ambient .5 .4 .3 diffuse .25 .2 .15
Xsurface lgreen ambient .07 .1 .07
X diffuse .42 .6 .42
X specular .28 .4 .28 specpow 10
X
Xplane white 0 0 -3 0 0 1
Xplane white 0 3 0 0 -1 0
Xplane white -3 0 0 1 0 0
X
Xobject s1 csg /* texture wood scale 3 3 3*/
X
Xlight 0.8 directional 0 0 1
Xlight 0.7 directional 0 -1 0
Xlight 0.6 directional 1 0 0
X
Xbackground .1 .3 .8
Xeyep 10. -13 8.
Xlookp 0 0 -0.3
Xup 0 0 1
Xfov 20.
END_OF_FILE
if test 2330 -ne `wc -c <'Examples/csg.ray'`; then
echo shar: \"'Examples/csg.ray'\" unpacked with wrong size!
fi
chmod +x 'Examples/csg.ray'
# end of 'Examples/csg.ray'
fi
if test -f 'Examples/mtv.ray' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Examples/mtv.ray'\"
else
echo shar: Extracting \"'Examples/mtv.ray'\" \(1943 characters\)
sed "s/^X//" >'Examples/mtv.ray' <<'END_OF_FILE'
X/*
X * Logo for a certain drek-filled cable channel.
X * Rod Bogart, 10/90
X */
Xeyep 0 20 8
Xlookp 0 0 3.5
Xfov 30
Xbackground .1 .3 .8
Xlight 1 1 1 directional 0.5 1.5 2
Xscreen 100 100
Xmaxdepth 10
Xsurface red
X ambient .2 .05 .05
X diffuse .8 .1 .05
X specular .05 .05 .05 specpow 20
Xsurface green
X ambient .05 .2 .05
X diffuse .1 .8 .05
X specular .05 .05 .05 specpow 20
Xsurface blue
X ambient .05 .05 .2
X diffuse .1 .1 .8
X specular .05 .05 .05 specpow 20
Xsurface white
X ambient .2 .2 .2
X diffuse 1. 1. 1.
X specular 0.2 0.2 0.2 specpow 18
Xsurface glass
X ambient .02 .02 .02
X diffuse 0.1 0.1 0.1
X specular 0.8 0.8 0.8 specpow 200
X transp 1. index 1.5
Xsurface redglass
X ambient .52 .02 .02
X transp 1. index 1.0
Xsurface greenglass
X ambient .02 .52 .02
X transp 1 index 1.0
Xsurface m_surf specpow 20 specular 1. 1. 1. transp .8 reflect .1 index 1.4
Xsurface tv_surf
X ambient .2 .05 .05
X diffuse .8 .1 .05
X specular .05 .05 .05 specpow 20
Xplane white 0 0 -0.05 0 0 1 texture checker diffuse .8 .1 .05 scale 2 2 2
X
Xname general_cyl
Xlist
X cylinder tv_surf 0.25 0 0 0 0 0 1
X disc tv_surf 0.25 0 0 1 0 0 1
X disc tv_surf 0.25 0 0 0 0 0 -1
Xend
X
Xname thingy
Xgrid 6 6 6
X union /* M */
X list /* m legs */
X box m_surf 1.0 -1 0 4.2 1 7.0
X box m_surf -4.2 -1 0 -1 1 7.0
X /*box m_surf 2.6 0 3.5 1.6 1 3.5
X box m_surf -2.6 0 3.5 1.6 1 3.5 */
X end
X difference
X box m_surf (-4.5^0.5) -1 (-4.5^0.5)
X (4.5^0.5) 1 (4.5^0.5)
X translate (4.5^0.5) 0 (4.5^0.5)
X rotate 0 1 0 -45 translate 0 0 2
X box m_surf -1 -1 -1 1 1 1
X translate 1 0 1
X rotate 0 1 0 -45 translate 0 0 6
X end
X end /* M */
X /* TV */
X object general_cyl scale 1 1 3.6 rotate 0 1 0 -64 translate 0.2 0 3.4
X object general_cyl scale 1 1 4.0 rotate 0 1 0 3 translate -1.8 0 0.9
X object general_cyl scale 1 1 2.7 rotate 0 1 0 15 translate -3.2 0 1.5
X object general_cyl scale 1 1 5.0 rotate 0 1 0 -25 translate -3.2 0 1.5
Xend
X
Xobject thingy rotate 0 0 1 -40
END_OF_FILE
if test 1943 -ne `wc -c <'Examples/mtv.ray'`; then
echo shar: \"'Examples/mtv.ray'\" unpacked with wrong size!
fi
# end of 'Examples/mtv.ray'
fi
if test -f 'etc/malloc.sgi' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'etc/malloc.sgi'\"
else
echo shar: Extracting \"'etc/malloc.sgi'\" \(1812 characters\)
sed "s/^X//" >'etc/malloc.sgi' <<'END_OF_FILE'
X[ Mike Gigante notes that when rendering exteremely large datasets
X (consisting primarily of triangles in his case), one may use the
X 'mallopt()' routine on certain machines to improve performance
X significantly (to say the least). -- CEK ]
X
X
XFrom mg@godzilla.cgl.rmit.OZ.AU Tue Aug 21 14:35:08 1990
XReceived: from godzilla.cgl.rmit.oz.au by weedeater.math.yale.edu via SMTP; Tue, 21 Aug 90 14:35:08 -0400
XReceived: by godzilla
XDate: Wed, 22 Aug 90 05:16:40 EST
XFrom: mg@godzilla.cgl.rmit.OZ.AU (Mike Gigante)
XMessage-Id: <9008211916.4715@godzilla>
XTo: craig@weedeater.math.yale.edu
XSubject: malloc stuff
XStatus: RO
X
XCraig,
Xwe spoke after the ray tracing sig about malloc stuff. Here is that
Xstuff I promised to send you.
X
X1) include <malloc.h> in your main program
X2) make the following code the *first* executable statements
X
X#ifdef sgi
X /*
X * try to tune the malloc stuff. First thing to note is that most
X * allocated blocks (at least for triangles) are less than 200 bytes...
X */
X mallopt(M_MXFAST, 200);
X /*
X * allocate a big chunk at a time - esp since we are going to use LOTS
X * of memory!
X */
X mallopt(M_BLKSZ, 65536);
X /*
X * don't try too hard when looking for free'd memory to re-use. This
X * avoids the heavy paging penalty we have seen... In fact don't look
X * at all!
X */
X mallopt(M_MXCHK, 0);
X#endif
X
Xand wow! *HUGE* improvments for large models. Just to remind you, it was
Xa difference of 88 min CPU time over 10 hour period (just to read a model)
Xvs about 2 minutes cpu/elapsed. Because of the M_MXCHK call, the working
Xset was larger but it didn't make much difference..
X
XBTW, you should check the 200 bytes in the M_MXFAST call. Make it larger
Xthan the common malloc sizes (say for mallocing triangle/poly structs).
X
XHope this is useful.
X
XMike Gigante, RMIT
END_OF_FILE
if test 1812 -ne `wc -c <'etc/malloc.sgi'`; then
echo shar: \"'etc/malloc.sgi'\" unpacked with wrong size!
fi
# end of 'etc/malloc.sgi'
fi
if test -f 'libray/libcommon/common.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libcommon/common.h'\"
else
echo shar: Extracting \"'libray/libcommon/common.h'\" \(2162 characters\)
sed "s/^X//" >'libray/libcommon/common.h' <<'END_OF_FILE'
X/*
X * common.h
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: common.h,v 4.0 91/07/17 14:30:18 kolb Exp Locker: kolb $
X *
X * $Log: common.h,v $
X * Revision 4.0 91/07/17 14:30:18 kolb
X * Initial version.
X *
X */
X#ifndef COMMON_H
X#define COMMON_H
X
X#include <stdio.h>
X#include <math.h>
X#ifdef I_STDLIB
X#include <stdlib.h>
X#endif
X#include "config.h"
X
Xtypedef double Float;
X
X#if (VOIDFLAGS & 8) == 8
Xtypedef void * voidstar;
X#else
Xtypedef char * voidstar;
X#endif
X
X#include "expr.h"
X#include "vector.h"
X#include "ray.h"
X#include "color.h"
X#include "transform.h"
X#include "error.h"
X
X#ifndef TRUE
X#define TRUE 1
X#endif
X
X#ifndef FALSE
X#define FALSE 0
X#endif
X
X/*
X * Various useful constants and macros.
X */
X#ifndef PI
X#define PI 3.14159265358979323846
X#endif
X#define TWOPI (2. * PI)
X#define INV_TWOPI (1. / TWOPI)
X#define deg2rad(x) (Float)(x * PI/180.)
X#define LNHALF (-.69314718)
X
X#ifndef NULL
X# define NULL 0
X#endif
X
X#define UNSET -1
X
X/*
X * Some systems, such as the RS6000, have fast fabs already defined.
X */
X#ifndef fabs
Xextern Float RSabstmp;
X#define fabs(x) ((RSabstmp=x) < 0 ? -RSabstmp : RSabstmp)
X#endif
X
X#ifdef MULTIMAX
X/*
X * On the multimax, allocate large pieces of memory as shared memory.
X */
Xextern char *share_malloc(), *share_calloc();
X#else
X/*
X * Otherwise, malloc is malloc, etc.
X */
X#define share_malloc(x) Malloc(x)
X#define share_calloc(x,y) Calloc(x,y)
X#endif
X
X/*
X * Close enough for us.
X */
X#define equal(a, b) (fabs((a) - (b)) < 0.000001)
X/*
X * Maximum/Minimum functions
X */
X#define max(a, b) ((a) > (b) ? (a) : (b))
X#define min(a, b) ((a) < (b) ? (a) : (b))
X
Xextern voidstar Malloc(), Calloc();
Xextern char *strsave();
Xextern double drand48(); /* just in case */
X
X#endif /* COMMON_H */
END_OF_FILE
if test 2162 -ne `wc -c <'libray/libcommon/common.h'`; then
echo shar: \"'libray/libcommon/common.h'\" unpacked with wrong size!
fi
# end of 'libray/libcommon/common.h'
fi
if test -f 'libray/libcommon/rotate.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libcommon/rotate.c'\"
else
echo shar: Extracting \"'libray/libcommon/rotate.c'\" \(2419 characters\)
sed "s/^X//" >'libray/libcommon/rotate.c' <<'END_OF_FILE'
X/*
X * rotate.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: rotate.c,v 4.0 91/07/17 14:31:18 kolb Exp Locker: kolb $
X *
X * $Log: rotate.c,v $
X * Revision 4.0 91/07/17 14:31:18 kolb
X * Initial version.
X *
X */
X#include "common.h"
X#include "rotate.h"
X
XTransMethods *iRotateMethods;
Xvoid RotationMatrix();
X
XRotate *
XRotateCreate()
X{
X Rotate *res;
X
X res = (Rotate *)Malloc(sizeof(Rotate));
X res->x = res->y = res->theta = 0.;
X res->z = 1.;
X return res;
X}
X
XTransMethods *
XRotateMethods()
X{
X if (iRotateMethods == (TransMethods *)NULL) {
X iRotateMethods = (TransMethods *)Malloc(sizeof(TransMethods));
X iRotateMethods->create = (TransCreateFunc *)RotateCreate;
X iRotateMethods->propagate = RotatePropagate;
X }
X return iRotateMethods;
X}
X
Xvoid
XRotatePropagate(rotate, trans, itrans)
XRotate *rotate;
XRSMatrix *trans, *itrans;
X{
X Vector axis;
X
X RotationMatrix(rotate->x, rotate->y, rotate->z, deg2rad(rotate->theta), trans);
X /*
X * Build the inverse...
X */
X MatrixInvert(trans, itrans);
X}
X
Xvoid
XRotationMatrix(x, y, z, theta, trans)
XFloat x, y, z, theta;
XRSMatrix *trans;
X{
X Float n1, n2, n3, sintheta, costheta;
X Vector vector;
X
X MatrixInit(trans);
X vector.x = x;
X vector.y = y;
X vector.z = z;
X
X if (VecNormalize(&vector) == 0.)
X RLerror(RL_WARN, "Degenerate rotation axis.\n");
X
X sintheta = sin(theta);
X costheta = cos(theta);
X
X n1 = vector.x; n2 = vector.y; n3 = vector.z;
X trans->matrix[0][0] = (Float)(n1*n1 + (1. - n1*n1)*costheta);
X trans->matrix[0][1] = (Float)(n1*n2*(1 - costheta) + n3*sintheta);
X trans->matrix[0][2] = (Float)(n1*n3*(1 - costheta) - n2*sintheta);
X trans->matrix[1][0] = (Float)(n1*n2*(1 - costheta) - n3*sintheta);
X trans->matrix[1][1] = (Float)(n2*n2 + (1 - n2*n2)*costheta);
X trans->matrix[1][2] = (Float)(n2*n3*(1 - costheta) + n1*sintheta);
X trans->matrix[2][0] = (Float)(n1*n3*(1 - costheta) + n2*sintheta);
X trans->matrix[2][1] = (Float)(n2*n3*(1 - costheta) - n1*sintheta);
X trans->matrix[2][2] = (Float)(n3*n3 + (1 - n3*n3)*costheta);
X}
END_OF_FILE
if test 2419 -ne `wc -c <'libray/libcommon/rotate.c'`; then
echo shar: \"'libray/libcommon/rotate.c'\" unpacked with wrong size!
fi
# end of 'libray/libcommon/rotate.c'
fi
if test -f 'libray/libcommon/transform.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libcommon/transform.h'\"
else
echo shar: Extracting \"'libray/libcommon/transform.h'\" \(1857 characters\)
sed "s/^X//" >'libray/libcommon/transform.h' <<'END_OF_FILE'
X/*
X * transform.h
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: transform.h,v 4.0 91/07/17 14:32:33 kolb Exp Locker: kolb $
X *
X * $Log: transform.h,v $
X * Revision 4.0 91/07/17 14:32:33 kolb
X * Initial version.
X *
X */
X#ifndef TRANSFORM_H
X#define TRANSFORM_H
X
Xtypedef voidstar TransRef;
Xtypedef TransRef TransCreateFunc();
X
X/*
X * Transformation 'matrix'.
X */
Xtypedef struct RSMatrix {
X Float matrix[3][3]; /* Rotation matrix */
X Vector translate; /* Translation */
X} RSMatrix;
X
Xtypedef struct {
X TransRef (*create)(); /* Create it... */
X void (*propagate)(); /* Propagate changes to parameters */
X} TransMethods;
X
X/*
X * Transformation structure
X */
Xtypedef struct Trans {
X TransRef tr; /* transform data */
X TransMethods *methods; /* transform methods */
X ExprAssoc *assoc; /* animated parameters */
X short animated; /* is the transformation animated? */
X RSMatrix trans, /* object space --> world space */
X itrans; /* worldspace --> object space */
X struct Trans *next, *prev;
X} Trans;
X
Xextern void MatrixMult(), MatrixCopy(), MatrixInit(), MatrixInvert(),
X TransCopy(), TransInit(), TransInvert(),
X TransCompose(),
X VecTransform(), PointTransform(), NormalTransform();
X
Xextern Trans *TransCreate();
X
Xextern RSMatrix *MatrixCreate();
X
Xvoid RotationMatrix(), TranslationMatrix(),
X ScaleMatrix(), ArbitraryMatrix(), CoordSysTransform();
Xextern Float RayTransform();
X
X#endif /* TRANSFORM_H */
END_OF_FILE
if test 1857 -ne `wc -c <'libray/libcommon/transform.h'`; then
echo shar: \"'libray/libcommon/transform.h'\" unpacked with wrong size!
fi
# end of 'libray/libcommon/transform.h'
fi
if test -f 'libray/libcommon/vector.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libcommon/vector.h'\"
else
echo shar: Extracting \"'libray/libcommon/vector.h'\" \(2301 characters\)
sed "s/^X//" >'libray/libcommon/vector.h' <<'END_OF_FILE'
X/*
X * vector.h
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: vector.h,v 4.0 91/07/17 14:33:11 kolb Exp Locker: kolb $
X *
X * $Log: vector.h,v $
X * Revision 4.0 91/07/17 14:33:11 kolb
X * Initial version.
X *
X */
X#ifndef VECTOR_H
X#define VECTOR_H
X/*
X * Constants used in projecting onto planes
X */
X#define XNORMAL (char)0
X#define YNORMAL (char)1
X#define ZNORMAL (char)2
X
X/*
X * Minimum vector length
X */
X#define EPSILON (Float)0.00001
X/*
X * Maximum length
X */
X#define FAR_AWAY 1.0E+14
X
Xtypedef struct {
X Float u, v; /* 2D point */
X} Vec2d;
X
Xtypedef struct Vector {
X Float x, y, z; /* 3D point */
X} Vector;
X
X/*
X * Linked list of points
X */
Xtypedef struct PointList {
X Vector vec; /* Vector data */
X struct PointList *next; /* Next in list */
X} PointList;
X
X/*
X * Project a point in 3-space to the plane whose normal is indicated by "i."
X */
X#define VecProject(r, p, i) {switch(i) { \
X case XNORMAL: \
X r.u = (p).y; \
X r.v = (p).z; \
X break; \
X case YNORMAL: \
X r.u = (p).x; \
X r.v = (p).z; \
X break; \
X case ZNORMAL: \
X r.u = (p).x; \
X r.v = (p).y; \
X break; \
X } }
X
X#define dotp(a, b) (((a)->x*(b)->x)+((a)->y*(b)->y)+((a)->z*(b)->z))
X#define VecSub(a,b,r) (r)->x=(a).x-(b).x,(r)->y=(a).y-(b).y,(r)->z=(a).z-(b).z
X#define VecAdd(a,b,r) (r)->x=(a).x+(b).x,(r)->y=(a).y+(b).y,(r)->z=(a).z+(b).z
X#define VecScale(s,a,r) (r)->x=(s)*(a).x,(r)->y=(s)*(a).y,(r)->z=(s)*(a).z
X#define VecComb(s1,v1,s2,v2,r) (r)->x = (s1)*(v1).x + (s2)*(v2).x, \
X (r)->y = (s1)*(v1).y + (s2)*(v2).y, \
X (r)->z = (s1)*(v1).z + (s2)*(v2).z
X#define VecAddScaled(v1,s,v2,r) (r)->x = (v1).x + (s)*(v2).x, \
X (r)->y = (v1).y + (s)*(v2).y, \
X (r)->z = (v1).z + (s)*(v2).z
X
Xextern void VecCross(), VecCoordSys(), MakeBump();
Xextern Float VecNormCross(), VecNormalize();
Xextern int Refract();
X
X#endif /* VECTOR_H */
END_OF_FILE
if test 2301 -ne `wc -c <'libray/libcommon/vector.h'`; then
echo shar: \"'libray/libcommon/vector.h'\" unpacked with wrong size!
fi
# end of 'libray/libcommon/vector.h'
fi
if test -f 'libray/liblight/jittered.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/liblight/jittered.c'\"
else
echo shar: Extracting \"'libray/liblight/jittered.c'\" \(1905 characters\)
sed "s/^X//" >'libray/liblight/jittered.c' <<'END_OF_FILE'
X/*
X * jittered.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: jittered.c,v 4.0 91/07/17 14:34:43 kolb Exp Locker: kolb $
X *
X * $Log: jittered.c,v $
X * Revision 4.0 91/07/17 14:34:43 kolb
X * Initial version.
X *
X */
X#include "light.h"
X#include "jittered.h"
X
Xstatic LightMethods *iJitteredMethods = NULL;
X
XJittered *
XJitteredCreate(pos, e1, e2)
XVector *pos, *e1, *e2;
X{
X Jittered *j;
X
X j = (Jittered *)share_malloc(sizeof(Jittered));
X
X j->pos = *pos;
X j->e1 = *e1;
X j->e2 = *e2;
X
X return j;
X}
X
XLightMethods *
XJitteredMethods()
X{
X if (iJitteredMethods == (LightMethods *)NULL) {
X iJitteredMethods = LightMethodsCreate();
X iJitteredMethods->intens = JitteredIntens;
X iJitteredMethods->dir = JitteredDirection;
X }
X return iJitteredMethods;
X}
X
Xint
XJitteredIntens(jit, lcolor, cache, ray, dist, noshadow, color)
XJittered *jit;
XColor *lcolor, *color;
XShadowCache *cache;
XRay *ray;
XFloat dist;
Xint noshadow;
X{
X return !Shadowed(color, lcolor, cache, ray, dist, noshadow);
X}
X
Xvoid
XJitteredDirection(lp, pos, dir, dist)
XJittered *lp;
XVector *pos, *dir;
XFloat *dist;
X{
X /*
X * Choose a location with the area define by corner, e1
X * and e2 at which this sample will be taken.
X */
X VecAddScaled(lp->pos, nrand(), lp->e1, &lp->curpos);
X VecAddScaled(lp->curpos, nrand(), lp->e2, &lp->curpos);
X VecSub(lp->curpos, *pos, dir);
X *dist = VecNormalize(dir);
X}
X
XJitteredMethodRegister(meth)
XUserMethodType meth;
X{
X if (iJitteredMethods)
X iJitteredMethods->user = meth;
X}
END_OF_FILE
if test 1905 -ne `wc -c <'libray/liblight/jittered.c'`; then
echo shar: \"'libray/liblight/jittered.c'\" unpacked with wrong size!
fi
# end of 'libray/liblight/jittered.c'
fi
if test -f 'libray/liblight/light.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/liblight/light.c'\"
else
echo shar: Extracting \"'libray/liblight/light.c'\" \(1978 characters\)
sed "s/^X//" >'libray/liblight/light.c' <<'END_OF_FILE'
X/*
X * light.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: light.c,v 4.0 91/07/17 14:35:01 kolb Exp Locker: kolb $
X *
X * $Log: light.c,v $
X * Revision 4.0 91/07/17 14:35:01 kolb
X * Initial version.
X *
X */
X#include "light.h"
X
XLight *
XLightCreate(light, meth, color)
XLightRef light;
XLightMethods *meth;
XColor *color;
X{
X Light *ltmp;
X
X if (light == (LightRef)NULL || meth == (LightMethods *)NULL)
X return (Light *)NULL;
X
X ltmp = (Light *)share_malloc(sizeof(Light));
X ltmp->light = light;
X ltmp->methods = meth;
X ltmp->color = *color;
X ltmp->next = (Light *)NULL;
X ltmp->cache = (ShadowCache *)NULL;
X ltmp->shadow = TRUE;
X return ltmp;
X}
X
XLightMethods *
XLightMethodsCreate()
X{
X return (LightMethods *)share_calloc(1, sizeof(LightMethods));
X}
X
X/*
X * Compute light color. Returns FALSE if in full shadow, TRUE otherwise.
X * Computed light color is stored in 'color'.
X */
Xint
XLightIntens(lp, ray, dist, noshadow, color)
XLight *lp;
XRay *ray;
XFloat dist;
Xint noshadow;
XColor *color;
X{
X if (lp->methods->intens)
X return (*lp->methods->intens)(lp->light, &lp->color,
X lp->cache, ray, dist, noshadow || !lp->shadow, color);
X RLerror(RL_ABORT, "Cannot compute light intensity!\n");
X return FALSE;
X}
X
X/*
X * Calculate ray and distance from position to light.
X */
Xint
XLightDirection(lp, objpos, lray, dist)
XLight *lp;
XVector *objpos, *lray;
XFloat *dist;
X{
X if (lp->methods->dir) {
X (*lp->methods->dir)(lp->light, objpos, lray, dist);
X return TRUE;
X } else {
X RLerror(RL_ABORT, "Cannot compute light direction!\n");
X return FALSE;
X }
X}
END_OF_FILE
if test 1978 -ne `wc -c <'libray/liblight/light.c'`; then
echo shar: \"'libray/liblight/light.c'\" unpacked with wrong size!
fi
# end of 'libray/liblight/light.c'
fi
if test -f 'libray/liblight/light.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/liblight/light.h'\"
else
echo shar: Extracting \"'libray/liblight/light.h'\" \(2038 characters\)
sed "s/^X//" >'libray/liblight/light.h' <<'END_OF_FILE'
X/*
X * light.h
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: light.h,v 4.0 91/07/17 14:35:10 kolb Exp Locker: kolb $
X *
X * $Log: light.h,v $
X * Revision 4.0 91/07/17 14:35:10 kolb
X * Initial version.
X *
X */
X#ifndef LIGHT_H
X#define LIGHT_H
X
X#include "libobj/geom.h"
X
X#define SHADOW_NONE 001
X#define SHADOW_TRANSP 002
X#define SHADOW_CSG 004
X#define SHADOW_CACHE 010
X#define SHADOW_BLUR 020
X
X#define NOSHADOWS(f) ((f) & SHADOW_NONE)
X#define SHADOWTRANSP(f) ((f) & SHADOW_TRANSP)
X#define SHADOWCSG(f) ((f) & SHADOW_CSG)
X#define SHADOWCACHE(f) ((f) & SHADOW_CACHE)
X#define SHADOWBLUR(f) ((f) & SHADOW_BLUR)
X
X#define SHADOW_EPSILON (4. * EPSILON)
X
Xtypedef char * LightRef;
X
Xtypedef struct {
X struct Geom *obj; /* Pointer to cached object */
X RSMatrix trans; /* World-to-object transformation */
X char dotrans; /* TRUE if above trans is non-identity */
X} ShadowCache;
X
Xtypedef struct {
X int (*intens)(); /* intensity method */
X void (*dir)(), /* direction method */
X (*user)(); /* user-defined method */
X} LightMethods;
X
Xtypedef struct Light {
X Color color; /* Light source color & intensity */
X int shadow; /* Does light source cast shadows? */
X LightRef light; /* Pointer to light information */
X LightMethods *methods; /* Light source methods */
X ShadowCache *cache; /* Shadow cache, if any */
X struct Light *next; /* Next light in list */
X} Light;
X
Xextern LightMethods *LightMethodsCreate();
Xextern Light *LightCreate();
Xextern void LightAllocateCache(), LightAddToDefined();
Xextern int LightIntens(), LightDirection();
Xextern void ShadowSetOptions(), ShadowStats();
X
X#endif /* LIGHT_H */
END_OF_FILE
if test 2038 -ne `wc -c <'libray/liblight/light.h'`; then
echo shar: \"'libray/liblight/light.h'\" unpacked with wrong size!
fi
# end of 'libray/liblight/light.h'
fi
if test -f 'libray/libobj/instance.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libobj/instance.c'\"
else
echo shar: Extracting \"'libray/libobj/instance.c'\" \(2473 characters\)
sed "s/^X//" >'libray/libobj/instance.c' <<'END_OF_FILE'
X/*
X * instance.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: instance.c,v 4.0 91/07/17 14:38:26 kolb Exp Locker: kolb $
X *
X * $Log: instance.c,v $
X * Revision 4.0 91/07/17 14:38:26 kolb
X * Initial version.
X *
X */
X#include "geom.h"
X#include "instance.h"
X
Xstatic Methods *iInstanceMethods = NULL;
Xstatic char instanceName[] = "instance";
X
XInstance *
XInstanceCreate(obj)
XGeom *obj;
X{
X Instance *inst;
X
X if (obj == (Geom *)NULL) {
X RLerror(RL_WARN, "Instance of NULL?\n");
X return (Instance *)NULL;
X }
X inst = (Instance *)share_malloc(sizeof(Instance));
X inst->obj = obj;
X BoundsCopy(obj->bounds, inst->bounds);
X return inst;
X}
X
Xchar *
XInstanceName()
X{
X return instanceName;
X}
X
X
X/*
X * Intersect ray & an instance by calling intersect.
X */
Xint
XInstanceIntersect(inst, ray, hitlist, mindist, maxdist)
XInstance *inst;
XRay *ray;
XHitList *hitlist;
XFloat mindist, *maxdist;
X{
X return intersect(inst->obj, ray, hitlist, mindist, maxdist);
X}
X
XMethods *
XInstanceMethods()
X{
X /*
X * Instances are special in that there is no
X * "convert" method -- when created, they are passed
X * a pointer to the object being instantiated.
X * This means that you will need to set an instance's
X * 'prims' field by hand (e.g., inst->prims = object->prims).
X */
X if (iInstanceMethods == (Methods *)NULL) {
X iInstanceMethods = MethodsCreate();
X iInstanceMethods->methods = InstanceMethods;
X iInstanceMethods->create = (GeomCreateFunc *)InstanceCreate;
X iInstanceMethods->name = InstanceName;
X iInstanceMethods->intersect = InstanceIntersect;
X iInstanceMethods->bounds = InstanceBounds;
X iInstanceMethods->convert = (voidstar)NULL;
X iInstanceMethods->checkbounds = FALSE;
X iInstanceMethods->closed = TRUE;
X }
X return iInstanceMethods;
X}
X
Xvoid
XInstanceBounds(inst, bounds)
XInstance *inst;
XFloat bounds[2][3];
X{
X GeomComputeBounds(inst->obj);
X BoundsCopy(inst->obj->bounds, inst->bounds);
X BoundsCopy(inst->bounds, bounds);
X}
X
Xvoid
XInstanceMethodRegister(meth)
XUserMethodType meth;
X{
X if (iInstanceMethods)
X iInstanceMethods->user = meth;
X}
END_OF_FILE
if test 2473 -ne `wc -c <'libray/libobj/instance.c'`; then
echo shar: \"'libray/libobj/instance.c'\" unpacked with wrong size!
fi
# end of 'libray/libobj/instance.c'
fi
if test -f 'libray/libsurf/atmosphere.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libsurf/atmosphere.c'\"
else
echo shar: Extracting \"'libray/libsurf/atmosphere.c'\" \(1801 characters\)
sed "s/^X//" >'libray/libsurf/atmosphere.c' <<'END_OF_FILE'
X/*
X * atmosphere.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: atmosphere.c,v 4.0 91/07/17 14:40:02 kolb Exp Locker: kolb $
X *
X * $Log: atmosphere.c,v $
X * Revision 4.0 91/07/17 14:40:02 kolb
X * Initial version.
X *
X */
X#include "atmosphere.h"
X
XAtmosphere *
XAtmosCreate(data, method)
Xchar *data;
Xvoid (*method)();
X{
X Atmosphere *ef;
X
X ef = (Atmosphere *)Malloc(sizeof(Atmosphere));
X ef->data = data;
X ef->method = method;
X ef->next = (Atmosphere *)0;
X return ef;
X}
X
XAtmosphere *
XAtmosphereCopy(atmos)
XAtmosphere *atmos;
X{
X Atmosphere *res;
X
X if (atmos == (Atmosphere *)NULL)
X return (Atmosphere *)NULL;
X res = AtmosCreate(atmos->data, atmos->method);
X res->next = AtmosphereCopy(atmos->next);
X return res;
X}
X
XMedium *
XMediumPush(index, statten, media)
XFloat index, statten;
XMedium *media;
X{
X Medium *new;
X
X new = (Medium *)Malloc(sizeof(Medium));
X new->index = index;
X new->statten = statten;
X new->next = media;
X
X return new;
X}
X
Xvoid
XAtmospherics(effects, ray, dist, pos, color)
XAtmosphere *effects;
XRay *ray;
XFloat dist;
XVector *pos;
XColor *color;
X{
X Atmosphere *etmp;
X
X for (etmp = effects; etmp; etmp = etmp->next)
X (*etmp->method)(etmp->data, ray, pos, dist, color);
X}
X
XFloat
XExpAtten(dist, trans)
XFloat dist, trans;
X{
X Float atten;
X
X if (trans < EPSILON)
X return 0.;
X atten = LNHALF * dist / trans;
X return (atten < -10. ? 0. : exp(atten));
X}
END_OF_FILE
if test 1801 -ne `wc -c <'libray/libsurf/atmosphere.c'`; then
echo shar: \"'libray/libsurf/atmosphere.c'\" unpacked with wrong size!
fi
# end of 'libray/libsurf/atmosphere.c'
fi
if test -f 'libray/libsurf/surface.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libsurf/surface.h'\"
else
echo shar: Extracting \"'libray/libsurf/surface.h'\" \(1924 characters\)
sed "s/^X//" >'libray/libsurf/surface.h' <<'END_OF_FILE'
X/*
X * surface.h
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: surface.h,v 4.0 91/07/17 14:41:02 kolb Exp Locker: kolb $
X *
X * $Log: surface.h,v $
X * Revision 4.0 91/07/17 14:41:02 kolb
X * Initial version.
X *
X */
X#ifndef SURFACE_H
X#define SURFACE_H
X
X#define DEFAULT_INDEX 1.0 /* Default index of refraction */
X#define DEFAULT_PHONGPOW 15.0 /* Default specular highlight exp */
X
X/*
X * Surface definition.
X */
Xtypedef struct Surface {
X char *name; /* Name */
X struct Color amb, /* Ambient 'curve' */
X diff, /* Diffuse reflection 'curve' */
X spec, /* Specular reflection 'curve' */
X translu, /* Diffuse transmission 'curve' */
X body; /* Specular transmission 'curve' */
X Float srexp, /* Specular reflection exponent */
X stexp, /* Specular transmission exponent */
X statten, /* Specular transmission attenuation */
X index, /* Index of refraction */
X reflect, /* Specular reflectivity */
X transp, /* Specular transmittance */
X translucency; /* Diffuse transmittance */
X char noshadow; /* No shadowing? */
X struct Surface *next; /* Next surface in list (if any) */
X} Surface;
X
X/*
X * Linked list of (linked list of) surfaces.
X */
Xtypedef struct SurfList {
X Surface *surf;
X struct SurfList *next;
X} SurfList;
X
Xextern Surface *SurfaceCreate(),
X *GetShadingSurf(), /* application-provided */
X *SurfaceCopy();
X
Xextern SurfList *SurfPop(), *SurfPush();
X
Xextern void SurfaceBlend(), ColorBlend();
X
Xextern int ComputeSurfProps();
X
X#endif /* SURFACE_H */
END_OF_FILE
if test 1924 -ne `wc -c <'libray/libsurf/surface.h'`; then
echo shar: \"'libray/libsurf/surface.h'\" unpacked with wrong size!
fi
# end of 'libray/libsurf/surface.h'
fi
if test -f 'libray/libtext/fbm.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libtext/fbm.c'\"
else
echo shar: Extracting \"'libray/libtext/fbm.c'\" \(1951 characters\)
sed "s/^X//" >'libray/libtext/fbm.c' <<'END_OF_FILE'
X/*
X * fbm.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: fbm.c,v 4.0 91/07/17 14:42:06 kolb Exp Locker: kolb $
X *
X * $Log: fbm.c,v $
X * Revision 4.0 91/07/17 14:42:06 kolb
X * Initial version.
X *
X */
X#include "texture.h"
X#include "fbm.h"
X
XFBm *
XFBmCreate(offset, scale, h, lambda, octaves, thresh, mapname)
XFloat h, lambda, scale, offset, thresh;
Xint octaves;
Xchar *mapname;
X{
X FBm *fbm;
X
X fbm = (FBm *)Malloc(sizeof(FBm));
X
X fbm->beta = 1. + 2*h;
X fbm->omega = pow(lambda, -0.5*fbm->beta);
X fbm->lambda = lambda;
X fbm->scale = scale;
X fbm->offset = offset;
X fbm->thresh = thresh;
X fbm->octaves = octaves;
X if (mapname != (char *)NULL)
X fbm->colormap = ColormapRead(mapname);
X else
X fbm->colormap = (Color *)NULL;
X return fbm;
X}
X
Xvoid
XFBmApply(fbm, prim, ray, pos, norm, gnorm, surf)
XFBm *fbm;
XGeom *prim;
XRay *ray;
XVector *pos, *norm, *gnorm;
XSurface *surf;
X{
X Float val;
X int index;
X
X val = fBm(pos, fbm->omega, fbm->lambda, fbm->octaves);
X if (val < fbm->thresh)
X val = fbm->offset;
X else
X val = fbm->offset + fbm->scale*(val - fbm->thresh);
X if (fbm->colormap) {
X index = 255. * val;
X if (index > 255) index = 255;
X if (index < 0) index = 0;
X surf->diff.r *= fbm->colormap[index].r;
X surf->diff.g *= fbm->colormap[index].g;
X surf->diff.b *= fbm->colormap[index].b;
X surf->amb.r *= fbm->colormap[index].r;
X surf->amb.g *= fbm->colormap[index].g;
X surf->amb.b *= fbm->colormap[index].b;
X } else {
X ColorScale(val, surf->diff, &surf->diff);
X ColorScale(val, surf->amb, &surf->amb);
X }
X}
END_OF_FILE
if test 1951 -ne `wc -c <'libray/libtext/fbm.c'`; then
echo shar: \"'libray/libtext/fbm.c'\" unpacked with wrong size!
fi
# end of 'libray/libtext/fbm.c'
fi
if test -f 'libray/libtext/texture.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libtext/texture.h'\"
else
echo shar: Extracting \"'libray/libtext/texture.h'\" \(2381 characters\)
sed "s/^X//" >'libray/libtext/texture.h' <<'END_OF_FILE'
X/*
X * texture.h
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: texture.h,v 4.0 91/07/17 14:44:19 kolb Exp Locker: kolb $
X *
X * $Log: texture.h,v $
X * Revision 4.0 91/07/17 14:44:19 kolb
X * Initial version.
X *
X */
X#ifndef TEXTURE_H
X#define TEXTURE_H
X
X#include "libobj/geom.h"
X#include "libsurf/surface.h"
X#include "mapping.h"
X
X/*
X * Surface properties
X */
X#define COLOR 0 /* AMBIENT, DIFFUSE, SPECULAR and BODY */
X#define AMBIENT 1
X#define DIFFUSE 2
X#define SPECULAR 3
X#define BODY 4
X#define REFLECT 5
X#define TRANSP 6
X#define SPECPOW 7
X#define BUMP 8
X#define INDEX 9
X
X#define TextPointToModel(p) PointTransform(p, &model2text.itrans)
X#define TextPointToPrim(p) PointTransform(p, &prim2text.itrans)
X#define TextPointToWorld(p) PointTransform(p, &world2text.itrans)
X#define TextRayToModel(p) RayTransform(r, &model2text.itrans)
X#define TextRayToPrim(r) RayTransform(r, &prim2text.itrans)
X#define TextRayToWorld(r) RayTransform(r, &world2text.itrans)
X#define TextNormToModel(n) NormalTransform(n, &model2text.trans)
X#define TextNormToPrim(n) NormalTransform(n, &prim2text.trans)
X#define TextNormToWorld(n) NormalTransform(n, &world2text.trans)
X
X#define ModelPointToText(p) PointTransform(p, &model2text.trans)
X#define ModelNormToText(n) NormalTransform(n, &model2text.itrans)
X#define ModelRayToText(r) RayTransform(r, &model2text.trans)
X
Xtypedef char *TextRef;
X
X/*
X * Texture structure
X */
Xtypedef struct Texture {
X TextRef data; /* Texturing info */
X void (*method)(); /* method */
X Trans *trans; /* transformation info */
X short animtrans; /* is the transformation animated? */
X struct Texture *next; /* next in list */
X} Texture;
X
Xextern Texture *TextCreate(), *TextAppend();
Xextern void DNoise3(), VfBm(), TextApply(), MakeBump(), Wrinkled();
Xextern Float Noise3(), Noise2(), Chaos(), Marble(), fBm();
Xextern int TileValue();
XColor *ColormapRead();
X
Xextern Trans model2text, prim2text, world2text;
X
X#endif TEXTURE_H
END_OF_FILE
if test 2381 -ne `wc -c <'libray/libtext/texture.h'`; then
echo shar: \"'libray/libtext/texture.h'\" unpacked with wrong size!
fi
# end of 'libray/libtext/texture.h'
fi
if test -f 'libray/libtext/wood.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libray/libtext/wood.c'\"
else
echo shar: Extracting \"'libray/libtext/wood.c'\" \(1805 characters\)
sed "s/^X//" >'libray/libtext/wood.c' <<'END_OF_FILE'
X/*
X * wood.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb, Robert F. Skinner
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: wood.c,v 4.0 91/07/17 14:44:35 kolb Exp Locker: kolb $
X *
X * $Log: wood.c,v $
X * Revision 4.0 91/07/17 14:44:35 kolb
X * Initial version.
X *
X */
X#include "texture.h"
X#include "wood.h"
X
XWood *
XWoodCreate()
X{
X return (Wood *)NULL; /* No data associated with wood texture */
X}
X
X/*ARGSUSED*/
Xvoid
XWoodApply(wood, prim, ray, pos, norm, gnorm, surf)
XWood *wood;
XGeom *prim;
XRay *ray;
XVector *pos, *norm, *gnorm;
XSurface *surf;
X{
X Float red, grn, blu;
X Float chaos, brownLayer, greenLayer;
X Float perturb, brownPerturb, greenPerturb, grnPerturb;
X Float t;
X
X chaos = Chaos(pos, 7);
X t = sin(sin(8.*chaos + 7*pos->x +3.*pos->y));
X
X greenLayer = brownLayer = fabs(t);
X
X perturb = sin(40.*chaos + 50.*pos->z);
X perturb = fabs(perturb);
X
X brownPerturb = .6*perturb + 0.3;
X greenPerturb = .2*perturb + 0.8;
X grnPerturb = .15*perturb + 0.85;
X grn = 0.5 * pow(fabs(brownLayer), 0.3);
X brownLayer = pow(0.5 * (brownLayer+1.0), 0.6) * brownPerturb;
X greenLayer = pow(0.5 * (greenLayer+1.0), 0.6) * greenPerturb;
X
X red = (0.5*brownLayer + 0.35*greenLayer)*2.*grn;
X blu = (0.25*brownLayer + 0.35*greenLayer)*2.0*grn;
X grn *= max(brownLayer, greenLayer) * grnPerturb;
X
X surf->diff.r *= red;
X surf->diff.g *= grn;
X surf->diff.b *= blu;
X surf->amb.r *= red;
X surf->amb.g *= grn;
X surf->amb.b *= blu;
X}
END_OF_FILE
if test 1805 -ne `wc -c <'libray/libtext/wood.c'`; then
echo shar: \"'libray/libtext/wood.c'\" unpacked with wrong size!
fi
# end of 'libray/libtext/wood.c'
fi
if test -f 'libshade/objdef.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libshade/objdef.c'\"
else
echo shar: Extracting \"'libshade/objdef.c'\" \(2418 characters\)
sed "s/^X//" >'libshade/objdef.c' <<'END_OF_FILE'
X/*
X * objdef.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: objdef.c,v 4.0 91/07/17 14:46:38 kolb Exp Locker: kolb $
X *
X * $Log: objdef.c,v $
X * Revision 4.0 91/07/17 14:46:38 kolb
X * Initial version.
X *
X */
X
X#include "rayshade.h"
X#include "options.h"
X#include "stats.h"
X
Xstatic Geom *Objects = NULL; /* named objects */
XGeom *World; /* top-level object */
X
X
X/*
X * Return pointer to named object, NULL if no such object has been defined.
X */
XGeom *
XGeomGetNamed(name)
Xchar *name;
X{
X Geom *otmp;
X for (otmp = Objects; otmp; otmp = otmp->next)
X if (strcmp(name, otmp->name) == 0)
X return otmp;
X return (Geom *)NULL;
X}
X
X/*
X * Add object to list of defined objects. At this point, the object has
X * been converted to the correct type, and obj->next is either NULL or
X * garbage.
X */
Xvoid
XGeomAddToDefined(obj)
XGeom *obj;
X{
X obj->next = Objects;
X Objects = obj;
X if (Options.verbose)
X AggregatePrintInfo(obj, Stats.fstats);
X else
X AggregatePrintInfo(obj, (FILE *)NULL);
X}
X
X/*
X * Return a copy of the named object.
X */
XGeom *
XGeomCopyNamed(name)
Xchar *name;
X{
X Geom *child;
X
X child = GeomGetNamed(name);
X if (child == (Geom *)NULL)
X RLerror(RL_PANIC, "There is no object named \"%s\".", name);
X child = GeomCopy(child);
X return child;
X}
X
Xvoid
XWorldSetup()
X{
X extern GeomList *Defstack;
X
X /*
X * Define World object, if not done previously.
X */
X if (World == (Geom *)NULL) {
X World = Defstack->obj; /* World is topmost object on stack */
X if (Defstack->next)
X RLerror(RL_ABORT, "Geom def stack is screwey.\n");
X World->prims = AggregateConvert(World, World->next);
X }
X
X GeomComputeBounds(World);
X
X /*
X * Complain if there are no primitives to be rendered.
X */
X if (World->prims == 0) {
X RLerror(RL_PANIC, "Nothing to be rendered.\n");
X }
X}
X
X/*
X * Main ray-spwaning routine required by libray
X */
Xint
XTraceRay(ray, hitlist, mindist, maxdist)
XRay *ray;
XHitList *hitlist;
XFloat mindist, *maxdist;
X{
X return intersect(World, ray, hitlist, mindist, maxdist);
X}
END_OF_FILE
if test 2418 -ne `wc -c <'libshade/objdef.c'`; then
echo shar: \"'libshade/objdef.c'\" unpacked with wrong size!
fi
# end of 'libshade/objdef.c'
fi
if test -f 'rayshade/main.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rayshade/main.c'\"
else
echo shar: Extracting \"'rayshade/main.c'\" \(2468 characters\)
sed "s/^X//" >'rayshade/main.c' <<'END_OF_FILE'
X/*
X * main.c
X *
X * Copyright (C) 1989, 1991, Craig E. Kolb
X * All rights reserved.
X *
X * This software may be freely copied, modified, and redistributed
X * provided that this copyright notice is preserved on all copies.
X *
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 *
X * There is no warranty or other guarantee of fitness of this software
X * for any purpose. It is provided solely "as is".
X *
X * $Id: main.c,v 4.0 91/07/17 14:50:39 kolb Exp Locker: kolb $
X *
X * $Log: main.c,v $
X * Revision 4.0 91/07/17 14:50:39 kolb
X * Initial version.
X *
X */
X
Xchar rcsid[] = "$Id: main.c,v 4.0 91/07/17 14:50:39 kolb Exp Locker: kolb $";
X
X#include "rayshade.h"
X#include "options.h"
X#include "stats.h"
X#include "viewing.h"
X#include "picture.h"
X
Xint
X#ifdef LINDA
Xrayshade_main(argc, argv)
X#else
Xmain(argc, argv)
X#endif
Xint argc;
Xchar **argv;
X{
X Float utime, stime, lasttime;
X int i;
X extern Geom *World;
X
X#ifdef LINDA
X Options.workernum = 0; /* we're the supervisor */
X#endif
X
X RSInitialize(argc, argv);
X
X
X /*
X * Start the first frame.
X */
X RSStartFrame(Options.startframe);
X /*
X * Print more information than we'll ever need to know...
X */
X if (Options.verbose) {
X /* World object info. */
X AggregatePrintInfo(World, Stats.fstats);
X /* Print info about rendering options and the like. */
X RSOptionsList();
X }
X /*
X * Start new picture.
X */
X PictureStart(argv);
X /*
X * Print preprocessing time.
X */
X RSGetCpuTime(&utime, &stime);
X fprintf(Stats.fstats,"Preprocessing time:\t");
X fprintf(Stats.fstats,"%2.2fu %2.2fs\n", utime, stime);
X fprintf(Stats.fstats,"Starting trace.\n");
X (void)fflush(Stats.fstats);
X lasttime = utime+stime;
X /*
X * Render the first frame
X */
X raytrace(argc, argv);
X /*
X * Render the remaining frames.
X */
X for (i = Options.startframe +1; i <= Options.endframe ; i++) {
X PictureFrameEnd(); /* End the previous frame */
X RSGetCpuTime(&utime, &stime);
X fprintf(Stats.fstats, "Total CPU time for frame %d: %2.2f \n",
X i - 1, utime+stime - lasttime);
X PrintMemoryStats(Stats.fstats);
X (void)fflush(Stats.fstats);
X lasttime = utime+stime;
X RSStartFrame(i);
X if (Options.verbose) {
X AggregatePrintInfo(World, Stats.fstats);
X (void)fflush(Stats.fstats);
X }
X PictureStart(argv);
X raytrace(argc, argv);
X }
X /*
X * Close the image file.
X */
X PictureFrameEnd(); /* End the last frame */
X PictureEnd();
X StatsPrint();
X return 0;
X}
END_OF_FILE
if test 2468 -ne `wc -c <'rayshade/main.c'`; then
echo shar: \"'rayshade/main.c'\" unpacked with wrong size!
fi
# end of 'rayshade/main.c'
fi
echo shar: End of archive 5 \(of 19\).
cp /dev/null ark5isdone
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
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 19 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
exit 0 # Just in case...