home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-23 | 52.3 KB | 1,632 lines |
- Newsgroups: comp.sources.misc
- From: Jonas Yngvesson <jonas-y@isy.liu.se>
- Subject: v21i026: sipp - A 3D rendering library v2.1, Part01/08
- Message-ID: <csm-v21i026=sipp.130352@sparky.imd.sterling.com>
- X-Md4-Signature: 8900b3d20590050f9deeee26b1d392fb
- Date: Tue, 23 Jul 1991 18:14:40 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: Jonas Yngvesson <jonas-y@isy.liu.se>
- Posting-number: Volume 21, Issue 26
- Archive-name: sipp/part01
- Supersedes: sipp2.0: Volume 16, Issue 5-10
- Environment: UNIX
-
- This is sipp-2.1. A library for rendering scenes with 3d objects.
-
- Changes from previous versions (2.0.*) include:
-
- - Support for more rendering modes: Phong, Gouraud, flat and line.
- Only Phong mode can do real texture mapping though.
-
- - Support for rendering into other places than files. We have chosen
- to call this rendering into pixmaps, but there is no restriction on
- what is really used. This is accomplished through a callback function
- similar to the shader interface. A basic implementation of pixmaps
- and bitmaps that could be used are supplied in the library.
-
- - Oversampling for antialiasing can now be arbitrarily large.
-
- - It is possible to turn off backface culling. This is useful if you
- have a database of objects that are inconsequent in the ordering
- of its vertices (clockwize/counterclockwize).
-
- - Two new object primitives, cone and prism.
- Thanks to David Jones (djones@awesome.berkeley.edu) for these.
-
- - Two new shaders.
- 1. strauss_shader() - This is an implementation of the shading
- model designed by Paul S. Strauss at Silicon Graphics Inc.
- and described in IEEE CG&A November 1990.
- 2. wood_shader() - A shader that simulates wood texture using
- noise and turbulence.
-
- - Matrix and vector handling functions and macros are now "public".
-
- - Correct interpolation of texture coordinates. Previously there
- were disturbing "rubberband" effects on objects spanning large
- depths in the picture.
-
- - A full polygon clipper is now used instead of the previous, rather
- strange approach. Objects behind the viewpoint are now handled correctly
- (I hope), previously they caused strange effects.
-
- - It is possible to get the current transformation matrix from an object
- and not only to set it. This makes it a lot easier to do animations.
-
- - Subobjects and surfaces can now be removed from objects.
-
-
- Thanks everybody who sent bugreports and suggestions for enhancements.
-
- /Jonas Ynvesson & Inge Wallin
-
- #!/bin/sh
- # This is sipp-2.1, a shell archive (produced by shar 3.49)
- # To extract the files from this archive, save it to a file, remove
- # everything above the "!/bin/sh" line above, and type "sh file_name".
- #
- # made 07/20/1991 22:25 UTC by jonas-y@gouraud
- # Source directory /home/driver/jonas-y/sippuz/sipp-2.1
- #
- # existing files will NOT be overwritten unless -c is specified
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 2495 -rw-r--r-- Makefile
- # 2832 -rw-rw-r-- README
- # 1907 -rw-r--r-- CHANGES
- # 346 -rw-rw-r-- TODO
- # 9212 -rw-rw-r-- ChangeLog
- # 3187 -rw-r--r-- libsipp/Makefile
- # 2591 -rw-rw-r-- libsipp/basic_shader.c
- # 13510 -rw-rw-r-- libsipp/bezier.c
- # 1640 -rw-rw-r-- libsipp/bezier.h
- # 1879 -rw-rw-r-- libsipp/bezier_lex.l
- # 1739 -rw-rw-r-- libsipp/bozo.c
- # 1894 -rw-rw-r-- libsipp/bumpy.c
- # 4352 -rw-rw-r-- libsipp/cone.c
- # 4769 -rw-rw-r-- libsipp/ellipsoid.c
- # 10785 -rw-rw-r-- libsipp/geometric.c
- # 4676 -rw-rw-r-- libsipp/geometric.h
- # 2260 -rw-r--r-- libsipp/granite.c
- # 1503 -rw-r--r-- libsipp/lightsource.c
- # 1109 -rw-r--r-- libsipp/lightsource.h
- # 2442 -rw-rw-r-- libsipp/marble.c
- # 1687 -rw-rw-r-- libsipp/mask.c
- # 9232 -rw-rw-r-- libsipp/noise.c
- # 257 -rw-rw-r-- libsipp/noise.h
- # 19672 -rw-r--r-- libsipp/objects.c
- # 1430 -rw-r--r-- libsipp/objects.h
- # 22 -rw-rw-r-- libsipp/patchlevel.h
- # 1700 -rw-rw-r-- libsipp/planet.c
- # 1264 -rw-rw-r-- libsipp/primitives.h
- # 2773 -rw-rw-r-- libsipp/prism.c
- # 39990 -rw-r--r-- libsipp/rendering.c
- # 2300 -rw-r--r-- libsipp/rendering.h
- # 4808 -rw-rw-r-- libsipp/shaders.h
- # 6406 -rw-rw-r-- libsipp/sipp.h
- # 4002 -rw-rw-r-- libsipp/sipp_bitmap.c
- # 1432 -rw-rw-r-- libsipp/sipp_bitmap.h
- # 3142 -rw-rw-r-- libsipp/sipp_pixmap.c
- # 1435 -rw-rw-r-- libsipp/sipp_pixmap.h
- # 1374 -rw-r--r-- libsipp/smalloc.c
- # 1006 -rw-r--r-- libsipp/smalloc.h
- # 5426 -rw-rw-r-- libsipp/strauss.c
- # 3223 -rw-rw-r-- libsipp/torus.c
- # 3036 -rw-r--r-- libsipp/transforms.c
- # 5462 -rw-r--r-- libsipp/viewpoint.c
- # 1666 -rw-r--r-- libsipp/viewpoint.h
- # 4490 -rw-r--r-- libsipp/wood.c
- # 5405 -rw-rw-r-- libsipp/xalloca.c
- # 314 -rw-rw-r-- libsipp/xalloca.h
- # 8030 -rw-r--r-- doc/geometric.man
- # 9152 -rw-rw-r-- doc/primitives.man
- # 13374 -rw-rw-r-- doc/shaders.man
- # 25493 -rw-rw-r-- doc/sipp.man
- # 4438 -rw-r--r-- doc/sipp_pixmap.man
- # 2878 -rw-rw-r-- demo/Makefile
- # 2643 -rw-rw-r-- demo/README
- # 273 -rw-rw-r-- demo/animation/Makefile
- # 5885 -rw-rw-r-- demo/animation/animation.c
- # 608 -rw-rw-r-- demo/animation/README
- # 2581 -rw-rw-r-- demo/chain.c
- # 2027 -rw-rw-r-- demo/conetest.c
- # 1595 -rw-rw-r-- demo/ellipsoid.c
- # 3595 -rw-rw-r-- demo/isy90.c
- # 1633 -rw-rw-r-- demo/planettest.c
- # 2312 -rw-rw-r-- demo/prismtest.c
- # 3272 -rw-r--r-- demo/strausstest.c
- # 3047 -rw-rw-r-- demo/structure.c
- # 2263 -rw-rw-r-- demo/teapot.c
- # 1585 -rw-rw-r-- demo/torustest.c
- # 644 -rw-rw-r-- demo/tpt_body.bez
- # 2371 -rw-rw-r-- demo/tpt_handle.bez
- # 482 -rw-rw-r-- demo/tpt_lid.bez
- # 2358 -rw-rw-r-- demo/tpt_spout.bez
- # 1441 -rw-r--r-- demo/woodtest.c
- #
- # ============= Makefile ==============
- if test -f 'Makefile' -a X"$1" != X"-c"; then
- echo 'x - skipping Makefile (File already exists)'
- else
- echo 'x - extracting Makefile (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
- # sipp - a 3-d rendering library
- #
- # Copyright Inge Wallin, Jonas Yngvesson
- #
- # This is the main Makefile for sipp version 2.1. This directory
- # contains three subdirectories:
- # libsipp: source code for the library itself.
- # demo: source code for demonstrations and tests
- # doc: standard manual pages for the library.
- #
- # You can either make the library and the tests/demos separately or
- # you can make them all in one make session.
- #
- # To create the library, just type 'make library'.
- # To make the demo programs, type 'make demos', but if you haven't
- # made the library first, this will be made automatically for you by
- # the makefile in the demos directory.
- #
- # Before you can make anything, though, you may have to edit the
- # following definitions:
- X
- X
- # If your C compiler doesn't grok the void type, uncomment the
- # following line:
- #NOVOID = -Dvoid=int
- X
- X
- # If you don't have memcpy() and friends in your C library, or
- # if you don't have memory.h in /usr/include, uncomment the
- # following line:
- #NOMEMCPY = -DNOMEMCPY
- X
- X
- # If you don't have alloca(), uncomment the following line:
- #ALLOCA = -DHAVE_NO_ALLOCA
- X
- X
- # LIBDIR is where libsipp.a will be placed when you make install.
- # INCLUDEDIR is where the include files will be placed when you make install.
- # MANDIR is where the manuals will be placed when you make install.
- # MANEXT is the extension the manuals will receive in MANDIR
- X
- LIBDIR = /usr/local/lib
- INCLUDEDIR = /usr/local/include
- MANDIR = /usr/local/man/man3
- MANEXT = 3
- X
- X
- # Choose a suitable C compiler and appropriate flags:
- #CC = gcc
- CC = cc
- #CFLAGS = -g
- CFLAGS = -O
- X
- X
- # Choose a lexical analyzer generator:
- LEX = lex
- X
- X
- SHELL = /bin/sh
- RM = rm -f
- X
- X
- # ================================================================
- # Don't change anything below this line.
- # ================================================================
- X
- DOCFILES = primitives.man shaders.man sipp.man sipp_pixmap.man geometric.man
- X
- X
- MAKEOPTS = CC=$(CC) LEX=$(LEX) \
- X CFLAGS="$(NOVOID) $(NOMEMCPY) $(ALLOCA) $(CFLAGS) -I../libsipp"
- X
- X
- all: library demos
- X
- library:
- X cd libsipp; $(MAKE) $(MAKEOPTS) libsipp.a
- X
- demos:
- X cd demo; $(MAKE) $(MAKEOPTS) programs
- X
- X
- install: library
- X cd libsipp; $(MAKE) LIBDIR=$(LIBDIR) INCLUDEDIR=$(INCLUDEDIR) install
- X for i in $(DOCFILES) ; do \
- X cp doc/$$i $(MANDIR)/`basename $$i .man`.$(MANEXT); \
- X done
- X
- X
- clean:
- X $(RM) *~ *shar*
- X cd libsipp; $(MAKE) clean;
- X cd demo; $(MAKE) clean;
- X cd doc; ls -1 | egrep -v \.man$$ | xargs rm -f
- SHAR_EOF
- chmod 0644 Makefile ||
- echo 'restore of Makefile failed'
- Wc_c="`wc -c < 'Makefile'`"
- test 2495 -eq "$Wc_c" ||
- echo 'Makefile: original size 2495, current size' "$Wc_c"
- fi
- # ============= README ==============
- if test -f 'README' -a X"$1" != X"-c"; then
- echo 'x - skipping README (File already exists)'
- else
- echo 'x - extracting README (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'README' &&
- *******************************************************************
- X sipp -- 3d rendering package
- X
- X by Jonas Yngvesson jonas-y@isy.liu.se
- X Inge Wallin ingwa@isy.liu.se
- X
- X Linkoping Institute of Technology
- X Sweden
- *******************************************************************
- X
- This is SIPP, the SImple Polygon Processor, version 2.1. SIPP is a
- library for creating 3-dimensional scenes and rendering them using a
- scan-line z-buffer algorithm. A scene is built up of objects which
- can be transformed with rotation, translation and scaling. The
- objects form hierarchies where each object can have arbitrarily many
- subobjects and subsurfaces. A surface is a number of connected
- polygons which are rendered with either Phong, Gouraud or flat
- shading. An image can also be rendered as a line drawing of the
- polygon edges without any shading at all.
- X
- The library has an internal database for the objects that is to be
- rendered. Objects can be installed in, and removed from, this
- database at any time.
- X
- The library also provides 3-dimensional texture mapping with
- automatic interpolation of texture coordinates. Simple anti-aliasing
- can be performed through oversampling. A scene can be illuminated
- by an arbitrary number of light sources. A basic shading algorithm is
- provided with the library, but the user can also use his own shading
- algorithms for each surface to produce special effects.
- X
- Images can be rendered directly onto a file in the Portable Pixmap
- format (ppm) (or, for line images, Portable Bitmap, pbm) or into a
- pixmap (bitmap) in core. The representation of the pixmap is not
- restricted in any way. It can be any structure, or device, that is
- capable of plotting a pixel or drawing a line.
- X
- Version 2.1 should be fully compatible with previous versions (2.0.*)
- and only a recompilation should be needed to update older programs.
- X
- The program has some bugs & limitations. See the BUGS entry in the
- manuals for more information. All bugs in version 2.0 which were
- reported to us have been fixed though.
- X
- To install the library, edit the Makefile and type 'make install'. If
- Your system does not have the drand48() random number generator,
- change the macro RANDOM() in sipp.h to use the random number
- generator available on your system.
- X
- If you only want to make the library but not install it, just type
- 'make library'.
- X
- If you want to make the tests and demonstrations, type 'make demos'.
- X
- X
- Please send any enhancements, bug reports and fixes to us.
- Especially, if you create nice new object types, we would be
- grateful if you sent the C functions creating those to us. We could
- then compile a library of object functions and let other people share
- the benefits.
- X
- Linkoping 15 July 1991
- X
- X enjoy! /Jonas & Inge
- SHAR_EOF
- chmod 0664 README ||
- echo 'restore of README failed'
- Wc_c="`wc -c < 'README'`"
- test 2832 -eq "$Wc_c" ||
- echo 'README: original size 2832, current size' "$Wc_c"
- fi
- # ============= CHANGES ==============
- if test -f 'CHANGES' -a X"$1" != X"-c"; then
- echo 'x - skipping CHANGES (File already exists)'
- else
- echo 'x - extracting CHANGES (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'CHANGES' &&
- Changes in version 2.1 vs. version 2.0.*
- X
- X - Support for more rendering modes: Phong, Gouraud, flat and line.
- X Only Phong mode can do real texture mapping though.
- X
- X - Support for rendering into other places than files. We have chosen
- X to call this rendering into pixmaps, but there is no restriction on
- X what is really used. This is accomplished through a callback function
- X similar to the shader interface. A basic implementation of pixmaps
- X and bitmaps that could be used are supplied in the library.
- X
- X - Oversampling for antialiasing can now be arbitrarily large.
- X
- X - It is possible to turn off backface culling. This is useful if you
- X have a database of objects that are inconsequent in the ordering
- X of its vertices (clockwize/counterclockwize).
- X
- X - Two new object primitives, cone and prism.
- X Thanks to David Jones (djones@awesome.berkeley.edu) for these.
- X
- X - Two new shaders.
- X 1. strauss_shader() - This is an implementation of the shading
- X model designed by Paul S. Strauss at Silicon Graphics Inc.
- X and described in IEEE CG&A November 1990.
- X 2. wood_shader() - A shader that simulates wood texture using
- X noise and turbulence.
- X
- X - Matrix and vector handling functions and macros are now "public".
- X
- X - Correct interpolation of texture coordinates. Previously there
- X were disturbing "rubberband" effects on objects spanning large
- X depths in the picture.
- X
- X - A full polygon clipper is now used instead of the previous, rather
- X strange approach. Objects behind the viewpoint are now handled correctly
- X (I hope), previously they caused strange effects.
- X
- X - It is possible to get the current transformation matrix from an object
- X and not only to set it. This makes it a lot easier to do animations.
- X
- X - Subobjects and surfaces can now be removed from objects.
- SHAR_EOF
- chmod 0644 CHANGES ||
- echo 'restore of CHANGES failed'
- Wc_c="`wc -c < 'CHANGES'`"
- test 1907 -eq "$Wc_c" ||
- echo 'CHANGES: original size 1907, current size' "$Wc_c"
- fi
- # ============= TODO ==============
- if test -f 'TODO' -a X"$1" != X"-c"; then
- echo 'x - skipping TODO (File already exists)'
- else
- echo 'x - extracting TODO (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'TODO' &&
- X
- [Texinfo manual for SIPP.]
- X
- [Have the program whistle while it works with a verbose flag.
- X (Hmmm, I don't think I want this anymore /Jonas)]
- X
- [Shaped lightsources, e.g. point, spotlight]
- X
- [Transparent objects]
- X
- [Colored lightsources]
- X
- [Shadows, see eg article in siggraph 87 about depth maps]
- X
- [Curved surface rendering (not siPp any longer)]
- X
- SHAR_EOF
- chmod 0664 TODO ||
- echo 'restore of TODO failed'
- Wc_c="`wc -c < 'TODO'`"
- test 346 -eq "$Wc_c" ||
- echo 'TODO: original size 346, current size' "$Wc_c"
- fi
- # ============= ChangeLog ==============
- if test -f 'ChangeLog' -a X"$1" != X"-c"; then
- echo 'x - skipping ChangeLog (File already exists)'
- else
- echo 'x - extracting ChangeLog (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'ChangeLog' &&
- Sun Jul 21 00:00:56 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * viewpoint.[ch]: Removed declaration and calculation of
- X alfa and beta (perspective transformation constants).
- X They are no longer needed (see last entry)
- X
- X * Changed percpective transformation of the z-coordinate.
- X It is now only scaled and stores the homogenous "coordinate".
- X
- X * rendering.c: Changed interpolation of texture coordinates so
- X it is done in perspective coordinates. They are transformed
- X back just before calling the shader. Previously the texture on
- X object spanning large depths showed disturbing "rubberband"
- X effects.
- X
- Thu Jul 18 19:52:17 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * New file: wood.c, a wood shader.
- X
- X * New file: woodtest.c. demo of the wood shader.
- X
- Mon Jul 15 15:09:54 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * New file: strausstest.c in the demo directory. This program
- X demonstrates the new strauss shader.
- X
- X * Documented sipp_cone()
- X
- Fri Jul 12 19:37:29 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * Uppdated all demo/test programs to use the new function calls.
- X Added switches to them to decide what rendering mode to use.
- X Updated the Makefile and README file.
- X
- X * New file: conetest.c, demonstration/test of the cone and
- X cylinder primitive. cylindertest.c removed.
- X
- X * cone.c: Installed David Jones cone code into the library.
- X cylinder.c removed, cylinder is now a special case of a
- X truncated cone.
- X
- Wed Jul 10 20:43:35 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * rendering.c: Changed create_edges() so that horizontal lines
- X are not included in the edge lists. These were previously used
- X when rendering line images, but no more (see Jul 1 1991).
- X Changes in merge_edge_lists() and render_line() to comply
- X with this.
- X
- X * sipp.c is no more... It had grown out of proportions so I
- X split it up into the following files:
- X
- X rendering.[ch] - The actual rendering engine.
- X lightsource.[ch] - Lightsource handling.
- X objects.[ch] - Creation of objects and surfaces, object hierachy
- X handling and object database handling.
- X smalloc.[ch] - "Safe" malloc and calloc.
- X transforms.c - Object transformations.
- X viewpoint.[ch] - Viewpoint and viewing transformation handling.
- X
- X The old sipptypes.h is now (almost) rendering.h. All new .h files
- X defines internal types and interfaces. Public ditos are as before
- X defined in sipp.h
- X
- X
- Sat Jul 6 01:07:08 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * sipp.c: New functions object_sub_subobj() and object_sub_surface()
- X to remove a subobject and a surface from an object.
- X
- X * sipp.c: New function object_get_transf() to retrieve the current
- X transformation matrix of an object.
- X
- Fri Jul 5 20:38:12 1991 Inge Wallin (ingwa at brassie)
- X
- X * Updated the README file to tell about version 2.1 instead of
- X 2.0.2.
- X
- X * Moved the definition of Vector and Transf_mat to geometric.h
- X instead of sipp.h. Also made the definition of ident_matrix
- X public.
- X
- X * sipp_prism() documented.
- X
- X * New file: geometric.man which documents all functions and macros
- X dealing with vectors and matrixes.
- X
- X * bitmap.[hc] changed name to sipp_bitmap.[hc]. Same for pixmap.
- X
- X * sipp_pixmap.man: Finished documenting the sipp_bitmap and
- X sipp_pixmap implementations.
- X
- Mon Jul 1 17:50:01 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * sipp.c: Changed generation of line images so that the y_bucket
- X and edge lists don't have to be allocated. It's faster and
- X saves LOTS of memory. Lines are drawn directly in
- X create_edges(). The bitmap support in bitmap.c are now used
- X internally in sipp.c.
- X
- X * sipp.c: Changed the polygon clipper so clipping is performed
- X before the perspective transformation. Otherwize texture
- X coordinates were destoyed by the clipping.
- X
- Tue Jun 25 23:48:44 1991 Inge Wallin (jonas-y at brassie)
- X
- X * New file: demo/prismtest.c replacing blocktest.c.
- X
- X * New file: prism.c implementing the new object prism. The file
- X block.c is removed and the code for producing a block is
- X rewritten to use prism instead.
- X
- X
- Tue Jun 25 14:45:59 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * New file: strauss.c implementing a more advanced shading
- X model than the basic one (slower too...). The model is the
- X one described by Paul Strauss in IEEE CG&A Nov. 1990.
- X Changes in shaders.h also to support this shader.
- X
- X * New files: bitmap.c and bitmap.h containing functions handling
- X SIPP bitmaps. These functions could be used when rendering
- X line images into bitmaps instead of files.
- X
- X * sipp.c: Added support for rendering line images into bitmaps.
- X The user provides a bitmap pointer and a line drawing function.
- X
- X * sipp.c: A global flag decides if backface culling should be
- X performed. If not, backfacing polygons are "inverted" and
- X rendered as usual.
- X
- X * sipp.c: Added a complete polygon clipper. Previously, strange
- X things could happen if objects were behind the viewpoint.
- X
- Sat Jun 8 17:21:11 1991 Jonas Yngvesson (jonas-y at gouraud)
- X
- X * sipp.c: Support for rendering into pixmaps. A general storage
- X function is called for each rendered line. Rendering of line
- X images into bitmaps is *NOT* yet supported. The user provides
- X a pixmap pointer and a function to set a pixel in it.
- X
- Fri Jun 7 03:50:05 1991 Jonas Yngvesson (jonas-y at brassie)
- X
- X * sipp.c: Added support for new rendering modes: gouraud, flat
- X and line.
- X
- X * sipp.c: Added support for arbitrary oversampling factors.
- X
- Fri Jun 7 02:34:20 1991 Inge Wallin (ingwa at brassie)
- X
- X * New file: pixmap.c containing functions for handling SIPP
- X pixmaps. These functions could be used when rendering into
- X a pixmap instead of a file.
- X
- X * ChangeLog created.
- X
- These are all the older records:
- X
- 910527 Ver. 2.0.2. A major bug in traverse_object_tree() fixed.
- X The invers transformation of the eyepoint was not correct,
- X causing polygons erroneously to be marked as backfacing.
- X
- 910412 Ver. 2.0.1. Some minor bugfixes. Division by zero in
- X create_edges() if an edge was horizontal in both x and y.
- X Free-list became corrupted since the y_bucket was freed
- X twice. Wrong parameters to (D)noise() in bumpy.c. Two lines
- X interchanged in mat_rotate(). A few other minor changes.
- X
- 901219 At last! 2.0 is out of the bag. And right in time for X-mas :-)
- X *Major* rewrite. A new level in the object hierarchy introduced.
- X An object is now a collection of surfaces and other objects
- X (subobjects). This allows creation of complex composite objects.
- X Objects in the hierarchy have coupled transformations.
- X The old "Object" is now, more appropriately, called Surface.
- X A fatal bug in the viewing transformation fixed.
- X Objects and surfaces have internal reference counters so deletion
- X won't leave dangling references in an hierachy.
- X The code is now almost readable.
- X Images format changed to PPM since much more applications
- X exists that can handle that format.
- X The shader package is extended and a package with functions
- X to create geometric primitives as objects is provided.
- X
- 901030 More general shader interface. The simple internal shader
- X was moved out of sipp into its own file. Several shaders
- X provided together with it in a "shader package".
- X
- 900712 Major code beautifying, quite a lot left to do though...
- X Typedefs instead of raw structures,
- X much better typenames, lots of comments added (probably
- X not enough though). Split into a few header files and
- X a source file. More portable interface.
- X
- 891124 Made the object representation independent of the
- X illumination model used. A user can now supply his
- X own surface description and shading function.
- X Added support for texture mapping (both solid and 2d).
- X No texture mapping is built into the internal shader though.
- X
- 891120 Added colour. New illumination model. Simple antialiasing
- X with double oversampling and a box filter.
- X
- 891028 Converted from sippuz to sipp. Z-buffer changed
- X to scan-line z-buffer.
- X Phong-shading.
- X The stack notion introduced.
- X Changed fixed viewpoint to a user defined one.
- X World coordinates and picture resolution can be chosen
- X freely.
- X
- 881128 Converted from Pascal to C. Gouraud shading. Redesign of the
- X data structures.
- X
- 88???? Original program "sippuz - simple polygon processing using a
- X z-buffer", written in Hedrick Pascal on a DEC-20 system
- X running TOPS-20. Greyscales only. Flat shading.
- SHAR_EOF
- chmod 0664 ChangeLog ||
- echo 'restore of ChangeLog failed'
- Wc_c="`wc -c < 'ChangeLog'`"
- test 9212 -eq "$Wc_c" ||
- echo 'ChangeLog: original size 9212, current size' "$Wc_c"
- fi
- # ============= libsipp/Makefile ==============
- if test ! -d 'libsipp'; then
- echo 'x - creating directory libsipp'
- mkdir 'libsipp'
- fi
- if test -f 'libsipp/Makefile' -a X"$1" != X"-c"; then
- echo 'x - skipping libsipp/Makefile (File already exists)'
- else
- echo 'x - extracting libsipp/Makefile (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'libsipp/Makefile' &&
- #
- # Makefile for libsipp.a
- #
- X
- #These values are default if they are not overridden from the command line:
- CC = cc
- CFLAGS = -pipe -I. -g
- X
- SHELL = /bin/sh
- RM = rm -f
- X
- IHDRS = bezier.h lightsource.h noise.h objects.h rendering.h smalloc.h \
- X viewpoint.h
- EHDRS = sipp.h geometric.h shaders.h primitives.h sipp_pixmap.h sipp_bitmap.h
- HDRS = $(IHDRS) $(EHDRS)
- SRCS = rendering.c geometric.c lightsource.c objects.c smalloc.c \
- X transforms.c viewpoint.c \
- X basic_shader.c mask.c marble.c granite.c noise.c bozo.c bumpy.c \
- X planet.c strauss.c wood.c \
- X prism.c cone.c ellipsoid.c torus.c bezier.c bezier_lex.l \
- X sipp_pixmap.c sipp_bitmap.c
- LIBOBJS = libsipp.a(rendering.o) libsipp.a(geometric.o) \
- X libsipp.a(lightsource.o) libsipp.a(objects.o) libsipp.a(smalloc.o) \
- X libsipp.a(transforms.o) libsipp.a(viewpoint.o) \
- X libsipp.a(basic_shader.o) libsipp.a(strauss.o) libsipp.a(wood.o) \
- X libsipp.a(marble.o) libsipp.a(granite.o) libsipp.a(mask.o)\
- X libsipp.a(bozo.o) libsipp.a(bumpy.o) libsipp.a(planet.o)\
- X libsipp.a(noise.o) libsipp.a(bezier.o) libsipp.a(bezier_lex.o)\
- X libsipp.a(torus.o) libsipp.a(cone.o) libsipp.a(ellipsoid.o) \
- X libsipp.a(prism.o)\
- X libsipp.a(sipp_pixmap.o) libsipp.a(sipp_bitmap.o)\
- X libsipp.a(xalloca.o)
- X
- X
- # These are used if no other values are given at the command line:
- LIBDIR = /usr/local/lib
- INCLUDEDIR = /usr/local/include
- X
- X
- all: libsipp.a
- X
- libsipp.a: $(LIBOBJS)
- X ranlib libsipp.a
- X $(RM) bezier_lex.c
- X
- install: libsipp.a $(EHDRS)
- X cp libsipp.a $(LIBDIR)
- X cp $(EHDRS) $(INCLUDEDIR)
- X
- X
- tags:
- X etags -t $(HDRS) $(SRCS)
- X
- clean:
- X $(RM) *.o *~ TAGS libsipp.a
- X
- X
- libsipp.a(rendering.o): sipp.h rendering.h lightsource.h geometric.h \
- X objects.h sipp_bitmap.h viewpoint.h smalloc.h \
- X patchlevel.h
- libsipp.a(geometric.o): geometric.h sipp.h
- libsipp.a(lightsource.o): geometric.h lightsource.h sipp.h smalloc.h
- libsipp.a(objects.o): sipp.h objects.h smalloc.h
- libsipp.a(smalloc.o):
- libsipp.a(transforms.o): geometric.h sipp.h
- libsipp.a(viewpoint.o): geometric.h viewpoint.h
- libsipp.a(basic_shader.o): sipp.h
- libsipp.a(strauss.o): sipp.h shaders.h geometric.h
- libsipp.a(mask.o): shaders.h sipp.h
- libsipp.a(marble.o): noise.h shaders.h sipp.h
- libsipp.a(granite.o): noise.h shaders.h sipp.h
- libsipp.a(wood.o): noise.h shaders.h sipp.h
- libsipp.a(bozo.o): noise.h shaders.h sipp.h
- libsipp.a(bumpy.o): noise.h shaders.h sipp.h geometric.h
- libsipp.a(planet.o): noise.h sipp.h geometric.h
- libsipp.a(noise.o): noise.h sipp.h
- libsipp.a(bezier.o): bezier.h sipp.h
- libsipp.a(bezier_lex.o): bezier.h
- libsipp.a(torus.o): sipp.h
- libsipp.a(ellipsoid.o): sipp.h
- libsipp.a(prism.o): sipp.h
- libsipp.a(cone.o): sipp.h
- libsipp.a(sipp_pixmap.o): sipp_pixmap.h sipp.h patchlevel.h
- libsipp.a(sipp_bitmap.o): sipp_bitmap.h sipp.h patchlevel.h
- libsipp.a(xalloca.o): xalloca.h
- SHAR_EOF
- chmod 0644 libsipp/Makefile ||
- echo 'restore of libsipp/Makefile failed'
- Wc_c="`wc -c < 'libsipp/Makefile'`"
- test 3187 -eq "$Wc_c" ||
- echo 'libsipp/Makefile: original size 3187, current size' "$Wc_c"
- fi
- # ============= libsipp/basic_shader.c ==============
- if test -f 'libsipp/basic_shader.c' -a X"$1" != X"-c"; then
- echo 'x - skipping libsipp/basic_shader.c (File already exists)'
- else
- echo 'x - extracting libsipp/basic_shader.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'libsipp/basic_shader.c' &&
- /**
- X ** sipp - SImple Polygon Processor
- X **
- X ** A general 3d graphic package
- X **
- X ** Copyright Jonas Yngvesson (jonas-y@isy.liu.se) 1988/89/90/91
- X ** Inge Wallin (ingwa@isy.liu.se) 1990/91
- X **
- X ** This program is free software; you can redistribute it and/or modify
- X ** it under the terms of the GNU General Public License as published by
- X ** the Free Software Foundation; either version 1, or any later version.
- X ** This program is distributed in the hope that it will be useful,
- X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X ** GNU General Public License for more details.
- X ** You can receive a copy of the GNU General Public License from the
- X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X **/
- X
- /**
- X ** basic_shader.c - Basic shading model, somewhat modified and
- X ** simplified version of Blinn's
- X **/
- X
- #include <math.h>
- X
- #include <sipp.h>
- X
- X
- void
- basic_shader(a, b, c, u, v, w, view_vec, lights, sd, color)
- X double a, b, c, u, v, w;
- X Vector view_vec;
- X Lightsource *lights;
- X Surf_desc *sd;
- X Color *color;
- {
- X double nx, ny, nz, l;
- X double xs, ys, zs;
- X double coss, cosi, diffsum, specsum;
- X double c3two;
- X Lightsource *lp;
- X
- X l = (a * a + b * b + c * c);
- X nx = a;
- X ny = b;
- X nz = c;
- X if (fabs(l - 1.0) > 1e-5) {
- X l = sqrt(l);
- X nx /= l;
- X ny /= l;
- X nz /= l;
- X }
- X diffsum = specsum = 0;
- X c3two = sd->c3 * sd->c3;
- X for (lp = lights; lp != (Lightsource *)0; lp = lp->next) {
- X cosi = (lp->dir.x * nx + lp->dir.y * ny + lp->dir.z * nz);
- X if (cosi > 0)
- X diffsum += cosi * lp->intensity;
- X cosi *= -2.0;
- X xs = -lp->dir.x - cosi * nx;
- X ys = -lp->dir.y - cosi * ny;
- X zs = -lp->dir.z - cosi * nz;
- X coss = (xs * view_vec.x + ys * view_vec.y + zs * view_vec.z);
- X if (coss > 0)
- X specsum += lp->intensity * c3two * coss /
- X (coss * coss * (c3two -1) + 1);
- X }
- X color->red = (sd->color.red * (sd->ambient + diffsum) + sd->specular
- X * specsum);
- X if (color->red > 1.0) color->red = 1.0;
- X color->grn = (sd->color.grn * (sd->ambient + diffsum) + sd->specular
- X * specsum);
- X if (color->grn > 1.0) color->grn = 1.0;
- X color->blu = (sd->color.blu * (sd->ambient + diffsum) + sd->specular
- X * specsum);
- X if (color->blu > 1.0) color->blu = 1.0;
- }
- X
- X
- X
- SHAR_EOF
- chmod 0664 libsipp/basic_shader.c ||
- echo 'restore of libsipp/basic_shader.c failed'
- Wc_c="`wc -c < 'libsipp/basic_shader.c'`"
- test 2591 -eq "$Wc_c" ||
- echo 'libsipp/basic_shader.c: original size 2591, current size' "$Wc_c"
- fi
- # ============= libsipp/bezier.c ==============
- if test -f 'libsipp/bezier.c' -a X"$1" != X"-c"; then
- echo 'x - skipping libsipp/bezier.c (File already exists)'
- else
- echo 'x - extracting libsipp/bezier.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bezier.c' &&
- /**
- X ** sipp - SImple Polygon Processor
- X **
- X ** A general 3d graphic package
- X **
- X ** Copyright Jonas Yngvesson (jonas-y@isy.liu.se) 1988/89/90/91
- X ** Inge Wallin (ingwa@isy.liu.se) 1990/91
- X **
- X ** This program is free software; you can redistribute it and/or modify
- X ** it under the terms of the GNU General Public License as published by
- X ** the Free Software Foundation; either version 1, or any later version.
- X ** This program is distributed in the hope that it will be useful,
- X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X ** GNU General Public License for more details.
- X ** You can receive a copy of the GNU General Public License from the
- X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X **/
- X
- /**
- X ** bezier.c - Reading bezier descriptions and creating objects.
- X **/
- X
- #include <math.h>
- #include <stdio.h>
- X
- #include "sipp.h"
- #include "bezier.h"
- X
- X
- Tokenval tokenval;
- extern FILE *yyin;
- X
- X
- /*================================================================*/
- /* */
- /* Functions for reading bezier descriptions from file */
- /* */
- /*================================================================*/
- X
- X
- /*
- X * Read a vertex list, where each vertex is an xyz triple, and
- X * install it in the bezier structure.
- X */
- static void
- vertex_read(obj)
- X Bez_Object *obj;
- {
- X int token;
- X int i, j;
- X
- X token = yylex();
- X if (token != NVERTICES) {
- X fprintf(stderr, "Corrupt vertex description.\n");
- X goto errout;
- X }
- X
- X token = yylex();
- X if (token != INTEGER) {
- X fprintf(stderr, "Corrupt vertex description.\n");
- X goto errout;
- X }
- X obj->nvertex = tokenval.intval;
- X obj->vertex = (Bez_Vertex *)malloc(obj->nvertex * sizeof(Bez_Vertex));
- X if (obj->vertex == NULL) {
- X fprintf(stderr, "vertex_read: Out of core.\n");
- X goto errout;
- X }
- X
- X token = yylex();
- X if (token != VERTEX_LIST) {
- X fprintf(stderr, "Corrupt vertex description.\n");
- X goto errout;
- X }
- X
- X for (i = 0; i < obj->nvertex; i++) {
- X for (j = 0; j < 3; j++) {
- X token = yylex();
- X if (token != FLOAT && token != INTEGER) {
- X fprintf(stderr, "Corrupt vertex description.\n");
- X goto errout;
- X }
- X if (token == FLOAT) {
- X obj->vertex[i].coor[j] = tokenval.floatval;
- X } else {
- X obj->vertex[i].coor[j] = (double)tokenval.intval;
- X }
- X }
- X }
- X
- X return;
- X
- X errout:
- X if (obj->vertex != NULL) {
- X free(obj->vertex);
- X obj->vertex = NULL;
- X }
- }
- X
- X
- X
- /*
- X * Read a list of bezier curves, where each curve consists of
- X * four control points (index into the vertex list), and install
- X * it in the bezier structure.
- X */
- static void
- curve_read(obj)
- X Bez_Object *obj;
- {
- X int token;
- X int i, j;
- X
- X token = yylex();
- X if (token != NCURVES) {
- X fprintf(stderr, "Corrupt curve description.\n");
- X goto errout;
- X }
- X
- X token = yylex();
- X if (token != INTEGER) {
- X fprintf(stderr, "Corrupt curve description.\n");
- X goto errout;
- X }
- X obj->n.ncurves = tokenval.intval;
- X obj->cp.ccp = (Bez_Curve *)malloc(obj->n.ncurves * sizeof(Bez_Curve));
- X if (obj->cp.ccp == NULL) {
- X fprintf(stderr, "curve_read: Out of core.\n");
- X goto errout;
- X }
- X
- X token = yylex();
- X if (token != CURVE_LIST) {
- X fprintf(stderr, "Corrupt curve description.\n");
- X goto errout;
- X }
- X
- X for (i = 0; i < obj->n.ncurves; i++) {
- X for (j = 0; j < 4; j++) {
- X token = yylex();
- X if (token != INTEGER) {
- X fprintf(stderr, "Corrupt curve description.\n");
- X goto errout;
- X }
- X obj->cp.ccp[i].cp[j] = tokenval.intval - 1;
- X }
- X }
- X
- X return;
- X
- X errout:
- X if (obj->cp.ccp != NULL) {
- X free(obj->cp.ccp);
- X obj->cp.ccp = NULL;
- X }
- }
- X
- X
- X
- /*
- X * Read a list of bezier patches, where each patch consists of
- X * sixteen control points (index into the vertex list), and install
- X * it in the bezier structure.
- X */
- static void
- patch_read(obj)
- X Bez_Object *obj;
- {
- X int token;
- X int i, j, k;
- X
- X token = yylex();
- X if (token != NPATCHES) {
- X fprintf(stderr, "Corrupt patch description.\n");
- X goto errout;
- X }
- X
- X token = yylex();
- X if (token != INTEGER) {
- X fprintf(stderr, "Corrupt patch description.\n");
- X goto errout;
- X }
- X obj->n.npatches = tokenval.intval;
- X obj->cp.pcp = (Bez_Patch *)malloc(obj->n.npatches * sizeof(Bez_Patch));
- X if (obj->cp.pcp == NULL) {
- X fprintf(stderr, "patch_read: Out of core.\n");
- X goto errout;
- X }
- X
- X token = yylex();
- X if (token != PATCH_LIST) {
- X fprintf(stderr, "Corrupt patch description.\n");
- X goto errout;
- X }
- X
- X for (i = 0; i < obj->n.npatches; i++) {
- X for (j = 0; j < 4; j++) {
- X for (k = 0; k < 4; k++) {
- X token = yylex();
- X if (token != INTEGER) {
- X fprintf(stderr, "Corrupt patch description.\n");
- X goto errout;
- X }
- X obj->cp.pcp[i].cp[j][k] = tokenval.intval - 1;
- X }
- X }
- X }
- X
- X return;
- X
- X errout:
- X if (obj->cp.pcp != NULL) {
- X free(obj->cp.pcp);
- X obj->cp.pcp = NULL;
- X }
- }
- X
- X
- X
- /*
- X * Read a bezier object from a file, i.e. determine if it is a
- X * curve or patch description, read vertex and curve or patch
- X * description. Build a bezier object from the data.
- X */
- Bez_Object *
- bezier_read(file)
- X FILE *file;
- {
- X int token;
- X Bez_Object *obj;
- X
- X
- X yyin = file;
- X
- X obj = (Bez_Object *)calloc(1, sizeof(Bez_Object));
- X if (obj == NULL) {
- X fprintf(stderr, "bezier_read: Out of core.\n");
- X return obj;
- X }
- X if ((token = yylex()) == PATCHES) {
- X obj->type = PATCHES;
- X vertex_read(obj);
- X if (obj->vertex == NULL) {
- X goto errout;
- X }
- X patch_read(obj);
- X if (obj->cp.pcp == NULL) {
- X goto errout;
- X }
- X } else if (token == CURVES) {
- X obj->type = CURVES;
- X vertex_read(obj);
- X if (obj->vertex == NULL) {
- X goto errout;
- X }
- X curve_read(obj);
- X if (obj->cp.ccp == NULL) {
- X goto errout;
- X }
- X } else {
- X fprintf(stderr, "Corrupt bezier description file: %s\n", file);
- X return NULL;
- X }
- X
- X return obj;
- X
- X errout:
- X if (obj != NULL) {
- X if (obj->vertex != NULL) {
- X free(obj->vertex);
- X }
- X if (obj->cp.pcp != NULL) {
- X free(obj->cp.pcp);
- X }
- X free(obj);
- X }
- X return NULL;
- }
- X
- X
- /*================================================================*/
- /* */
- /* Functions for evaluating bezier functions */
- /* */
- /*================================================================*/
- X
- static double
- C(i)
- X int i;
- {
- X int j, a;
- X
- X a = 1;
- X for (j = i + 1; j < 4; j++) {
- X a = a * j;
- X }
- X for (j = 1 ; j < 4 - i; j++) {
- X a = a / j;
- X }
- X
- X return (double)a;
- }
- X
- X
- static double
- bblend(i, u)
- X int i;
- X double u;
- {
- X int j;
- X double v;
- X
- X v = C(i);
- X for (j = 1; j <= i; j++) {
- X v *= u;
- X }
- X for (j = 1; j < 4 - i; j++) {
- X v *= 1.0 - u;
- X }
- X
- X if (fabs(v) < 1.0E-15) {
- X return 0.0;
- X } else {
- X return v;
- X }
- }
- X
- X
- /*
- X * Determine x, y and z coordinates of a point on the bezier
- X * curve described by CURVE and VERTEX. U is a parameter between
- X * 0 and 1 that determines how far "into" the curve we are.
- X */
- static void
- bez_curve_eval(vertex, curve, u, x, y, z)
- X Bez_Vertex *vertex;
- X Bez_Curve *curve;
- X double u;
- X double *x, *y, *z;
- {
- X int i;
- X double b;
- X
- X *x = 0;
- X *y = 0;
- X *z = 0;
- X
- X for (i = 0; i < 4; i++) {
- X b = bblend(i, u);
- X *x += vertex[curve->cp[i]].coor[0] * b;
- X *y += vertex[curve->cp[i]].coor[1] * b;
- X *z += vertex[curve->cp[i]].coor[2] * b;
- X }
- }
- X
- X
- /*
- X * Determine x, y and z coordinates of a point on the bezier
- X * patch described by PATCH and VERTEX. U and V are parameters
- X * between 0 and 1 that determines where on the patch we are.
- X */
- static void
- bez_patch_eval(vertex, patch, v, u, x, y, z)
- X Bez_Vertex *vertex;
- X Bez_Patch *patch;
- X double u, v;
- X double *x, *y, *z;
- {
- X int i, j;
- X double b;
- X
- X *x = 0;
- X *y = 0;
- X *z = 0;
- X
- X for (i = 0; i < 4; i++) {
- X for (j = 0; j < 4; j++) {
- X b = bblend(i, v);
- X b *= bblend(j, u);
- X *x += vertex[patch->cp[i][j]].coor[0] * b;
- X *y += vertex[patch->cp[i][j]].coor[1] * b;
- X *z += vertex[patch->cp[i][j]].coor[2] * b;
- X }
- X }
- }
- X
- X
- X
- /*================================================================*/
- /* */
- /* Functions for creating bezier objects */
- /* (these functions are SIPP specific) */
- /* */
- /*================================================================*/
- X
- X
- /*
- X * Approximate the bezier patches described in OBJ with polygons
- X * and create a SIPP surface out of them. The patches will be
- X * tesselated into RESxRES polygons (rectangles).
- X */
- Surface *
- bezier_patches(obj, res, surface, shader)
- X Bez_Object *obj;
- X int res;
- X void *surface;
- X Shader *shader;
- {
- X double x, y, z;
- X double u, v;
- X double step;
- X int i, j, k;
- X
- X step = 1.0 / (double)res;
- X
- X for (i = 0; i < obj->n.npatches; i++) {
- X for (v = 0.0, j = 0; j < res; j++, v += step) {
- X for (u = 0.0, k = 0; k < res; k++, u += step) {
- X bez_patch_eval(obj->vertex, &obj->cp.pcp[i], v, u, &x, &y, &z);
- X vertex_tx_push(x, y, z, x, y, z);
- X bez_patch_eval(obj->vertex, &obj->cp.pcp[i], v, u + step,
- X &x, &y, &z);
- X vertex_tx_push(x, y, z, x, y, z);
- X bez_patch_eval(obj->vertex, &obj->cp.pcp[i],
- X v + step, u + step, &x, &y, &z);
- X vertex_tx_push(x, y, z, x, y, z);
- X bez_patch_eval(obj->vertex, &obj->cp.pcp[i], v + step, u,
- X &x, &y, &z);
- X vertex_tx_push(x, y, z, x, y, z);
- X polygon_push();
- X }
- X }
- X }
- X return surface_create(surface, shader);
- }
- X
- X
- X
- /*
- X * Take the bezier curves described in OBJ and create a
- X * surface by rotating them about th y-axis. The object
- X * will be tesselated as RESx(RES*4) polygons per curve.
- X * (The reason for using 4 times the resolution is rather
- X * "handwavy". I think 90 degrees is about as much as a
- X * patch should cover of a rotational body.)
- X */
- Surface *
- bezier_rot_curves(obj, res, surface, shader)
- X Bez_Object *obj;
- X int res;
- X void *surface;
- X Shader *shader;
- {
- X double x1, y1, z1;
- X double x2, y2, z2;
- X double xtmp;
- X double u;
- X double step;
- X double ca, sa;
- X int i, j, k;
- X
- X step = 1.0 / (double)res;
- X ca = cos(2.0 * M_PI / (4.0 * (double)res));
- X sa = sin(2.0 * M_PI / (4.0 * (double)res));
- X
- X for (i = 0; i < obj->n.ncurves; i++) {
- X for (u = 0.0, j = 0; j < res; j++, u += step) {
- X bez_curve_eval(obj->vertex, &obj->cp.ccp[i], u,
- X &x1, &y1, &z1);
- X bez_curve_eval(obj->vertex, &obj->cp.ccp[i], u + step,
- X &x2, &y2, &z2);
- X vertex_tx_push(x1, y1, z1, x1, y1, z1);
- X vertex_tx_push(x2, y2, z2, x2, y2, z2);
- X for (k = 0; k < 4 * res; k++) {
- X xtmp = ca * x1 + sa * z1;
- X z1 = ca * z1 - sa * x1;
- X x1 = xtmp;
- X xtmp = ca * x2 + sa * z2;
- X z2 = ca * z2 - sa * x2;
- X x2 = xtmp;
- X vertex_tx_push(x2, y2, z2, x2, y2, z2);
- X vertex_tx_push(x1, y1, z1, x1, y1, z1);
- X polygon_push();
- X
- X if (k == 4 * res - 1) {
- X break;
- X }
- X
- X vertex_tx_push(x1, y1, z1, x1, y1, z1);
- X vertex_tx_push(x2, y2, z2, x2, y2, z2);
- X }
- X }
- X }
- X
- X return surface_create(surface, shader);
- }
- X
- X
- X
- /*
- X * Read a bezier description from FILE and build
- X * a bezier surface. Tesselate this object into
- X * polygons and return a pointer to a SIPP object.
- X */
- Object *
- sipp_bezier(file, res, surface, shader)
- X FILE *file;
- X int res;
- X void *surface;
- X Shader *shader;
- {
- X Object *obj;
- X Bez_Object *bez_obj;
- X
- X bez_obj = bezier_read(file);
- X if (bez_obj == NULL) {
- X return NULL;
- X }
- X
- X obj = object_create();
- X if (bez_obj->type == PATCHES) {
- X object_add_surface(obj, bezier_patches(bez_obj, res, surface, shader));
- X } else {
- X object_add_surface(obj, bezier_rot_curves(bez_obj, res, surface,
- X shader));
- X }
- X
- X return obj;
- }
- SHAR_EOF
- chmod 0664 libsipp/bezier.c ||
- echo 'restore of libsipp/bezier.c failed'
- Wc_c="`wc -c < 'libsipp/bezier.c'`"
- test 13510 -eq "$Wc_c" ||
- echo 'libsipp/bezier.c: original size 13510, current size' "$Wc_c"
- fi
- # ============= libsipp/bezier.h ==============
- if test -f 'libsipp/bezier.h' -a X"$1" != X"-c"; then
- echo 'x - skipping libsipp/bezier.h (File already exists)'
- else
- echo 'x - extracting libsipp/bezier.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bezier.h' &&
- /**
- X ** sipp - SImple Polygon Processor
- X **
- X ** A general 3d graphic package
- X **
- X ** Copyright Jonas Yngvesson (jonas-y@isy.liu.se) 1988/89/90/91
- X ** Inge Wallin (ingwa@isy.liu.se) 1990/91
- X **
- X ** This program is free software; you can redistribute it and/or modify
- X ** it under the terms of the GNU General Public License as published by
- X ** the Free Software Foundation; either version 1, or any later version.
- X ** This program is distributed in the hope that it will be useful,
- X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X ** GNU General Public License for more details.
- X ** You can receive a copy of the GNU General Public License from the
- X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X **/
- X
- /**
- X ** bezier.h - Types and defines needed by bezier.c
- X **/
- X
- #ifndef BEZIER_H
- #define BEZIER_H
- X
- X
- #define PATCHES 1
- #define CURVES 2
- #define NVERTICES 3
- #define NPATCHES 4
- #define NCURVES 5
- #define VERTEX_LIST 6
- #define PATCH_LIST 7
- #define CURVE_LIST 8
- #define INTEGER 9
- #define FLOAT 10
- X
- X
- typedef union {
- X int intval;
- X double floatval;
- } Tokenval;
- X
- X
- typedef struct {
- X double coor[3];
- } Bez_Vertex;
- X
- typedef struct {
- X int cp[4];
- } Bez_Curve;
- X
- typedef struct {
- X int cp[4][4];
- } Bez_Patch;
- X
- typedef struct {
- X int type;
- X int nvertex;
- X Bez_Vertex *vertex;
- X union {
- X int ncurves;
- X int npatches;
- X } n;
- X union {
- X Bez_Curve *ccp;
- X Bez_Patch *pcp;
- X } cp;
- } Bez_Object;
- X
- X
- #endif /* BEZIER_H */
- SHAR_EOF
- chmod 0664 libsipp/bezier.h ||
- echo 'restore of libsipp/bezier.h failed'
- Wc_c="`wc -c < 'libsipp/bezier.h'`"
- test 1640 -eq "$Wc_c" ||
- echo 'libsipp/bezier.h: original size 1640, current size' "$Wc_c"
- fi
- # ============= libsipp/bezier_lex.l ==============
- if test -f 'libsipp/bezier_lex.l' -a X"$1" != X"-c"; then
- echo 'x - skipping libsipp/bezier_lex.l (File already exists)'
- else
- echo 'x - extracting libsipp/bezier_lex.l (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bezier_lex.l' &&
- %{
- /**
- X ** sipp - SImple Polygon Processor
- X **
- X ** A general 3d graphic package
- X **
- X ** Copyright Jonas Yngvesson (jonas-y@isy.liu.se) 1988/89/90/91
- X ** Inge Wallin (ingwa@isy.liu.se) 1990/91
- X **
- X ** This program is free software; you can redistribute it and/or modify
- X ** it under the terms of the GNU General Public License as published by
- X ** the Free Software Foundation; either version 1, or any later version.
- X ** This program is distributed in the hope that it will be useful,
- X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X ** GNU General Public License for more details.
- X ** You can receive a copy of the GNU General Public License from the
- X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X **/
- X
- /**
- X ** bezier_lex.l - Lex source for reading bezier descriptions.
- X **/
- X
- #include "bezier.h"
- X
- extern int atoi();
- extern double atof();
- X
- extern Tokenval tokenval;
- extern FILE *bezier_file;
- %}
- %%
- X
- "bezier_patches:" {return PATCHES;}
- "bezier_curves:" {return CURVES;}
- "vertices:" {return NVERTICES;}
- "patches:" {return NPATCHES;}
- "curves:" {return NCURVES;}
- "vertex_list:" {return VERTEX_LIST;}
- "patch_list:" {return PATCH_LIST;}
- "curve_list:" {return CURVE_LIST;}
- X
- -?[0-9]+ {tokenval.intval = atoi(yytext);
- X return INTEGER;
- X }
- -?[0-9]+"."[0-9]*([eE][-+]?[0-9]+)? {tokenval.floatval = atof(yytext);
- X return FLOAT;
- X }
- X
- [ \n\t] {}
- #.*$ { /* This is a comment */ }
- . { return yytext[0]; /* We found something wrong */ }
- X
- %%
- X
- int
- yywrap()
- {
- X return 1;
- }
- SHAR_EOF
- chmod 0664 libsipp/bezier_lex.l ||
- echo 'restore of libsipp/bezier_lex.l failed'
- Wc_c="`wc -c < 'libsipp/bezier_lex.l'`"
- test 1879 -eq "$Wc_c" ||
- echo 'libsipp/bezier_lex.l: original size 1879, current size' "$Wc_c"
- fi
- # ============= libsipp/bozo.c ==============
- if test -f 'libsipp/bozo.c' -a X"$1" != X"-c"; then
- echo 'x - skipping libsipp/bozo.c (File already exists)'
- else
- echo 'x - extracting libsipp/bozo.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bozo.c' &&
- /**
- X ** sipp - SImple Polygon Processor
- X **
- X ** A general 3d graphic package
- X **
- X ** Copyright Jonas Yngvesson (jonas-y@isy.liu.se) 1988/89/90/91
- X ** Inge Wallin (ingwa@isy.liu.se) 1990/91
- X **
- X ** This program is free software; you can redistribute it and/or modify
- X ** it under the terms of the GNU General Public License as published by
- X ** the Free Software Foundation; either version 1, or any later version.
- X ** This program is distributed in the hope that it will be useful,
- X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X ** GNU General Public License for more details.
- X ** You can receive a copy of the GNU General Public License from the
- X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X **/
- X
- /**
- X ** bozo.c - Bozo shader: color objects a la Bozo the clown.
- X **/
- X
- #include <math.h>
- #include <stdio.h>
- X
- #include <sipp.h>
- #include <noise.h>
- #include <shaders.h>
- X
- X
- extern bool noise_ready;
- X
- void
- bozo_shader(nx, ny, nz, u, v, w, view_vec, lights, bd, color)
- X double nx, ny, nz, u, v, w;
- X Vector view_vec;
- X Lightsource *lights;
- X Bozo_desc *bd;
- X Color *color;
- {
- X Vector tmp;
- X Surf_desc surface;
- X double noiseval;
- X int i;
- X
- X if (!noise_ready) {
- X noise_init();
- X }
- X
- X tmp.x = u * bd->scale;
- X tmp.y = v * bd->scale;
- X tmp.z = w * bd->scale;
- X noiseval = noise(&tmp);
- X
- X i = (noiseval + 1) * bd->no_of_cols / 2.0;
- X surface.color = bd->colors[i];
- X surface.ambient = bd->ambient;
- X surface.specular = bd->specular;
- X surface.c3 = bd->c3;
- X basic_shader(nx, ny, nz, u, v, w, view_vec, lights, &surface, color);
- }
- SHAR_EOF
- chmod 0664 libsipp/bozo.c ||
- echo 'restore of libsipp/bozo.c failed'
- Wc_c="`wc -c < 'libsipp/bozo.c'`"
- test 1739 -eq "$Wc_c" ||
- echo 'libsipp/bozo.c: original size 1739, current size' "$Wc_c"
- fi
- true || echo 'restore of libsipp/bumpy.c failed'
- echo End of part 1, continue with part 2
- exit 0
-
- --
- ------------------------------------------------------------------------------
- J o n a s Y n g v e s s o n
- Dept. of Electrical Engineering jonas-y@isy.liu.se
- University of Linkoping, Sweden ...!uunet!isy.liu.se!jonas-y
-
- exit 0 # Just in case...
-