home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / sipp / part01 next >
Text File  |  1991-07-23  |  54KB  |  1,632 lines

  1. Newsgroups: comp.sources.misc
  2. From: Jonas Yngvesson <jonas-y@isy.liu.se>
  3. Subject:  v21i026:  sipp - A 3D rendering library v2.1, Part01/08
  4. Message-ID: <csm-v21i026=sipp.130352@sparky.imd.sterling.com>
  5. X-Md4-Signature: 8900b3d20590050f9deeee26b1d392fb
  6. Date: Tue, 23 Jul 1991 18:14:40 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Jonas Yngvesson <jonas-y@isy.liu.se>
  10. Posting-number: Volume 21, Issue 26
  11. Archive-name: sipp/part01
  12. Supersedes: sipp2.0: Volume 16, Issue 5-10
  13. Environment: UNIX
  14.  
  15. This is sipp-2.1. A library for rendering scenes with 3d objects.
  16.  
  17. Changes from previous versions (2.0.*) include:
  18.  
  19.     - Support for more rendering modes: Phong, Gouraud, flat and line.
  20.       Only Phong mode can do real texture mapping though.
  21.  
  22.     - Support for rendering into other places than files. We have chosen
  23.       to call this rendering into pixmaps, but there is no restriction on
  24.       what is really used. This is accomplished through a callback function
  25.       similar to the shader interface. A basic implementation of pixmaps
  26.       and bitmaps that could be used are supplied in the library.
  27.  
  28.     - Oversampling for antialiasing can now be arbitrarily large.
  29.  
  30.     - It is possible to turn off backface culling. This is useful if you
  31.       have a database of objects that are inconsequent in the ordering
  32.       of its vertices (clockwize/counterclockwize).
  33.  
  34.     - Two new object primitives, cone and prism.
  35.       Thanks to David Jones (djones@awesome.berkeley.edu) for these.
  36.  
  37.     - Two new shaders. 
  38.         1. strauss_shader() - This is an implementation of the shading 
  39.            model designed by Paul S. Strauss at Silicon Graphics Inc.
  40.            and described in IEEE CG&A November 1990.
  41.         2. wood_shader() - A shader that simulates wood texture using
  42.            noise and turbulence.
  43.  
  44.     - Matrix and vector handling functions and macros are now "public".
  45.  
  46.     - Correct interpolation of texture coordinates. Previously there
  47.       were disturbing "rubberband" effects on objects spanning large
  48.       depths in the picture.
  49.  
  50.     - A full polygon clipper is now used instead of the previous, rather
  51.       strange approach. Objects behind the viewpoint are now handled correctly
  52.       (I hope), previously they caused strange effects.
  53.  
  54.     - It is possible to get the current transformation matrix from an object
  55.       and not only to set it. This makes it a lot easier to do animations.
  56.  
  57.     - Subobjects and surfaces can now be removed from objects.
  58.  
  59.  
  60. Thanks everybody who sent bugreports and suggestions for enhancements.
  61.  
  62.         /Jonas Ynvesson & Inge Wallin
  63.  
  64. #!/bin/sh
  65. # This is sipp-2.1, a shell archive (produced by shar 3.49)
  66. # To extract the files from this archive, save it to a file, remove
  67. # everything above the "!/bin/sh" line above, and type "sh file_name".
  68. #
  69. # made 07/20/1991 22:25 UTC by jonas-y@gouraud
  70. # Source directory /home/driver/jonas-y/sippuz/sipp-2.1
  71. #
  72. # existing files will NOT be overwritten unless -c is specified
  73. #
  74. # This shar contains:
  75. # length  mode       name
  76. # ------ ---------- ------------------------------------------
  77. #   2495 -rw-r--r-- Makefile
  78. #   2832 -rw-rw-r-- README
  79. #   1907 -rw-r--r-- CHANGES
  80. #    346 -rw-rw-r-- TODO
  81. #   9212 -rw-rw-r-- ChangeLog
  82. #   3187 -rw-r--r-- libsipp/Makefile
  83. #   2591 -rw-rw-r-- libsipp/basic_shader.c
  84. #  13510 -rw-rw-r-- libsipp/bezier.c
  85. #   1640 -rw-rw-r-- libsipp/bezier.h
  86. #   1879 -rw-rw-r-- libsipp/bezier_lex.l
  87. #   1739 -rw-rw-r-- libsipp/bozo.c
  88. #   1894 -rw-rw-r-- libsipp/bumpy.c
  89. #   4352 -rw-rw-r-- libsipp/cone.c
  90. #   4769 -rw-rw-r-- libsipp/ellipsoid.c
  91. #  10785 -rw-rw-r-- libsipp/geometric.c
  92. #   4676 -rw-rw-r-- libsipp/geometric.h
  93. #   2260 -rw-r--r-- libsipp/granite.c
  94. #   1503 -rw-r--r-- libsipp/lightsource.c
  95. #   1109 -rw-r--r-- libsipp/lightsource.h
  96. #   2442 -rw-rw-r-- libsipp/marble.c
  97. #   1687 -rw-rw-r-- libsipp/mask.c
  98. #   9232 -rw-rw-r-- libsipp/noise.c
  99. #    257 -rw-rw-r-- libsipp/noise.h
  100. #  19672 -rw-r--r-- libsipp/objects.c
  101. #   1430 -rw-r--r-- libsipp/objects.h
  102. #     22 -rw-rw-r-- libsipp/patchlevel.h
  103. #   1700 -rw-rw-r-- libsipp/planet.c
  104. #   1264 -rw-rw-r-- libsipp/primitives.h
  105. #   2773 -rw-rw-r-- libsipp/prism.c
  106. #  39990 -rw-r--r-- libsipp/rendering.c
  107. #   2300 -rw-r--r-- libsipp/rendering.h
  108. #   4808 -rw-rw-r-- libsipp/shaders.h
  109. #   6406 -rw-rw-r-- libsipp/sipp.h
  110. #   4002 -rw-rw-r-- libsipp/sipp_bitmap.c
  111. #   1432 -rw-rw-r-- libsipp/sipp_bitmap.h
  112. #   3142 -rw-rw-r-- libsipp/sipp_pixmap.c
  113. #   1435 -rw-rw-r-- libsipp/sipp_pixmap.h
  114. #   1374 -rw-r--r-- libsipp/smalloc.c
  115. #   1006 -rw-r--r-- libsipp/smalloc.h
  116. #   5426 -rw-rw-r-- libsipp/strauss.c
  117. #   3223 -rw-rw-r-- libsipp/torus.c
  118. #   3036 -rw-r--r-- libsipp/transforms.c
  119. #   5462 -rw-r--r-- libsipp/viewpoint.c
  120. #   1666 -rw-r--r-- libsipp/viewpoint.h
  121. #   4490 -rw-r--r-- libsipp/wood.c
  122. #   5405 -rw-rw-r-- libsipp/xalloca.c
  123. #    314 -rw-rw-r-- libsipp/xalloca.h
  124. #   8030 -rw-r--r-- doc/geometric.man
  125. #   9152 -rw-rw-r-- doc/primitives.man
  126. #  13374 -rw-rw-r-- doc/shaders.man
  127. #  25493 -rw-rw-r-- doc/sipp.man
  128. #   4438 -rw-r--r-- doc/sipp_pixmap.man
  129. #   2878 -rw-rw-r-- demo/Makefile
  130. #   2643 -rw-rw-r-- demo/README
  131. #    273 -rw-rw-r-- demo/animation/Makefile
  132. #   5885 -rw-rw-r-- demo/animation/animation.c
  133. #    608 -rw-rw-r-- demo/animation/README
  134. #   2581 -rw-rw-r-- demo/chain.c
  135. #   2027 -rw-rw-r-- demo/conetest.c
  136. #   1595 -rw-rw-r-- demo/ellipsoid.c
  137. #   3595 -rw-rw-r-- demo/isy90.c
  138. #   1633 -rw-rw-r-- demo/planettest.c
  139. #   2312 -rw-rw-r-- demo/prismtest.c
  140. #   3272 -rw-r--r-- demo/strausstest.c
  141. #   3047 -rw-rw-r-- demo/structure.c
  142. #   2263 -rw-rw-r-- demo/teapot.c
  143. #   1585 -rw-rw-r-- demo/torustest.c
  144. #    644 -rw-rw-r-- demo/tpt_body.bez
  145. #   2371 -rw-rw-r-- demo/tpt_handle.bez
  146. #    482 -rw-rw-r-- demo/tpt_lid.bez
  147. #   2358 -rw-rw-r-- demo/tpt_spout.bez
  148. #   1441 -rw-r--r-- demo/woodtest.c
  149. #
  150. # ============= Makefile ==============
  151. if test -f 'Makefile' -a X"$1" != X"-c"; then
  152.     echo 'x - skipping Makefile (File already exists)'
  153. else
  154. echo 'x - extracting Makefile (Text)'
  155. sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
  156. #             sipp - a 3-d rendering library
  157. #
  158. # Copyright Inge Wallin, Jonas Yngvesson
  159. #
  160. # This is the main Makefile for sipp version 2.1. This directory
  161. # contains three subdirectories:
  162. # libsipp: source code for the library itself.
  163. # demo:    source code for demonstrations and tests
  164. # doc:     standard manual pages for the library.
  165. #
  166. # You can either make the library and the tests/demos separately or 
  167. # you can make them all in one make session. 
  168. #
  169. # To create the library, just type 'make library'.
  170. # To make the demo programs, type 'make demos', but if you haven't 
  171. # made the library first, this will be made automatically for you by
  172. # the makefile in the demos directory.
  173. #
  174. # Before you can make anything, though, you may have to edit the 
  175. # following definitions:
  176. X
  177. X
  178. # If your C compiler doesn't grok the void type, uncomment the 
  179. # following line:
  180. #NOVOID = -Dvoid=int
  181. X
  182. X
  183. # If you don't have memcpy() and friends in your C library, or 
  184. # if you don't have memory.h in /usr/include, uncomment the
  185. # following line:
  186. #NOMEMCPY = -DNOMEMCPY
  187. X
  188. X
  189. # If you don't have alloca(), uncomment the following line:
  190. #ALLOCA = -DHAVE_NO_ALLOCA
  191. X
  192. X
  193. # LIBDIR is where libsipp.a will be placed when you make install.
  194. # INCLUDEDIR is where the include files will be placed when you make install.
  195. # MANDIR is where the manuals will be placed when you make install.
  196. # MANEXT is the extension the manuals will receive in MANDIR
  197. X
  198. LIBDIR = /usr/local/lib
  199. INCLUDEDIR = /usr/local/include
  200. MANDIR = /usr/local/man/man3
  201. MANEXT = 3
  202. X
  203. X
  204. # Choose a suitable C compiler and appropriate flags:
  205. #CC = gcc
  206. CC = cc
  207. #CFLAGS = -g
  208. CFLAGS = -O
  209. X
  210. X
  211. # Choose a lexical analyzer generator:
  212. LEX = lex
  213. X
  214. X
  215. SHELL = /bin/sh
  216. RM = rm -f
  217. X
  218. X
  219. # ================================================================
  220. #           Don't change anything below this line.
  221. # ================================================================
  222. X
  223. DOCFILES = primitives.man shaders.man sipp.man sipp_pixmap.man geometric.man
  224. X
  225. X
  226. MAKEOPTS = CC=$(CC) LEX=$(LEX) \
  227. X    CFLAGS="$(NOVOID) $(NOMEMCPY) $(ALLOCA) $(CFLAGS) -I../libsipp"
  228. X        
  229. X
  230. all: library demos
  231. X
  232. library:
  233. X    cd libsipp; $(MAKE) $(MAKEOPTS) libsipp.a
  234. X
  235. demos:
  236. X    cd demo; $(MAKE) $(MAKEOPTS) programs
  237. X
  238. X
  239. install: library
  240. X    cd libsipp; $(MAKE) LIBDIR=$(LIBDIR) INCLUDEDIR=$(INCLUDEDIR) install
  241. X    for i in $(DOCFILES) ; do \
  242. X        cp doc/$$i $(MANDIR)/`basename $$i .man`.$(MANEXT); \
  243. X    done
  244. X
  245. X
  246. clean:
  247. X    $(RM) *~ *shar*
  248. X    cd libsipp; $(MAKE) clean;
  249. X    cd demo; $(MAKE) clean;
  250. X    cd doc;   ls -1 | egrep -v \.man$$ | xargs rm -f
  251. SHAR_EOF
  252. chmod 0644 Makefile ||
  253. echo 'restore of Makefile failed'
  254. Wc_c="`wc -c < 'Makefile'`"
  255. test 2495 -eq "$Wc_c" ||
  256.     echo 'Makefile: original size 2495, current size' "$Wc_c"
  257. fi
  258. # ============= README ==============
  259. if test -f 'README' -a X"$1" != X"-c"; then
  260.     echo 'x - skipping README (File already exists)'
  261. else
  262. echo 'x - extracting README (Text)'
  263. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  264. *******************************************************************
  265. X             sipp  --  3d rendering package
  266. X
  267. X             by         Jonas Yngvesson   jonas-y@isy.liu.se
  268. X                        Inge Wallin       ingwa@isy.liu.se
  269. X
  270. X             Linkoping Institute of Technology
  271. X             Sweden
  272. *******************************************************************
  273. X
  274. This is SIPP, the SImple Polygon Processor, version 2.1. SIPP is a
  275. library for creating 3-dimensional scenes and rendering them using a
  276. scan-line z-buffer algorithm. A scene is built up of objects which
  277. can be transformed with rotation, translation and scaling. The
  278. objects form hierarchies where each object can have arbitrarily many
  279. subobjects and subsurfaces. A surface is a number of connected
  280. polygons which are rendered with either Phong, Gouraud or flat
  281. shading.  An image can also be rendered as a line drawing of the
  282. polygon edges without any shading at all.
  283. X
  284. The library has an internal database for the objects that is to be
  285. rendered. Objects can be installed in, and removed from, this
  286. database at any time.
  287. X
  288. The library also provides 3-dimensional texture mapping with
  289. automatic interpolation of texture coordinates. Simple anti-aliasing
  290. can be performed through oversampling. A scene can be illuminated
  291. by an arbitrary number of light sources. A basic shading algorithm is
  292. provided with the library, but the user can also use his own shading
  293. algorithms for each surface to produce special effects.
  294. X
  295. Images can be rendered directly onto a file in the Portable Pixmap
  296. format (ppm) (or, for line images, Portable Bitmap, pbm) or into a
  297. pixmap (bitmap) in core. The representation of the pixmap is not
  298. restricted in any way. It can be any structure, or device, that is
  299. capable of plotting a pixel or drawing a line.
  300. X
  301. Version 2.1 should be fully compatible with previous versions (2.0.*) 
  302. and only a recompilation should be needed to update older programs.
  303. X
  304. The program has some bugs & limitations. See the BUGS entry in the
  305. manuals for more information. All bugs in version 2.0 which were
  306. reported to us have been fixed though.
  307. X
  308. To install the library, edit the Makefile and type 'make install'. If
  309. Your system does not have the drand48() random number generator,
  310. change the macro RANDOM() in sipp.h to use the random number
  311. generator available on your system.
  312. X
  313. If you only want to make the library but not install it, just type
  314. 'make library'.
  315. X
  316. If you want to make the tests and demonstrations, type 'make demos'. 
  317. X
  318. X
  319. Please send any enhancements, bug reports and fixes to us.
  320. Especially, if you create nice new object types, we would be
  321. grateful if you sent the C functions creating those to us. We could
  322. then compile a library of object functions and let other people share
  323. the benefits.
  324. X
  325. Linkoping 15 July 1991
  326. X
  327. X                enjoy! /Jonas & Inge
  328. SHAR_EOF
  329. chmod 0664 README ||
  330. echo 'restore of README failed'
  331. Wc_c="`wc -c < 'README'`"
  332. test 2832 -eq "$Wc_c" ||
  333.     echo 'README: original size 2832, current size' "$Wc_c"
  334. fi
  335. # ============= CHANGES ==============
  336. if test -f 'CHANGES' -a X"$1" != X"-c"; then
  337.     echo 'x - skipping CHANGES (File already exists)'
  338. else
  339. echo 'x - extracting CHANGES (Text)'
  340. sed 's/^X//' << 'SHAR_EOF' > 'CHANGES' &&
  341. Changes in version 2.1 vs. version 2.0.*
  342. X
  343. X    - Support for more rendering modes: Phong, Gouraud, flat and line.
  344. X      Only Phong mode can do real texture mapping though.
  345. X
  346. X    - Support for rendering into other places than files. We have chosen
  347. X      to call this rendering into pixmaps, but there is no restriction on
  348. X      what is really used. This is accomplished through a callback function
  349. X      similar to the shader interface. A basic implementation of pixmaps
  350. X      and bitmaps that could be used are supplied in the library.
  351. X
  352. X    - Oversampling for antialiasing can now be arbitrarily large.
  353. X
  354. X    - It is possible to turn off backface culling. This is useful if you
  355. X      have a database of objects that are inconsequent in the ordering
  356. X      of its vertices (clockwize/counterclockwize).
  357. X
  358. X    - Two new object primitives, cone and prism.
  359. X      Thanks to David Jones (djones@awesome.berkeley.edu) for these.
  360. X
  361. X    - Two new shaders. 
  362. X        1. strauss_shader() - This is an implementation of the shading 
  363. X           model designed by Paul S. Strauss at Silicon Graphics Inc.
  364. X           and described in IEEE CG&A November 1990.
  365. X        2. wood_shader() - A shader that simulates wood texture using
  366. X           noise and turbulence.
  367. X
  368. X    - Matrix and vector handling functions and macros are now "public".
  369. X
  370. X    - Correct interpolation of texture coordinates. Previously there
  371. X      were disturbing "rubberband" effects on objects spanning large
  372. X      depths in the picture.
  373. X
  374. X    - A full polygon clipper is now used instead of the previous, rather
  375. X      strange approach. Objects behind the viewpoint are now handled correctly
  376. X      (I hope), previously they caused strange effects.
  377. X
  378. X    - It is possible to get the current transformation matrix from an object
  379. X      and not only to set it. This makes it a lot easier to do animations.
  380. X
  381. X    - Subobjects and surfaces can now be removed from objects.
  382. SHAR_EOF
  383. chmod 0644 CHANGES ||
  384. echo 'restore of CHANGES failed'
  385. Wc_c="`wc -c < 'CHANGES'`"
  386. test 1907 -eq "$Wc_c" ||
  387.     echo 'CHANGES: original size 1907, current size' "$Wc_c"
  388. fi
  389. # ============= TODO ==============
  390. if test -f 'TODO' -a X"$1" != X"-c"; then
  391.     echo 'x - skipping TODO (File already exists)'
  392. else
  393. echo 'x - extracting TODO (Text)'
  394. sed 's/^X//' << 'SHAR_EOF' > 'TODO' &&
  395. X
  396. [Texinfo manual for SIPP.]
  397. X
  398. [Have the program whistle while it works with a verbose flag.
  399. X (Hmmm, I don't think I want this anymore  /Jonas)]
  400. X
  401. [Shaped lightsources, e.g. point, spotlight]
  402. X
  403. [Transparent objects]
  404. X
  405. [Colored lightsources]
  406. X
  407. [Shadows, see eg article in siggraph 87 about depth maps]
  408. X
  409. [Curved surface rendering (not siPp any longer)]
  410. X
  411. SHAR_EOF
  412. chmod 0664 TODO ||
  413. echo 'restore of TODO failed'
  414. Wc_c="`wc -c < 'TODO'`"
  415. test 346 -eq "$Wc_c" ||
  416.     echo 'TODO: original size 346, current size' "$Wc_c"
  417. fi
  418. # ============= ChangeLog ==============
  419. if test -f 'ChangeLog' -a X"$1" != X"-c"; then
  420.     echo 'x - skipping ChangeLog (File already exists)'
  421. else
  422. echo 'x - extracting ChangeLog (Text)'
  423. sed 's/^X//' << 'SHAR_EOF' > 'ChangeLog' &&
  424. Sun Jul 21 00:00:56 1991  Jonas Yngvesson  (jonas-y at gouraud)
  425. X
  426. X        * viewpoint.[ch]: Removed declaration and calculation of
  427. X          alfa and beta (perspective transformation constants).
  428. X          They are no longer needed (see last entry)
  429. X
  430. X        * Changed percpective transformation of the z-coordinate.
  431. X          It is now only scaled and stores the homogenous "coordinate".
  432. X
  433. X        * rendering.c: Changed interpolation of texture coordinates so
  434. X          it is done in perspective coordinates. They are transformed
  435. X          back just before calling the shader. Previously the texture on
  436. X          object spanning large depths showed disturbing "rubberband"
  437. X          effects. 
  438. X
  439. Thu Jul 18 19:52:17 1991  Jonas Yngvesson  (jonas-y at gouraud)
  440. X
  441. X        * New file: wood.c, a wood shader.
  442. X
  443. X        * New file: woodtest.c. demo of the wood shader.
  444. X
  445. Mon Jul 15 15:09:54 1991  Jonas Yngvesson  (jonas-y at gouraud)
  446. X
  447. X        * New file: strausstest.c in the demo directory. This program
  448. X          demonstrates the new strauss shader.
  449. X
  450. X        * Documented sipp_cone()
  451. X
  452. Fri Jul 12 19:37:29 1991  Jonas Yngvesson  (jonas-y at gouraud)
  453. X
  454. X        * Uppdated all demo/test programs to use the new function calls.
  455. X          Added switches to them to decide what rendering mode to use.
  456. X          Updated the Makefile and README file.
  457. X
  458. X        * New file: conetest.c, demonstration/test of the cone and
  459. X          cylinder primitive. cylindertest.c removed.
  460. X
  461. X        * cone.c: Installed David Jones cone code into the library.
  462. X          cylinder.c removed, cylinder is now a special case of a
  463. X          truncated cone.
  464. X
  465. Wed Jul 10 20:43:35 1991  Jonas Yngvesson  (jonas-y at gouraud)
  466. X
  467. X        * rendering.c: Changed create_edges() so that horizontal lines
  468. X          are not included in the edge lists. These were previously used
  469. X          when rendering line images, but no more (see Jul 1 1991).
  470. X          Changes in merge_edge_lists() and render_line() to comply
  471. X          with this.
  472. X
  473. X        * sipp.c is no more... It had grown out of proportions so I
  474. X          split it up into the following files:
  475. X
  476. X          rendering.[ch] - The actual rendering engine.
  477. X          lightsource.[ch] - Lightsource handling.
  478. X          objects.[ch] - Creation of objects and surfaces, object hierachy
  479. X                         handling and object database handling.
  480. X          smalloc.[ch] - "Safe" malloc and calloc.
  481. X          transforms.c - Object transformations.
  482. X          viewpoint.[ch] - Viewpoint and viewing transformation handling.
  483. X
  484. X          The old sipptypes.h is now (almost) rendering.h. All new .h files
  485. X          defines internal types and interfaces. Public ditos are as before
  486. X          defined in sipp.h
  487. X          
  488. X
  489. Sat Jul  6 01:07:08 1991  Jonas Yngvesson  (jonas-y at gouraud)
  490. X
  491. X        * sipp.c: New functions object_sub_subobj() and object_sub_surface()
  492. X          to remove a subobject and a surface from an object.
  493. X
  494. X        * sipp.c: New function object_get_transf() to retrieve the current
  495. X          transformation matrix of an object.
  496. X
  497. Fri Jul  5 20:38:12 1991  Inge Wallin  (ingwa at brassie)
  498. X
  499. X    * Updated the README file to tell about version 2.1 instead of
  500. X      2.0.2. 
  501. X
  502. X    * Moved the definition of Vector and Transf_mat to geometric.h
  503. X      instead of sipp.h. Also made the definition of ident_matrix
  504. X      public. 
  505. X
  506. X    * sipp_prism() documented.
  507. X
  508. X    * New file: geometric.man which documents all functions and macros
  509. X      dealing with vectors and matrixes.
  510. X
  511. X    * bitmap.[hc] changed name to sipp_bitmap.[hc]. Same for pixmap. 
  512. X
  513. X    * sipp_pixmap.man: Finished documenting the sipp_bitmap and
  514. X      sipp_pixmap implementations.
  515. X
  516. Mon Jul  1 17:50:01 1991  Jonas Yngvesson  (jonas-y at gouraud)
  517. X
  518. X        * sipp.c: Changed generation of line images so that the y_bucket
  519. X          and edge lists don't have to be allocated. It's faster and
  520. X          saves LOTS of memory. Lines are drawn directly in
  521. X          create_edges(). The bitmap support in bitmap.c are now used
  522. X          internally in sipp.c. 
  523. X
  524. X        * sipp.c: Changed the polygon clipper so clipping is performed 
  525. X          before the perspective transformation. Otherwize texture
  526. X          coordinates were destoyed by the clipping.
  527. X
  528. Tue Jun 25 23:48:44 1991  Inge Wallin      (jonas-y at brassie)
  529. X
  530. X        * New file: demo/prismtest.c replacing blocktest.c.
  531. X
  532. X        * New file: prism.c implementing the new object prism.  The file
  533. X          block.c is removed and the code for producing a block is
  534. X          rewritten to use prism instead.
  535. X
  536. X
  537. Tue Jun 25 14:45:59 1991  Jonas Yngvesson  (jonas-y at gouraud)
  538. X
  539. X        * New file: strauss.c implementing a more advanced shading
  540. X          model than the basic one (slower too...). The model is the
  541. X          one described by Paul Strauss in IEEE CG&A Nov. 1990.
  542. X          Changes in shaders.h also to support this shader.
  543. X
  544. X        * New files: bitmap.c and bitmap.h containing functions handling
  545. X          SIPP bitmaps. These functions could be used when rendering
  546. X          line images into bitmaps instead of files.
  547. X
  548. X        * sipp.c: Added support for rendering line images into bitmaps.
  549. X          The user provides a bitmap pointer and a line drawing function.
  550. X
  551. X        * sipp.c: A global flag decides if backface culling should be
  552. X          performed. If not, backfacing polygons are "inverted" and
  553. X          rendered as usual.
  554. X
  555. X        * sipp.c: Added a complete polygon clipper. Previously, strange
  556. X          things could happen if objects were behind the viewpoint.
  557. X
  558. Sat Jun  8 17:21:11 1991  Jonas Yngvesson  (jonas-y at gouraud)
  559. X
  560. X        * sipp.c: Support for rendering into pixmaps. A general storage
  561. X          function is called for each rendered line. Rendering of line 
  562. X          images into bitmaps is *NOT* yet supported. The user provides
  563. X          a pixmap pointer and a function to set a pixel in it.
  564. X
  565. Fri Jun  7 03:50:05 1991  Jonas Yngvesson  (jonas-y at brassie)
  566. X
  567. X        * sipp.c: Added support for new rendering modes: gouraud, flat
  568. X          and line. 
  569. X
  570. X        * sipp.c: Added support for arbitrary oversampling factors.
  571. X
  572. Fri Jun  7 02:34:20 1991  Inge Wallin  (ingwa at brassie)
  573. X
  574. X        * New file: pixmap.c containing functions for handling SIPP
  575. X          pixmaps. These functions could be used when rendering into
  576. X          a pixmap instead of a file.
  577. X
  578. X        * ChangeLog created.
  579. X
  580. These are all the older records:
  581. X
  582. 910527  Ver. 2.0.2. A major bug in traverse_object_tree() fixed.
  583. X        The invers transformation of the eyepoint was not correct, 
  584. X        causing polygons erroneously to be marked as backfacing.
  585. X
  586. 910412  Ver. 2.0.1. Some minor bugfixes. Division by zero in
  587. X        create_edges() if an edge was horizontal in both x and y.
  588. X        Free-list became corrupted since the y_bucket was freed
  589. X        twice. Wrong parameters to (D)noise() in bumpy.c. Two lines
  590. X        interchanged in mat_rotate(). A few other minor changes.
  591. X
  592. 901219  At last! 2.0 is out of the bag. And right in time for X-mas :-)
  593. X        *Major* rewrite. A new level in the object hierarchy introduced.
  594. X        An object is now a collection of surfaces and other objects
  595. X        (subobjects). This allows creation of complex composite objects.
  596. X        Objects in the hierarchy have coupled transformations.
  597. X        The old "Object" is now, more appropriately, called Surface.
  598. X        A fatal bug in the viewing transformation fixed.
  599. X        Objects and surfaces have internal reference counters so deletion
  600. X        won't leave dangling references in an hierachy.
  601. X        The code is now almost readable.
  602. X        Images format changed to PPM since much more applications
  603. X        exists that can handle that format.
  604. X        The shader package is extended and a package with functions
  605. X        to create geometric primitives as objects is provided.
  606. X
  607. 901030  More general shader interface. The simple internal shader
  608. X        was moved out of sipp into its own file. Several shaders
  609. X        provided together with it in a "shader package".
  610. X
  611. 900712  Major code beautifying, quite a lot left to do though...
  612. X        Typedefs instead of raw structures,
  613. X        much better typenames, lots of comments added (probably
  614. X        not enough though). Split into a few header files and
  615. X        a source file. More portable interface.
  616. X
  617. 891124  Made the object representation independent of the
  618. X        illumination model used. A user can now supply his
  619. X        own surface description and shading function.
  620. X        Added support for texture mapping (both solid and 2d).
  621. X        No texture mapping is built into the internal shader though.
  622. X
  623. 891120  Added colour. New illumination model. Simple antialiasing
  624. X        with double oversampling and a box filter.
  625. X
  626. 891028  Converted from sippuz to sipp. Z-buffer changed 
  627. X        to scan-line z-buffer.
  628. X        Phong-shading.
  629. X        The stack notion introduced.
  630. X        Changed fixed viewpoint to a user defined one.
  631. X        World coordinates and picture resolution can be chosen
  632. X        freely.
  633. X
  634. 881128  Converted from Pascal to C. Gouraud shading. Redesign of the
  635. X        data structures.
  636. X
  637. 88????  Original program "sippuz - simple polygon processing using a
  638. X        z-buffer", written in Hedrick Pascal on a DEC-20 system
  639. X        running TOPS-20. Greyscales only. Flat shading.
  640. SHAR_EOF
  641. chmod 0664 ChangeLog ||
  642. echo 'restore of ChangeLog failed'
  643. Wc_c="`wc -c < 'ChangeLog'`"
  644. test 9212 -eq "$Wc_c" ||
  645.     echo 'ChangeLog: original size 9212, current size' "$Wc_c"
  646. fi
  647. # ============= libsipp/Makefile ==============
  648. if test ! -d 'libsipp'; then
  649.     echo 'x - creating directory libsipp'
  650.     mkdir 'libsipp'
  651. fi
  652. if test -f 'libsipp/Makefile' -a X"$1" != X"-c"; then
  653.     echo 'x - skipping libsipp/Makefile (File already exists)'
  654. else
  655. echo 'x - extracting libsipp/Makefile (Text)'
  656. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/Makefile' &&
  657. #
  658. # Makefile for libsipp.a
  659. #
  660. X
  661. #These values are default if they are not overridden from the command line:
  662. CC = cc
  663. CFLAGS = -pipe -I. -g
  664. X
  665. SHELL = /bin/sh
  666. RM = rm -f
  667. X
  668. IHDRS = bezier.h lightsource.h noise.h objects.h rendering.h smalloc.h \
  669. X        viewpoint.h
  670. EHDRS = sipp.h geometric.h shaders.h primitives.h sipp_pixmap.h sipp_bitmap.h
  671. HDRS = $(IHDRS) $(EHDRS)
  672. SRCS =  rendering.c geometric.c lightsource.c objects.c smalloc.c \
  673. X        transforms.c viewpoint.c \
  674. X    basic_shader.c mask.c marble.c granite.c noise.c bozo.c bumpy.c \
  675. X    planet.c strauss.c wood.c \
  676. X    prism.c cone.c ellipsoid.c torus.c bezier.c bezier_lex.l \
  677. X        sipp_pixmap.c sipp_bitmap.c
  678. LIBOBJS = libsipp.a(rendering.o) libsipp.a(geometric.o) \
  679. X          libsipp.a(lightsource.o) libsipp.a(objects.o) libsipp.a(smalloc.o) \
  680. X          libsipp.a(transforms.o) libsipp.a(viewpoint.o) \
  681. X          libsipp.a(basic_shader.o) libsipp.a(strauss.o) libsipp.a(wood.o) \
  682. X          libsipp.a(marble.o) libsipp.a(granite.o) libsipp.a(mask.o)\
  683. X          libsipp.a(bozo.o) libsipp.a(bumpy.o) libsipp.a(planet.o)\
  684. X          libsipp.a(noise.o) libsipp.a(bezier.o) libsipp.a(bezier_lex.o)\
  685. X          libsipp.a(torus.o) libsipp.a(cone.o) libsipp.a(ellipsoid.o) \
  686. X          libsipp.a(prism.o)\
  687. X          libsipp.a(sipp_pixmap.o) libsipp.a(sipp_bitmap.o)\
  688. X      libsipp.a(xalloca.o)
  689. X
  690. X
  691. # These are used if no other values are given at the command line:
  692. LIBDIR = /usr/local/lib
  693. INCLUDEDIR = /usr/local/include
  694. X
  695. X
  696. all: libsipp.a
  697. X
  698. libsipp.a:      $(LIBOBJS)
  699. X    ranlib libsipp.a
  700. X    $(RM) bezier_lex.c
  701. X
  702. install: libsipp.a $(EHDRS)
  703. X    cp libsipp.a $(LIBDIR)
  704. X    cp $(EHDRS) $(INCLUDEDIR)
  705. X
  706. X
  707. tags:
  708. X    etags -t $(HDRS) $(SRCS)
  709. X
  710. clean: 
  711. X    $(RM) *.o *~ TAGS libsipp.a
  712. X
  713. X
  714. libsipp.a(rendering.o):         sipp.h rendering.h lightsource.h geometric.h \
  715. X                                objects.h sipp_bitmap.h viewpoint.h smalloc.h \
  716. X                                patchlevel.h
  717. libsipp.a(geometric.o):         geometric.h sipp.h
  718. libsipp.a(lightsource.o):       geometric.h lightsource.h sipp.h smalloc.h
  719. libsipp.a(objects.o):           sipp.h objects.h smalloc.h
  720. libsipp.a(smalloc.o):           
  721. libsipp.a(transforms.o):        geometric.h sipp.h
  722. libsipp.a(viewpoint.o):         geometric.h viewpoint.h
  723. libsipp.a(basic_shader.o):      sipp.h
  724. libsipp.a(strauss.o):           sipp.h shaders.h geometric.h
  725. libsipp.a(mask.o):              shaders.h sipp.h
  726. libsipp.a(marble.o):            noise.h shaders.h sipp.h
  727. libsipp.a(granite.o):           noise.h shaders.h sipp.h
  728. libsipp.a(wood.o):              noise.h shaders.h sipp.h
  729. libsipp.a(bozo.o):              noise.h shaders.h sipp.h
  730. libsipp.a(bumpy.o):             noise.h shaders.h sipp.h geometric.h
  731. libsipp.a(planet.o):            noise.h sipp.h geometric.h
  732. libsipp.a(noise.o):             noise.h sipp.h
  733. libsipp.a(bezier.o):            bezier.h sipp.h
  734. libsipp.a(bezier_lex.o):        bezier.h
  735. libsipp.a(torus.o):             sipp.h
  736. libsipp.a(ellipsoid.o):         sipp.h
  737. libsipp.a(prism.o):             sipp.h
  738. libsipp.a(cone.o):              sipp.h
  739. libsipp.a(sipp_pixmap.o):       sipp_pixmap.h sipp.h patchlevel.h
  740. libsipp.a(sipp_bitmap.o):       sipp_bitmap.h sipp.h patchlevel.h
  741. libsipp.a(xalloca.o):           xalloca.h
  742. SHAR_EOF
  743. chmod 0644 libsipp/Makefile ||
  744. echo 'restore of libsipp/Makefile failed'
  745. Wc_c="`wc -c < 'libsipp/Makefile'`"
  746. test 3187 -eq "$Wc_c" ||
  747.     echo 'libsipp/Makefile: original size 3187, current size' "$Wc_c"
  748. fi
  749. # ============= libsipp/basic_shader.c ==============
  750. if test -f 'libsipp/basic_shader.c' -a X"$1" != X"-c"; then
  751.     echo 'x - skipping libsipp/basic_shader.c (File already exists)'
  752. else
  753. echo 'x - extracting libsipp/basic_shader.c (Text)'
  754. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/basic_shader.c' &&
  755. /**
  756. X ** sipp - SImple Polygon Processor
  757. X **
  758. X **  A general 3d graphic package
  759. X **
  760. X **  Copyright Jonas Yngvesson  (jonas-y@isy.liu.se) 1988/89/90/91
  761. X **            Inge Wallin      (ingwa@isy.liu.se)         1990/91
  762. X **
  763. X ** This program is free software; you can redistribute it and/or modify
  764. X ** it under the terms of the GNU General Public License as published by
  765. X ** the Free Software Foundation; either version 1, or any later version.
  766. X ** This program is distributed in the hope that it will be useful,
  767. X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  768. X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  769. X ** GNU General Public License for more details.
  770. X ** You can receive a copy of the GNU General Public License from the
  771. X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  772. X **/
  773. X
  774. /**
  775. X ** basic_shader.c - Basic shading model, somewhat modified and 
  776. X **                  simplified version of Blinn's
  777. X **/
  778. X
  779. #include <math.h>
  780. X
  781. #include <sipp.h>
  782. X
  783. X
  784. void
  785. basic_shader(a, b, c, u, v, w, view_vec, lights, sd, color)
  786. X    double       a, b, c, u, v, w;
  787. X    Vector       view_vec;
  788. X    Lightsource *lights;
  789. X    Surf_desc   *sd;
  790. X    Color       *color;
  791. {
  792. X    double       nx, ny, nz, l;
  793. X    double       xs, ys, zs;
  794. X    double       coss, cosi, diffsum, specsum;
  795. X    double       c3two;
  796. X    Lightsource *lp;
  797. X
  798. X    l = (a * a + b * b + c * c);
  799. X    nx = a;
  800. X    ny = b;
  801. X    nz = c;
  802. X    if (fabs(l - 1.0) > 1e-5) {
  803. X        l = sqrt(l);
  804. X        nx /= l;
  805. X        ny /= l;
  806. X        nz /= l;
  807. X    }
  808. X    diffsum = specsum = 0;
  809. X    c3two = sd->c3 * sd->c3;
  810. X    for (lp = lights; lp != (Lightsource *)0; lp = lp->next) {
  811. X        cosi = (lp->dir.x * nx + lp->dir.y * ny + lp->dir.z * nz);
  812. X         if (cosi > 0)
  813. X            diffsum += cosi * lp->intensity;
  814. X        cosi *= -2.0;
  815. X        xs = -lp->dir.x - cosi * nx;
  816. X        ys = -lp->dir.y - cosi * ny;
  817. X        zs = -lp->dir.z - cosi * nz;
  818. X        coss = (xs * view_vec.x + ys * view_vec.y + zs * view_vec.z);
  819. X        if (coss > 0)
  820. X            specsum += lp->intensity * c3two * coss / 
  821. X                                   (coss * coss * (c3two -1) + 1);
  822. X    }
  823. X    color->red = (sd->color.red * (sd->ambient + diffsum) + sd->specular
  824. X                  * specsum); 
  825. X    if (color->red > 1.0) color->red = 1.0;
  826. X    color->grn = (sd->color.grn * (sd->ambient + diffsum) + sd->specular
  827. X                  * specsum); 
  828. X    if (color->grn > 1.0) color->grn = 1.0;
  829. X    color->blu = (sd->color.blu * (sd->ambient + diffsum) + sd->specular
  830. X                  * specsum);
  831. X    if (color->blu > 1.0) color->blu = 1.0;
  832. }
  833. X
  834. X
  835. X
  836. SHAR_EOF
  837. chmod 0664 libsipp/basic_shader.c ||
  838. echo 'restore of libsipp/basic_shader.c failed'
  839. Wc_c="`wc -c < 'libsipp/basic_shader.c'`"
  840. test 2591 -eq "$Wc_c" ||
  841.     echo 'libsipp/basic_shader.c: original size 2591, current size' "$Wc_c"
  842. fi
  843. # ============= libsipp/bezier.c ==============
  844. if test -f 'libsipp/bezier.c' -a X"$1" != X"-c"; then
  845.     echo 'x - skipping libsipp/bezier.c (File already exists)'
  846. else
  847. echo 'x - extracting libsipp/bezier.c (Text)'
  848. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bezier.c' &&
  849. /**
  850. X ** sipp - SImple Polygon Processor
  851. X **
  852. X **  A general 3d graphic package
  853. X **
  854. X **  Copyright Jonas Yngvesson  (jonas-y@isy.liu.se) 1988/89/90/91
  855. X **            Inge Wallin      (ingwa@isy.liu.se)         1990/91
  856. X **
  857. X ** This program is free software; you can redistribute it and/or modify
  858. X ** it under the terms of the GNU General Public License as published by
  859. X ** the Free Software Foundation; either version 1, or any later version.
  860. X ** This program is distributed in the hope that it will be useful,
  861. X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  862. X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  863. X ** GNU General Public License for more details.
  864. X ** You can receive a copy of the GNU General Public License from the
  865. X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  866. X **/
  867. X
  868. /**
  869. X ** bezier.c - Reading bezier descriptions and creating objects.
  870. X **/
  871. X
  872. #include <math.h>
  873. #include <stdio.h>
  874. X
  875. #include "sipp.h"
  876. #include "bezier.h"
  877. X
  878. X
  879. Tokenval     tokenval;
  880. extern FILE *yyin;
  881. X
  882. X
  883. /*================================================================*/
  884. /*                                                                */
  885. /*      Functions for reading bezier descriptions from file       */
  886. /*                                                                */
  887. /*================================================================*/
  888. X
  889. X
  890. /*
  891. X * Read a vertex list, where each vertex is an xyz triple, and 
  892. X * install it in the bezier structure.
  893. X */
  894. static void
  895. vertex_read(obj)
  896. X    Bez_Object *obj;
  897. {
  898. X    int token;
  899. X    int i, j;
  900. X
  901. X    token = yylex();
  902. X    if (token != NVERTICES) {
  903. X        fprintf(stderr, "Corrupt vertex description.\n");
  904. X        goto errout;
  905. X    }
  906. X    
  907. X    token = yylex();
  908. X    if (token != INTEGER) {
  909. X        fprintf(stderr, "Corrupt vertex description.\n");
  910. X        goto errout;
  911. X    }
  912. X    obj->nvertex = tokenval.intval;
  913. X    obj->vertex = (Bez_Vertex *)malloc(obj->nvertex * sizeof(Bez_Vertex));
  914. X    if (obj->vertex == NULL) {
  915. X        fprintf(stderr, "vertex_read: Out of core.\n");
  916. X        goto errout;
  917. X    }
  918. X
  919. X    token = yylex();
  920. X    if (token != VERTEX_LIST) {
  921. X        fprintf(stderr, "Corrupt vertex description.\n");
  922. X        goto errout;
  923. X    }
  924. X
  925. X    for (i = 0; i < obj->nvertex; i++) {
  926. X        for (j = 0; j < 3; j++) {
  927. X            token = yylex();
  928. X            if (token != FLOAT && token != INTEGER) {
  929. X                fprintf(stderr, "Corrupt vertex description.\n");
  930. X                goto errout;
  931. X            }
  932. X            if (token == FLOAT) {
  933. X                obj->vertex[i].coor[j] = tokenval.floatval;
  934. X            } else {
  935. X                obj->vertex[i].coor[j] = (double)tokenval.intval;
  936. X            }
  937. X        }
  938. X    }
  939. X
  940. X    return;
  941. X
  942. X  errout:
  943. X    if (obj->vertex != NULL) {
  944. X        free(obj->vertex);
  945. X        obj->vertex = NULL;
  946. X    }
  947. }
  948. X
  949. X    
  950. X
  951. /*
  952. X * Read a list of bezier curves, where each curve consists of 
  953. X * four control points (index into the vertex list), and install 
  954. X * it in the bezier structure.
  955. X */
  956. static void
  957. curve_read(obj)
  958. X    Bez_Object *obj;
  959. {
  960. X    int         token;
  961. X    int         i, j;
  962. X
  963. X    token = yylex();
  964. X    if (token != NCURVES) {
  965. X        fprintf(stderr, "Corrupt curve description.\n");
  966. X        goto errout;
  967. X    }
  968. X    
  969. X    token = yylex();
  970. X    if (token != INTEGER) {
  971. X        fprintf(stderr, "Corrupt curve description.\n");
  972. X        goto errout;
  973. X    }
  974. X    obj->n.ncurves = tokenval.intval;
  975. X    obj->cp.ccp = (Bez_Curve *)malloc(obj->n.ncurves * sizeof(Bez_Curve));
  976. X    if (obj->cp.ccp == NULL) {
  977. X        fprintf(stderr, "curve_read: Out of core.\n");
  978. X        goto errout;
  979. X    }
  980. X
  981. X    token = yylex();
  982. X    if (token != CURVE_LIST) {
  983. X        fprintf(stderr, "Corrupt curve description.\n");
  984. X        goto errout;
  985. X    }
  986. X
  987. X    for (i = 0; i < obj->n.ncurves; i++) {
  988. X        for (j = 0; j < 4; j++) {
  989. X            token = yylex();
  990. X            if (token != INTEGER) {
  991. X                fprintf(stderr, "Corrupt curve description.\n");
  992. X                goto errout;
  993. X            }
  994. X            obj->cp.ccp[i].cp[j] = tokenval.intval - 1;
  995. X        }
  996. X    }
  997. X
  998. X    return;
  999. X
  1000. X  errout:
  1001. X    if (obj->cp.ccp != NULL) {
  1002. X        free(obj->cp.ccp);
  1003. X        obj->cp.ccp = NULL;
  1004. X    }
  1005. }
  1006. X
  1007. X
  1008. X    
  1009. /*
  1010. X * Read a list of bezier patches, where each patch consists of 
  1011. X * sixteen control points (index into the vertex list), and install 
  1012. X * it in the bezier structure.
  1013. X */
  1014. static void
  1015. patch_read(obj)
  1016. X    Bez_Object *obj;
  1017. {
  1018. X    int         token;
  1019. X    int         i, j, k;
  1020. X
  1021. X    token = yylex();
  1022. X    if (token != NPATCHES) {
  1023. X        fprintf(stderr, "Corrupt patch description.\n");
  1024. X        goto errout;
  1025. X    }
  1026. X    
  1027. X    token = yylex();
  1028. X    if (token != INTEGER) {
  1029. X        fprintf(stderr, "Corrupt patch description.\n");
  1030. X        goto errout;
  1031. X    }
  1032. X    obj->n.npatches = tokenval.intval;
  1033. X    obj->cp.pcp = (Bez_Patch *)malloc(obj->n.npatches * sizeof(Bez_Patch));
  1034. X    if (obj->cp.pcp == NULL) {
  1035. X        fprintf(stderr, "patch_read: Out of core.\n");
  1036. X        goto errout;
  1037. X    }
  1038. X
  1039. X    token = yylex();
  1040. X    if (token != PATCH_LIST) {
  1041. X        fprintf(stderr, "Corrupt patch description.\n");
  1042. X        goto errout;
  1043. X    }
  1044. X
  1045. X    for (i = 0; i < obj->n.npatches; i++) {
  1046. X        for (j = 0; j < 4; j++) {
  1047. X            for (k = 0; k < 4; k++) {
  1048. X                token = yylex();
  1049. X                if (token != INTEGER) {
  1050. X                    fprintf(stderr, "Corrupt patch description.\n");
  1051. X                    goto errout;
  1052. X                }
  1053. X                obj->cp.pcp[i].cp[j][k] = tokenval.intval - 1;
  1054. X            }
  1055. X        }
  1056. X    }
  1057. X
  1058. X    return;
  1059. X
  1060. X  errout:
  1061. X    if (obj->cp.pcp != NULL) {
  1062. X        free(obj->cp.pcp);
  1063. X        obj->cp.pcp = NULL;
  1064. X    }
  1065. }
  1066. X
  1067. X
  1068. X    
  1069. /*
  1070. X * Read a bezier object from a file, i.e. determine if it is a
  1071. X * curve or patch description,  read vertex and curve or patch 
  1072. X * description. Build a bezier object from the data.
  1073. X */
  1074. Bez_Object *
  1075. bezier_read(file)
  1076. X    FILE *file;
  1077. {
  1078. X    int token;
  1079. X    Bez_Object *obj;
  1080. X
  1081. X
  1082. X    yyin = file;
  1083. X
  1084. X    obj = (Bez_Object *)calloc(1, sizeof(Bez_Object));
  1085. X    if (obj == NULL) {
  1086. X        fprintf(stderr, "bezier_read: Out of core.\n");
  1087. X        return obj;
  1088. X    }
  1089. X    if ((token = yylex()) == PATCHES) {
  1090. X        obj->type = PATCHES;
  1091. X        vertex_read(obj);
  1092. X        if (obj->vertex == NULL) {
  1093. X            goto errout;
  1094. X        }
  1095. X        patch_read(obj);
  1096. X        if (obj->cp.pcp == NULL) {
  1097. X            goto errout;
  1098. X        }
  1099. X    } else if (token == CURVES) {
  1100. X        obj->type = CURVES;
  1101. X        vertex_read(obj);
  1102. X        if (obj->vertex == NULL) {
  1103. X            goto errout;
  1104. X        }
  1105. X        curve_read(obj);
  1106. X        if (obj->cp.ccp == NULL) {
  1107. X            goto errout;
  1108. X        }
  1109. X    } else {
  1110. X        fprintf(stderr, "Corrupt bezier description file: %s\n", file);
  1111. X        return NULL;
  1112. X    }
  1113. X
  1114. X    return obj;
  1115. X
  1116. X  errout:
  1117. X    if (obj != NULL) {
  1118. X        if (obj->vertex != NULL) {
  1119. X            free(obj->vertex);
  1120. X        }
  1121. X        if (obj->cp.pcp != NULL) {
  1122. X            free(obj->cp.pcp);
  1123. X        }
  1124. X        free(obj);
  1125. X    }
  1126. X    return NULL;
  1127. }
  1128. X
  1129. X
  1130. /*================================================================*/
  1131. /*                                                                */
  1132. /*           Functions for evaluating bezier functions            */
  1133. /*                                                                */
  1134. /*================================================================*/
  1135. X
  1136. static double
  1137. C(i)
  1138. X    int i;
  1139. {
  1140. X    int j, a;
  1141. X
  1142. X    a = 1;
  1143. X    for (j = i + 1; j < 4; j++) {
  1144. X        a = a * j;
  1145. X    }
  1146. X    for (j = 1 ; j < 4 - i; j++) {
  1147. X        a = a / j;
  1148. X    }
  1149. X
  1150. X    return (double)a;
  1151. }
  1152. X
  1153. X
  1154. static double 
  1155. bblend(i, u)
  1156. X    int    i;
  1157. X    double u;
  1158. {
  1159. X    int j;
  1160. X    double v;
  1161. X
  1162. X    v = C(i);
  1163. X    for (j = 1; j <= i; j++) {
  1164. X        v *= u;
  1165. X    }
  1166. X    for (j = 1; j < 4 - i; j++) {
  1167. X        v *= 1.0 - u;
  1168. X    }
  1169. X
  1170. X    if (fabs(v) < 1.0E-15) {
  1171. X        return 0.0;
  1172. X    } else {
  1173. X        return v;
  1174. X    }
  1175. }
  1176. X
  1177. X
  1178. /*
  1179. X * Determine x, y and z coordinates of a point on the bezier
  1180. X * curve described by CURVE and VERTEX. U is a parameter between
  1181. X * 0 and 1 that determines how far "into" the curve we are.
  1182. X */
  1183. static void
  1184. bez_curve_eval(vertex, curve, u, x, y, z)
  1185. X    Bez_Vertex *vertex;
  1186. X    Bez_Curve  *curve;
  1187. X    double      u;
  1188. X    double     *x, *y, *z;
  1189. {
  1190. X    int    i;
  1191. X    double b;
  1192. X
  1193. X    *x = 0;
  1194. X    *y = 0;
  1195. X    *z = 0;
  1196. X    
  1197. X    for (i = 0; i < 4; i++) {
  1198. X        b = bblend(i, u);
  1199. X        *x += vertex[curve->cp[i]].coor[0] * b;
  1200. X        *y += vertex[curve->cp[i]].coor[1] * b;
  1201. X        *z += vertex[curve->cp[i]].coor[2] * b;
  1202. X    }
  1203. }
  1204. X
  1205. X
  1206. /*
  1207. X * Determine x, y and z coordinates of a point on the bezier
  1208. X * patch described by PATCH and VERTEX. U and V are parameters
  1209. X * between 0 and 1 that determines where on the patch we are.
  1210. X */
  1211. static void
  1212. bez_patch_eval(vertex, patch, v, u, x, y, z)
  1213. X    Bez_Vertex *vertex;
  1214. X    Bez_Patch  *patch;
  1215. X    double      u, v;
  1216. X    double     *x, *y, *z;
  1217. {
  1218. X    int i, j;
  1219. X    double b;
  1220. X
  1221. X    *x = 0;
  1222. X    *y = 0;
  1223. X    *z = 0;
  1224. X
  1225. X    for (i = 0; i < 4; i++) {
  1226. X        for (j = 0; j < 4; j++) {
  1227. X            b   = bblend(i, v);
  1228. X            b  *= bblend(j, u);
  1229. X            *x += vertex[patch->cp[i][j]].coor[0] * b;
  1230. X            *y += vertex[patch->cp[i][j]].coor[1] * b;
  1231. X            *z += vertex[patch->cp[i][j]].coor[2] * b;
  1232. X        }
  1233. X    }
  1234. }
  1235. X
  1236. X
  1237. X
  1238. /*================================================================*/
  1239. /*                                                                */
  1240. /*             Functions for creating bezier objects              */
  1241. /*             (these functions are SIPP specific)                */
  1242. /*                                                                */
  1243. /*================================================================*/
  1244. X
  1245. X
  1246. /*
  1247. X * Approximate the bezier patches described in OBJ with polygons
  1248. X * and create a SIPP surface out of them. The patches will be 
  1249. X * tesselated into RESxRES polygons (rectangles).
  1250. X */
  1251. Surface *
  1252. bezier_patches(obj, res, surface, shader)
  1253. X    Bez_Object *obj;
  1254. X    int         res;
  1255. X    void       *surface;
  1256. X    Shader     *shader;
  1257. {
  1258. X    double  x, y, z;
  1259. X    double  u, v;
  1260. X    double  step;
  1261. X    int     i, j, k;
  1262. X
  1263. X    step = 1.0 / (double)res;
  1264. X    
  1265. X    for (i = 0; i < obj->n.npatches; i++) {
  1266. X        for (v = 0.0, j = 0; j < res; j++, v += step) {
  1267. X            for (u = 0.0, k = 0; k < res; k++, u += step) {
  1268. X                bez_patch_eval(obj->vertex, &obj->cp.pcp[i], v, u, &x, &y, &z);
  1269. X                vertex_tx_push(x, y, z, x, y, z);
  1270. X                bez_patch_eval(obj->vertex, &obj->cp.pcp[i], v, u + step,
  1271. X                               &x, &y, &z); 
  1272. X                vertex_tx_push(x, y, z, x, y, z);
  1273. X                bez_patch_eval(obj->vertex, &obj->cp.pcp[i], 
  1274. X                               v + step, u + step, &x, &y, &z);
  1275. X                vertex_tx_push(x, y, z, x, y, z);
  1276. X                bez_patch_eval(obj->vertex, &obj->cp.pcp[i], v + step, u, 
  1277. X                               &x, &y, &z);
  1278. X                vertex_tx_push(x, y, z, x, y, z);
  1279. X                polygon_push();
  1280. X            }
  1281. X        }
  1282. X    }
  1283. X    return surface_create(surface, shader);
  1284. }
  1285. X
  1286. X
  1287. X
  1288. /*
  1289. X * Take the bezier curves described in OBJ and create a
  1290. X * surface by rotating them about th y-axis. The object
  1291. X * will be tesselated as RESx(RES*4) polygons per curve.
  1292. X * (The reason for using 4 times the resolution is rather
  1293. X * "handwavy". I think 90 degrees is about as much as a
  1294. X * patch should cover of a rotational body.)
  1295. X */
  1296. Surface *
  1297. bezier_rot_curves(obj, res, surface, shader)
  1298. X    Bez_Object *obj;
  1299. X    int         res;
  1300. X    void       *surface;
  1301. X    Shader     *shader;
  1302. {
  1303. X    double  x1, y1, z1;
  1304. X    double  x2, y2, z2;
  1305. X    double  xtmp;
  1306. X    double  u;
  1307. X    double  step;
  1308. X    double  ca, sa;
  1309. X    int     i, j, k;
  1310. X
  1311. X    step = 1.0 / (double)res;
  1312. X    ca = cos(2.0 * M_PI / (4.0 * (double)res));
  1313. X    sa = sin(2.0 * M_PI / (4.0 * (double)res));
  1314. X
  1315. X    for (i = 0; i < obj->n.ncurves; i++) {
  1316. X        for (u = 0.0, j = 0; j < res; j++, u += step) {
  1317. X            bez_curve_eval(obj->vertex, &obj->cp.ccp[i], u, 
  1318. X                           &x1, &y1, &z1);
  1319. X            bez_curve_eval(obj->vertex, &obj->cp.ccp[i], u + step, 
  1320. X                           &x2, &y2, &z2);
  1321. X            vertex_tx_push(x1, y1, z1, x1, y1, z1);
  1322. X            vertex_tx_push(x2, y2, z2, x2, y2, z2);
  1323. X            for (k = 0; k < 4 * res; k++) {
  1324. X                xtmp = ca * x1 + sa * z1;
  1325. X                z1   = ca * z1 - sa * x1;
  1326. X                x1   = xtmp;
  1327. X                xtmp = ca * x2 + sa * z2;
  1328. X                z2   = ca * z2 - sa * x2;
  1329. X                x2   = xtmp;
  1330. X                vertex_tx_push(x2, y2, z2, x2, y2, z2);
  1331. X                vertex_tx_push(x1, y1, z1, x1, y1, z1);
  1332. X                polygon_push();
  1333. X
  1334. X                if (k == 4 * res - 1) {
  1335. X                    break;
  1336. X                }
  1337. X
  1338. X                vertex_tx_push(x1, y1, z1, x1, y1, z1);
  1339. X                vertex_tx_push(x2, y2, z2, x2, y2, z2);
  1340. X            }
  1341. X        }
  1342. X    }
  1343. X    
  1344. X    return surface_create(surface, shader);
  1345. }
  1346. X
  1347. X
  1348. X
  1349. /*
  1350. X * Read a bezier description from FILE and build
  1351. X * a bezier surface. Tesselate this object into
  1352. X * polygons and return a pointer to a SIPP object.
  1353. X */
  1354. Object *
  1355. sipp_bezier(file, res, surface, shader)
  1356. X    FILE    *file;
  1357. X    int      res;
  1358. X    void    *surface;
  1359. X    Shader  *shader;
  1360. {
  1361. X    Object     *obj;
  1362. X    Bez_Object *bez_obj;
  1363. X
  1364. X    bez_obj = bezier_read(file);
  1365. X    if (bez_obj == NULL) {
  1366. X        return NULL;
  1367. X    }
  1368. X
  1369. X    obj = object_create();
  1370. X    if (bez_obj->type == PATCHES) {
  1371. X        object_add_surface(obj, bezier_patches(bez_obj, res, surface, shader));
  1372. X    } else {
  1373. X        object_add_surface(obj, bezier_rot_curves(bez_obj, res, surface,
  1374. X                                                  shader)); 
  1375. X    }
  1376. X
  1377. X    return obj;
  1378. }
  1379. SHAR_EOF
  1380. chmod 0664 libsipp/bezier.c ||
  1381. echo 'restore of libsipp/bezier.c failed'
  1382. Wc_c="`wc -c < 'libsipp/bezier.c'`"
  1383. test 13510 -eq "$Wc_c" ||
  1384.     echo 'libsipp/bezier.c: original size 13510, current size' "$Wc_c"
  1385. fi
  1386. # ============= libsipp/bezier.h ==============
  1387. if test -f 'libsipp/bezier.h' -a X"$1" != X"-c"; then
  1388.     echo 'x - skipping libsipp/bezier.h (File already exists)'
  1389. else
  1390. echo 'x - extracting libsipp/bezier.h (Text)'
  1391. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bezier.h' &&
  1392. /**
  1393. X ** sipp - SImple Polygon Processor
  1394. X **
  1395. X **  A general 3d graphic package
  1396. X **
  1397. X **  Copyright Jonas Yngvesson  (jonas-y@isy.liu.se) 1988/89/90/91
  1398. X **            Inge Wallin      (ingwa@isy.liu.se)         1990/91
  1399. X **
  1400. X ** This program is free software; you can redistribute it and/or modify
  1401. X ** it under the terms of the GNU General Public License as published by
  1402. X ** the Free Software Foundation; either version 1, or any later version.
  1403. X ** This program is distributed in the hope that it will be useful,
  1404. X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  1405. X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1406. X ** GNU General Public License for more details.
  1407. X ** You can receive a copy of the GNU General Public License from the
  1408. X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1409. X **/
  1410. X
  1411. /**
  1412. X ** bezier.h - Types and defines needed by bezier.c
  1413. X **/
  1414. X
  1415. #ifndef BEZIER_H
  1416. #define BEZIER_H
  1417. X
  1418. X
  1419. #define PATCHES     1
  1420. #define CURVES      2
  1421. #define NVERTICES   3
  1422. #define NPATCHES    4
  1423. #define NCURVES     5
  1424. #define VERTEX_LIST 6
  1425. #define PATCH_LIST  7
  1426. #define CURVE_LIST  8
  1427. #define INTEGER     9
  1428. #define FLOAT       10
  1429. X
  1430. X
  1431. typedef union {
  1432. X    int    intval;
  1433. X    double floatval;
  1434. } Tokenval;
  1435. X
  1436. X
  1437. typedef struct {
  1438. X    double coor[3];
  1439. } Bez_Vertex;
  1440. X
  1441. typedef struct {
  1442. X    int cp[4];
  1443. } Bez_Curve;
  1444. X
  1445. typedef struct {
  1446. X    int cp[4][4];
  1447. } Bez_Patch;
  1448. X
  1449. typedef struct {
  1450. X    int         type;
  1451. X    int         nvertex;
  1452. X    Bez_Vertex *vertex;
  1453. X    union {
  1454. X        int ncurves;
  1455. X        int npatches;
  1456. X    } n;
  1457. X    union {
  1458. X        Bez_Curve *ccp;
  1459. X        Bez_Patch *pcp;
  1460. X    } cp;
  1461. } Bez_Object;
  1462. X
  1463. X
  1464. #endif /* BEZIER_H */
  1465. SHAR_EOF
  1466. chmod 0664 libsipp/bezier.h ||
  1467. echo 'restore of libsipp/bezier.h failed'
  1468. Wc_c="`wc -c < 'libsipp/bezier.h'`"
  1469. test 1640 -eq "$Wc_c" ||
  1470.     echo 'libsipp/bezier.h: original size 1640, current size' "$Wc_c"
  1471. fi
  1472. # ============= libsipp/bezier_lex.l ==============
  1473. if test -f 'libsipp/bezier_lex.l' -a X"$1" != X"-c"; then
  1474.     echo 'x - skipping libsipp/bezier_lex.l (File already exists)'
  1475. else
  1476. echo 'x - extracting libsipp/bezier_lex.l (Text)'
  1477. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bezier_lex.l' &&
  1478. %{
  1479. /**
  1480. X ** sipp - SImple Polygon Processor
  1481. X **
  1482. X **  A general 3d graphic package
  1483. X **
  1484. X **  Copyright Jonas Yngvesson  (jonas-y@isy.liu.se) 1988/89/90/91
  1485. X **            Inge Wallin      (ingwa@isy.liu.se)         1990/91
  1486. X **
  1487. X ** This program is free software; you can redistribute it and/or modify
  1488. X ** it under the terms of the GNU General Public License as published by
  1489. X ** the Free Software Foundation; either version 1, or any later version.
  1490. X ** This program is distributed in the hope that it will be useful,
  1491. X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  1492. X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1493. X ** GNU General Public License for more details.
  1494. X ** You can receive a copy of the GNU General Public License from the
  1495. X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1496. X **/
  1497. X
  1498. /**
  1499. X ** bezier_lex.l - Lex source for reading bezier descriptions.
  1500. X **/
  1501. X
  1502. #include "bezier.h"
  1503. X
  1504. extern int     atoi();
  1505. extern double  atof();
  1506. X
  1507. extern Tokenval  tokenval;
  1508. extern FILE     *bezier_file;
  1509. %}
  1510. %%
  1511. X
  1512. "bezier_patches:"       {return PATCHES;}
  1513. "bezier_curves:"        {return CURVES;}
  1514. "vertices:"             {return NVERTICES;}
  1515. "patches:"              {return NPATCHES;}
  1516. "curves:"               {return NCURVES;}
  1517. "vertex_list:"          {return VERTEX_LIST;}
  1518. "patch_list:"           {return PATCH_LIST;}
  1519. "curve_list:"           {return CURVE_LIST;}
  1520. X
  1521. -?[0-9]+                {tokenval.intval = atoi(yytext);
  1522. X                         return INTEGER;
  1523. X                        }
  1524. -?[0-9]+"."[0-9]*([eE][-+]?[0-9]+)?  {tokenval.floatval = atof(yytext);
  1525. X                                      return FLOAT;
  1526. X                                     }
  1527. X
  1528. [ \n\t]                 {}
  1529. #.*$                    { /* This is a comment */ }
  1530. .                       { return yytext[0]; /* We found something wrong */ }
  1531. X
  1532. %%
  1533. X
  1534. int
  1535. yywrap()
  1536. {
  1537. X    return 1;
  1538. }
  1539. SHAR_EOF
  1540. chmod 0664 libsipp/bezier_lex.l ||
  1541. echo 'restore of libsipp/bezier_lex.l failed'
  1542. Wc_c="`wc -c < 'libsipp/bezier_lex.l'`"
  1543. test 1879 -eq "$Wc_c" ||
  1544.     echo 'libsipp/bezier_lex.l: original size 1879, current size' "$Wc_c"
  1545. fi
  1546. # ============= libsipp/bozo.c ==============
  1547. if test -f 'libsipp/bozo.c' -a X"$1" != X"-c"; then
  1548.     echo 'x - skipping libsipp/bozo.c (File already exists)'
  1549. else
  1550. echo 'x - extracting libsipp/bozo.c (Text)'
  1551. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/bozo.c' &&
  1552. /**
  1553. X ** sipp - SImple Polygon Processor
  1554. X **
  1555. X **  A general 3d graphic package
  1556. X **
  1557. X **  Copyright Jonas Yngvesson  (jonas-y@isy.liu.se) 1988/89/90/91
  1558. X **            Inge Wallin      (ingwa@isy.liu.se)         1990/91
  1559. X **
  1560. X ** This program is free software; you can redistribute it and/or modify
  1561. X ** it under the terms of the GNU General Public License as published by
  1562. X ** the Free Software Foundation; either version 1, or any later version.
  1563. X ** This program is distributed in the hope that it will be useful,
  1564. X ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  1565. X ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1566. X ** GNU General Public License for more details.
  1567. X ** You can receive a copy of the GNU General Public License from the
  1568. X ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1569. X **/
  1570. X
  1571. /**
  1572. X ** bozo.c - Bozo shader: color objects a la Bozo the clown.
  1573. X **/
  1574. X
  1575. #include <math.h>
  1576. #include <stdio.h>
  1577. X
  1578. #include <sipp.h>
  1579. #include <noise.h>
  1580. #include <shaders.h>
  1581. X
  1582. X
  1583. extern bool noise_ready;
  1584. X
  1585. void
  1586. bozo_shader(nx, ny, nz, u, v, w, view_vec, lights, bd, color)
  1587. X    double  nx, ny, nz, u, v, w;
  1588. X    Vector  view_vec;
  1589. X    Lightsource *lights;
  1590. X    Bozo_desc *bd;
  1591. X    Color *color;
  1592. {
  1593. X    Vector     tmp;
  1594. X    Surf_desc  surface;
  1595. X    double     noiseval;
  1596. X    int        i;
  1597. X
  1598. X    if (!noise_ready) {
  1599. X        noise_init();
  1600. X    }
  1601. X
  1602. X    tmp.x = u * bd->scale;
  1603. X    tmp.y = v * bd->scale;
  1604. X    tmp.z = w * bd->scale;
  1605. X    noiseval = noise(&tmp);
  1606. X
  1607. X    i = (noiseval + 1) * bd->no_of_cols / 2.0;
  1608. X    surface.color    = bd->colors[i];
  1609. X    surface.ambient  = bd->ambient;
  1610. X    surface.specular = bd->specular;
  1611. X    surface.c3       = bd->c3;
  1612. X    basic_shader(nx, ny, nz, u, v, w, view_vec, lights, &surface, color);
  1613. }
  1614. SHAR_EOF
  1615. chmod 0664 libsipp/bozo.c ||
  1616. echo 'restore of libsipp/bozo.c failed'
  1617. Wc_c="`wc -c < 'libsipp/bozo.c'`"
  1618. test 1739 -eq "$Wc_c" ||
  1619.     echo 'libsipp/bozo.c: original size 1739, current size' "$Wc_c"
  1620. fi
  1621. true || echo 'restore of libsipp/bumpy.c failed'
  1622. echo End of part 1, continue with part 2
  1623. exit 0
  1624.  
  1625. -- 
  1626. ------------------------------------------------------------------------------
  1627.  J o n a s   Y n g v e s s o n
  1628. Dept. of Electrical Engineering                             jonas-y@isy.liu.se
  1629. University of Linkoping, Sweden                   ...!uunet!isy.liu.se!jonas-y
  1630.  
  1631. exit 0 # Just in case...
  1632.