home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume21 / sipp / part06 < prev    next >
Text File  |  1991-07-23  |  40KB  |  1,243 lines

  1. Newsgroups: comp.sources.misc
  2. From: Jonas Yngvesson <jonas-y@isy.liu.se>
  3. Subject:  v21i031:  sipp - A 3D rendering library v2.1, Part06/08
  4. Message-ID: <1991Jul23.181745.27934@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 182a24e2e62f55a1e2b7ed2a11f9a9d4
  6. Date: Tue, 23 Jul 1991 18:17:45 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 31
  11. Archive-name: sipp/part06
  12. Supersedes: sipp2.0: Volume 16, Issue 5-10
  13. Environment: UNIX
  14.  
  15. #!/bin/sh
  16. # This is part 06 of sipp-2.1
  17. # ============= libsipp/xalloca.c ==============
  18. if test ! -d 'libsipp'; then
  19.     echo 'x - creating directory libsipp'
  20.     mkdir 'libsipp'
  21. fi
  22. if test -f 'libsipp/xalloca.c' -a X"$1" != X"-c"; then
  23.     echo 'x - skipping libsipp/xalloca.c (File already exists)'
  24. else
  25. echo 'x - extracting libsipp/xalloca.c (Text)'
  26. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/xalloca.c' &&
  27. #ifdef HAVE_NO_ALLOCA
  28. X
  29. /*
  30. X    alloca -- (mostly) portable public-domain implementation -- D A Gwyn
  31. X
  32. X    last edit:    86/05/30    rms
  33. X       include config.h, since on VMS it renames some symbols.
  34. X       Use xmalloc instead of malloc.
  35. X
  36. X    This implementation of the PWB library alloca() function,
  37. X    which is used to allocate space off the run-time stack so
  38. X    that it is automatically reclaimed upon procedure exit, 
  39. X    was inspired by discussions with J. Q. Johnson of Cornell.
  40. X
  41. X    It should work under any C implementation that uses an
  42. X    actual procedure stack (as opposed to a linked list of
  43. X    frames).  There are some preprocessor constants that can
  44. X    be defined when compiling for your specific system, for
  45. X    improved efficiency; however, the defaults should be okay.
  46. X
  47. X    The general concept of this implementation is to keep
  48. X    track of all alloca()-allocated blocks, and reclaim any
  49. X    that are found to be deeper in the stack than the current
  50. X    invocation.  This heuristic does not reclaim storage as
  51. X    soon as it becomes invalid, but it will do so eventually.
  52. X
  53. X    As a special case, alloca(0) reclaims storage without
  54. X    allocating any.  It is a good idea to use alloca(0) in
  55. X    your main control loop, etc. to force garbage collection.
  56. */
  57. #ifndef lint
  58. static char    SCCSid[] = "@(#)alloca.c    1.1";    /* for the "what" utility */
  59. #endif
  60. X
  61. #include "xalloca.h"
  62. X
  63. extern void    free();
  64. X
  65. /* ================================================================ */
  66. /*      This is entered from general.h in the GNU shell bash.       */
  67. X
  68. X
  69. #include <stdio.h>
  70. X
  71. /* **************************************************************** */
  72. /*                                    */
  73. /*           Memory Allocation and Deallocation.            */
  74. /*                                    */
  75. /* **************************************************************** */
  76. X
  77. static char *
  78. xmalloc (size)
  79. X     int size;
  80. {
  81. X    char *temp = (char *)malloc (size);
  82. X    
  83. X    if (!temp) {
  84. X        fprintf (stderr, "Out of virtual memory!");
  85. X        exit(1);
  86. X    }
  87. X
  88. X    return (temp);
  89. }
  90. X
  91. X
  92. /* ================================================================ */
  93. X
  94. /*
  95. X    Define STACK_DIRECTION if you know the direction of stack
  96. X    growth for your system; otherwise it will be automatically
  97. X    deduced at run-time.
  98. X
  99. X    STACK_DIRECTION > 0 => grows toward higher addresses
  100. X    STACK_DIRECTION < 0 => grows toward lower addresses
  101. X    STACK_DIRECTION = 0 => direction of growth unknown
  102. */
  103. X
  104. #ifndef STACK_DIRECTION
  105. #define    STACK_DIRECTION    0        /* direction unknown */
  106. #endif
  107. X
  108. #if STACK_DIRECTION != 0
  109. X
  110. #define    STACK_DIR    STACK_DIRECTION    /* known at compile-time */
  111. X
  112. #else    /* STACK_DIRECTION == 0; need run-time code */
  113. X
  114. static int    stack_dir;        /* 1 or -1 once known */
  115. #define    STACK_DIR    stack_dir
  116. X
  117. static void
  118. find_stack_direction (/* void */)
  119. {
  120. X  static char    *addr = NULL;    /* address of first
  121. X                   `dummy', once known */
  122. X  auto char    dummy;        /* to get stack address */
  123. X
  124. X  if (addr == NULL)
  125. X    {                /* initial entry */
  126. X      addr = &dummy;
  127. X
  128. X      find_stack_direction ();    /* recurse once */
  129. X    }
  130. X  else                /* second entry */
  131. X    if (&dummy > addr)
  132. X      stack_dir = 1;        /* stack grew upward */
  133. X    else
  134. X      stack_dir = -1;        /* stack grew downward */
  135. }
  136. X
  137. #endif    /* STACK_DIRECTION == 0 */
  138. X
  139. /*
  140. X    An "alloca header" is used to:
  141. X    (a) chain together all alloca()ed blocks;
  142. X    (b) keep track of stack depth.
  143. X
  144. X    It is very important that sizeof(header) agree with malloc()
  145. X    alignment chunk size.  The following default should work okay.
  146. */
  147. X
  148. #ifndef    ALIGN_SIZE
  149. #define    ALIGN_SIZE    sizeof(double)
  150. #endif
  151. X
  152. typedef union hdr
  153. {
  154. X  char    align[ALIGN_SIZE];    /* to force sizeof(header) */
  155. X  struct
  156. X    {
  157. X      union hdr *next;        /* for chaining headers */
  158. X      char *deep;        /* for stack depth measure */
  159. X    } h;
  160. } header;
  161. X
  162. /*
  163. X    alloca( size ) returns a pointer to at least `size' bytes of
  164. X    storage which will be automatically reclaimed upon exit from
  165. X    the procedure that called alloca().  Originally, this space
  166. X    was supposed to be taken from the current stack frame of the
  167. X    caller, but that method cannot be made to work for some
  168. X    implementations of C, for example under Gould's UTX/32.
  169. */
  170. X
  171. static header *last_alloca_header = NULL; /* -> last alloca header */
  172. X
  173. pointer
  174. alloca (size)            /* returns pointer to storage */
  175. X     unsigned    size;        /* # bytes to allocate */
  176. {
  177. X  auto char    probe;        /* probes stack depth: */
  178. X  register char    *depth = &probe;
  179. X
  180. #if STACK_DIRECTION == 0
  181. X  if (STACK_DIR == 0)        /* unknown growth direction */
  182. X    find_stack_direction ();
  183. #endif
  184. X
  185. X  /* Reclaim garbage, defined as all alloca()ed storage that
  186. X     was allocated from deeper in the stack than currently. */
  187. X  {
  188. X    register header    *hp;    /* traverses linked list */
  189. X
  190. X    for (hp = last_alloca_header; hp != NULL;)
  191. X      if (STACK_DIR > 0 && hp->h.deep > depth
  192. X      || STACK_DIR < 0 && hp->h.deep < depth)
  193. X    {
  194. X      register header    *np = hp->h.next;
  195. X
  196. X      free ((pointer) hp);    /* collect garbage */
  197. X
  198. X      hp = np;        /* -> next header */
  199. X    }
  200. X      else
  201. X    break;            /* rest are not deeper */
  202. X
  203. X    last_alloca_header = hp;    /* -> last valid storage */
  204. X  }
  205. X
  206. X  if (size == 0)
  207. X    return NULL;        /* no allocation required */
  208. X
  209. X  /* Allocate combined header + user data storage. */
  210. X
  211. X  {
  212. X    register pointer    new = xmalloc (sizeof (header) + size);
  213. X    /* address of header */
  214. X
  215. X    ((header *)new)->h.next = last_alloca_header;
  216. X    ((header *)new)->h.deep = depth;
  217. X
  218. X    last_alloca_header = (header *)new;
  219. X
  220. X    /* User storage begins just after header. */
  221. X
  222. X    return (pointer)((char *)new + sizeof(header));
  223. X  }
  224. }
  225. X
  226. #endif  /* HAVE_NO_ALLOCA */
  227. SHAR_EOF
  228. chmod 0664 libsipp/xalloca.c ||
  229. echo 'restore of libsipp/xalloca.c failed'
  230. Wc_c="`wc -c < 'libsipp/xalloca.c'`"
  231. test 5405 -eq "$Wc_c" ||
  232.     echo 'libsipp/xalloca.c: original size 5405, current size' "$Wc_c"
  233. fi
  234. # ============= libsipp/xalloca.h ==============
  235. if test -f 'libsipp/xalloca.h' -a X"$1" != X"-c"; then
  236.     echo 'x - skipping libsipp/xalloca.h (File already exists)'
  237. else
  238. echo 'x - extracting libsipp/xalloca.h (Text)'
  239. sed 's/^X//' << 'SHAR_EOF' > 'libsipp/xalloca.h' &&
  240. #ifdef HAVE_NO_ALLOCA
  241. X
  242. #ifdef X3J11
  243. typedef void    *pointer;        /* generic pointer type */
  244. pointer alloca (unsigned);        /* returns pointer to storage */
  245. #else
  246. typedef char    *pointer;        /* generic pointer type */
  247. pointer alloca ();            /* returns pointer to storage */
  248. #endif /* X3J11 */
  249. X
  250. #else
  251. X
  252. #include <alloca.h>
  253. X
  254. #endif
  255. SHAR_EOF
  256. chmod 0664 libsipp/xalloca.h ||
  257. echo 'restore of libsipp/xalloca.h failed'
  258. Wc_c="`wc -c < 'libsipp/xalloca.h'`"
  259. test 314 -eq "$Wc_c" ||
  260.     echo 'libsipp/xalloca.h: original size 314, current size' "$Wc_c"
  261. fi
  262. # ============= doc/geometric.man ==============
  263. if test ! -d 'doc'; then
  264.     echo 'x - creating directory doc'
  265.     mkdir 'doc'
  266. fi
  267. if test -f 'doc/geometric.man' -a X"$1" != X"-c"; then
  268.     echo 'x - skipping doc/geometric.man (File already exists)'
  269. else
  270. echo 'x - extracting doc/geometric.man (Text)'
  271. sed 's/^X//' << 'SHAR_EOF' > 'doc/geometric.man' &&
  272. .\" Copyright Jonas Yngvesson, Inge Wallin
  273. .\" This program and documentation may be distributed freely under
  274. .\" the terms of GNU GENERAL PUBLIC LICENSE.
  275. .TH GEOMETRIC 3X "July , 1991" 3X
  276. .SH NAME
  277. geometric - Vector and matrix functions for the sipp(3X) library
  278. X
  279. .SH SYNOPSIS
  280. \fI#include <geometric.h>\fR
  281. .sp
  282. [g]cc [\fIflags\fR] \fIfiles\fR -lsipp -lm [ \fIlibraries\fR ]
  283. X
  284. .SH DESCRIPTION
  285. The sipp(3X) 3D rendering library uses a lot of vector calculations
  286. and geometric transformations.  The functions which implement these
  287. features are declared in geometric.h and are described in this manual.
  288. X
  289. .SH VECTOR OPERATIONS
  290. Sipp uses row vectors, not column vectors and a vector is defined as
  291. follows:
  292. X
  293. \fItypedef \ struct\ {\fR
  294. .br
  295. \fI    double\ x;\fR
  296. .br
  297. \fI    double\ y;\fR
  298. .br
  299. \fI    double\ z;\fR
  300. .br
  301. \fI}\ Vector;\fR
  302. X
  303. A vector is used both for directional vectors and points (positional
  304. vectors).  In the description of the sipp vector macros and functions
  305. below, lower case letters denote scalar values and upper case letters
  306. denote vectors.
  307. X
  308. .IP \fIMakeVector(V,\ xx,\ yy,\ zz)
  309. Put \fIxx\fR, \fIyy\fR and \fIzz\fR in the x, y and z slot of the
  310. Vector \fIV\fR respectively.
  311. X
  312. .IP \fIVecNegate(A)\fR
  313. Negate all components of the Vector \fIA\fR.
  314. X
  315. .IP \fIVecDot(A,\ B)\fR
  316. Return the dot product of the two Vectors \fIA\fR and \fIB\fR.
  317. X
  318. .IP \fIVecLen(A)\fR
  319. Return the length of the Vector \fIA\fR.
  320. X
  321. .IP \fIVecCopy(B,\ A)\fR
  322. Copy the Vector \fIA\fR to the Vector \fIB\fR (\fIB\fR = \fIA\fR;
  323. using C notation).
  324. X
  325. .IP \fIVecAdd(C,\ A,\ B)\fR
  326. Add the two Vectors \fIA\fR and \fIB\fR and put the result in \fIC\fR
  327. (Add \fIA\fR to \fIB\fR giving \fIC\fR; using COBOL notation).
  328. X
  329. .IP \fIVecSub(C,\ A,\ B)\fR
  330. Subtract the Vector \fIB\fR from Vector \fIA\fR and put the result in
  331. \fIC\fR (\fIC\fR = \fIA\fR - \fIB\fR; using C notation).
  332. X
  333. .IP \fIVecScalMul(B,\ a,\ A)\fR
  334. Multiply the Vector \fIA\fR with the scalar \fIa\fR and put the result
  335. in Vector \fIB\fR (\fIB\fR = \fIa\fR * \fIA\fR; using C notation).
  336. X
  337. .IP \fIVecAddS(C,\ a,\ A,\ B)\fR
  338. Multiply the Vector \fIA\fR with the scalar \fIa\fR, add it to Vector
  339. \fIB\fR and put the result in Vector \fIC\fR (\fIC\fR = \fIa\fR *
  340. \fIA\fR + \fIB\fR; using C notation). 
  341. X
  342. .IP \fIVecComb(C,\ a,\ A,\ b,\ B)\fR
  343. Linearly combine the two Vectors \fIA\fR and \fIB\fR and put the
  344. result in Vector \fIC\fR (\fIC\fR = \fIa\fR * \fIA\fR + \fIb\fR *
  345. \fIB\fR; using C notation).  
  346. X
  347. .IP \fIVecCross(C,\ A,\ B)\fR
  348. Cross multiply Vector \fIA\fR with Vector \fIB\fR and put the result
  349. in \fIC\fR (\fIC\fR = \fIA\fR X \fIB\fR; using C notation).
  350. X
  351. .IP \fIvoid\ vecnorm(v)\fR
  352. .br
  353. \fIVector\ *v;\fR
  354. .sp
  355. Normalize the vector \fIv\fR, i.e. keep the direction but make it have
  356. length 1.  The length of \fIv\fR should not be equal to 0 to begin with.
  357. .B NOTE:
  358. This is the only function operating on vectors in sipp.
  359. X
  360. .SH MATRIX OPERATIONS
  361. An ordinary homogenous transformation matrix has 4 X 4 elements.
  362. However, all linear transformations only use 4 X 3 values so to save
  363. space a sipp transformation matrix only store 4 X 3 values.  Thus the
  364. transformation matrix used in sipp is defined as follows:
  365. X
  366. \fItypedef\ struct\ {\fR
  367. .br
  368. \fI    double\ mat[4][3];\fR
  369. .br
  370. \fI}\ Transf_mat;\fR
  371. X
  372. We wrap a struct around the two-dimensional array since we want to be
  373. able to say things like \fI&mat\fR without being forced to write
  374. \fI(Transf_mat\ *)\ &mat[0]\fR which we find horribly ugly.
  375. X
  376. There is a predefined identity matrix declared in geometric.h which
  377. you can use if you want to:
  378. X
  379. \fIextern\ Transf_mat\ ident_matrix;\fR
  380. X
  381. The rest of this section describes the macro and functions defined in
  382. the sipp library which work on sipp transformation matrixes.
  383. X
  384. .IP \fIMatCopy(A,\ B)\fR
  385. This macro copies the matrix \fIB\fR to the matrix \fIA\fR. \fIA\fR
  386. and \fIB\fR should both be pointers.
  387. .B NOTE:
  388. This is the only macro operating on matrices in sipp.
  389. X
  390. X
  391. .IP \fITransf_mat\ *transf_mat_create(initmat)\fR
  392. .br
  393. \fITransf_mat\ *initmat;\fR
  394. .sp
  395. Allocate memory for a new transformation matrix and if \fIinitmat\fR
  396. is equal to \fINULL\fR, set the new matrix to the identity matrix.
  397. Otherwise set the new matrix to the contents of \fIinitmat\fR.  Return
  398. a pointer to the new matrix.
  399. X
  400. .IP \fITransf_mat\ *transf_mat_destruct(mat)\fR
  401. .br
  402. \fITransf_mat\ *initmat;\fR
  403. .sp
  404. Free the memory associated with the matrix \fImat\fR.
  405. X
  406. .IP \fIvoid\ mat_translate(mat,\ dx,\ dy,\ dz)\fR
  407. .br
  408. \fITransf_mat\ *mat;\fR
  409. .br
  410. \fIdouble\ dx;\fR
  411. .br
  412. \fIdouble\ dy;\fR
  413. .br
  414. \fIdouble\ dz;\fR
  415. .sp
  416. Set \fImat\fR to the transformation matrix that represents the
  417. concatenation of the previous transformation in \fImat\fR and a
  418. translation along the vector (\fIdx\fR,\ \fIdy\fR,\ \fIdz\fR).
  419. X
  420. .IP \fIvoid\ mat_rotate_x(mat,\ ang)\fR
  421. .br
  422. \fITransf_mat\ *mat;\fR
  423. .br
  424. \fIdouble\ ang;\fR
  425. .sp
  426. Set \fImat\fR to the transformation matrix that represents the
  427. concatenation of the previous transformation in \fImat\fR and a
  428. rotation with the angle \fIang\fR around the X axis. The angle
  429. \fIang\fR is expressed in radians.
  430. X
  431. .IP \fIvoid\ mat_rotate_y(mat,\ ang)\fR
  432. .br
  433. \fITransf_mat\ *mat;\fR
  434. .br
  435. \fIdouble\ ang;\fR
  436. .sp
  437. Set \fImat\fR to the transformation matrix that represents the
  438. concatenation of the previous transformation in \fImat\fR and a
  439. rotation with the angle \fIang\fR around the Y axis.  The angle
  440. \fIang\fR is expressed in radians.
  441. X
  442. .IP \fIvoid\ mat_rotate_z(mat,\ ang)\fR
  443. .br
  444. \fITransf_mat\ *mat;\fR
  445. .br
  446. \fIdouble\ ang;\fR
  447. .sp
  448. Set \fImat\fR to the transformation matrix that represents the
  449. concatenation of the previous transformation in \fImat\fR and a
  450. rotation with the angle \fIang\fR around the Z axis.  The angle
  451. \fIang\fR is expressed in radians.
  452. X
  453. .IP \fIvoid\ mat_rotate(mat,\ point,\ vector,\ ang)\fR
  454. .br
  455. \fITransf_mat\ *mat;\fR
  456. .br
  457. \fIVector\ *point;\fR
  458. .br
  459. \fIVector\ *vector\fR
  460. .br
  461. \fIdouble\ ang;\fR
  462. .sp
  463. Set \fImat\fR to the transformation matrix that represents the
  464. concatenation of the previous transformation in \fImat\fR and a
  465. rotation with the angle \fIang\fR around the line represented by the
  466. point \fIpoint\fR and the vector \fIvector\fR.  The angle
  467. \fIang\fR is expressed in radians.
  468. X
  469. .IP \fIvoid\ mat_scale(mat,\ xscale,\ yscale,\ zscale)\fR
  470. .br
  471. \fITransf_mat\ *mat;\fR
  472. .br
  473. \fIdouble\ xscale;\fR
  474. .br
  475. \fIdouble\ yscale;\fR
  476. .br
  477. \fIdouble\ zscale;\fR
  478. .sp
  479. Set \fImat\fR to the transformation matrix that represents the
  480. concatenation of the previous transformation in \fImat\fR and a
  481. scaling with the scaling factors (\fIxscale\fR,\ \fIyscale\fR,\ \fIzscale\fR).
  482. X
  483. .IP \fIvoid\ mat_mirror_plane(mat,\ point,\ normal)\fR
  484. .br
  485. \fITransf_mat\ *mat;\fR
  486. .br
  487. \fIVector\ *point;\fR
  488. .br
  489. \fIVector\ *normal\fR
  490. .sp
  491. Set \fImat\fR to the transformation matrix that represents the
  492. concatenation of the previous transformation in \fImat\fR and a
  493. mirroring in the plane defined by the point \fIpoint\fR and the normal
  494. vector \fInormal\fR. 
  495. X
  496. .IP \fIvoid\ mat_mul(res,\ a,\ b)\fR
  497. .br
  498. \fITransf_mat\ *res\fR
  499. .br
  500. \fITransf_mat\ *a\fR
  501. .br
  502. \fITransf_mat\ *b\fR
  503. .sp
  504. Multiply the two matrixes \fIa\fR and \fIb\fR and put the result in
  505. the matrix \fIres\fR.  All three parameters are pointers to matrixes.
  506. It is possible for \fIres\fR to point at the same matrix as either
  507. \fIa\fR or \fIb\fR since the result is stored in a temporary matrix
  508. during the computations.
  509. X
  510. .IP \fIvoid\ point_transform(res,\ vec,\ mat)\fR
  511. .br
  512. \fIVector\ *res\fR
  513. .br
  514. \fIVector\ *vec;\fR
  515. .br
  516. \fITransf_mat\ *mat;\fR
  517. .sp
  518. Transform the point (vector) \fIvec\fR with the transformation matrix
  519. \fImat\fR and put the result into the vector \fIres\fR.  The two
  520. vectors \fIres\fR and \fIvec\fR should not be the same vector since no
  521. temporary is used during the computations.
  522. X
  523. .SH SEE ALSO
  524. sipp(3X) - simple polygon processor, a 3d-graphics library
  525. .br
  526. shaders(3X) - a collection of shaders for \fIsipp\fR.
  527. .br
  528. primitives(3X) - a collection of object primitives for \fIsipp\fR.
  529. .br
  530. sipp_pixmap(3X) - pixmap handling code for \fIsipp\fR.
  531. .br
  532. sipp_bitmap(3X) - bitmap handling code for \fIsipp\fR.
  533. X
  534. .SH AUTHORS
  535. Jonas Yngvesson\    \    (jonas-y@isy.liu.se)
  536. .br
  537. Inge Wallin\        (ingwa@isy.liu.se)
  538. X
  539. .SH BUGS
  540. No known bugs.
  541. SHAR_EOF
  542. chmod 0644 doc/geometric.man ||
  543. echo 'restore of doc/geometric.man failed'
  544. Wc_c="`wc -c < 'doc/geometric.man'`"
  545. test 8030 -eq "$Wc_c" ||
  546.     echo 'doc/geometric.man: original size 8030, current size' "$Wc_c"
  547. fi
  548. # ============= doc/primitives.man ==============
  549. if test -f 'doc/primitives.man' -a X"$1" != X"-c"; then
  550.     echo 'x - skipping doc/primitives.man (File already exists)'
  551. else
  552. echo 'x - extracting doc/primitives.man (Text)'
  553. sed 's/^X//' << 'SHAR_EOF' > 'doc/primitives.man' &&
  554. .\" Copyright 1990, Jonas Yngvesson, Inge Wallin
  555. .\" This program and documentation may be distributed freely under
  556. .\" the terms of GNU GENERAL PUBLIC LICENSE.
  557. .TH PRIMITIVES 3X "December , 1990" 3X
  558. .SH NAME
  559. primitives - a collection of object primitives for \fIsipp\fR.
  560. .SH SYNOPSIS
  561. \fI#include <primitives.h>\fR
  562. .sp
  563. [g]cc [\fIflags\fR] \fIfiles\fR -lsipp -lm [ \fIlibraries\fR ]
  564. X
  565. .SH DESCRIPTION
  566. \fIsipp\fR gives the user access to a number of rather low level functions
  567. to create polygons, surfaces and objects. This manual describes a set of
  568. functions that use the low level functions in \fIsipp\fR to create
  569. geometric primitives. Each primitive is a complete \fIsipp\fR object.
  570. .sp
  571. All primitives described here will get texture coordinates equal to the
  572. respective world coordinates.
  573. X
  574. .SH PRIMITIVES
  575. .IP \fIObject\ *sipp_torus(bigradius,\ smallradius,\ res1,\ res2,\ surface,\ shader)\fR
  576. .br
  577. \fIdouble\  bigradius;\fR
  578. .br
  579. \fIdouble\  smallradius;\fR
  580. .br
  581. \fIint\     res1;\fR
  582. .br
  583. \fIint\     res2;\fR
  584. .br
  585. \fIvoid\   *surface;\fR
  586. .br
  587. \fIShader\ *shader;\fR
  588. .sp
  589. \fIsipp_torus()\fR creates a torus centered about the origin and with the
  590. z-axis pointing up through the ring. \fIbigradius\fR is the radius of the
  591. ring and \fIsmallradius\fR is the radius of the "tube" itself. \fIres1\fR
  592. is the number of polygons that will be created radially around the ring
  593. and \fIres2\fR is the number of polygons that will be created around the
  594. tube. \fIsurface\fR is the surface description used by \fIshader()\fR
  595. which is the shading function used when shading the torus.
  596. X
  597. .IP \fIObject\ *sipp_cone(bot_rad,\ ,top_rad,\ length,\ resolution,\ surface,\ shader)\fR
  598. .br
  599. \fIdouble\  bot_rad;\fR
  600. .br
  601. \fIdouble\  top_rad;\fR
  602. .br
  603. \fIdouble\  length;\fR
  604. .br
  605. \fIint\     resolution;\fR
  606. .br
  607. \fIvoid\   *surface;\fR
  608. .br
  609. \fIShader\ *shader;\fR
  610. .sp
  611. \fIsipp_cone()\fR creates a cone centered about the origin and with the z-axis
  612. along the cones main axis. \fIbot_rad\fR and \fItop_rad\fR determines the
  613. radius of the cone in its bottom and top, if both of these are non zero a
  614. truncated cone is created. \fIlength\fR defines the length of the cone.
  615. \fIresolution\fR is the number of polygons that will be created radially
  616. around the rim.  \fIsurface\fR is the surface description used by
  617. \fIshader()\fR which is the shading function used when shading the cone.
  618. X
  619. .IP \fIObject\ *sipp_cylinder(radius,\ length,\ resolution,\ surface,\ shader)\fR
  620. .br
  621. \fIdouble\  radius;\fR
  622. .br
  623. \fIdouble\  length;\fR
  624. .br
  625. \fIint\     resolution;\fR
  626. .br
  627. \fIvoid\   *surface;\fR
  628. .br
  629. \fIShader\ *shader;\fR
  630. .sp
  631. \fIsipp_cylinder()\fR creates a cylinder centered about the origin and with the
  632. z-axis along the cylinders main axis. \fIradius\fR and \fIlength\fR
  633. defines the size of the cylinder. \fIresolution\fR
  634. is the number of polygons that will be created radially around the rim.
  635. \fIsurface\fR is the surface description used by \fIshader()\fR
  636. which is the shading function used when shading the cylinder.
  637. X
  638. .IP \fIObject\ *sipp_ellipsoid(x_rad,\ y_rad,\ z_rad,\ resolution,\ surface,\ shader)\fR
  639. .br
  640. \fIdouble\  x_rad;\fR
  641. .br
  642. \fIdouble\  y_rad;\fR
  643. .br
  644. \fIdouble\  z_rad;\fR
  645. .br
  646. \fIint\     resolution;\fR
  647. .br
  648. \fIvoid\   *surface;\fR
  649. .br
  650. \fIShader\ *shader;\fR
  651. .sp
  652. \fIsipp_ellipsoid()\fR creates a ellipsoid centered about the origin.
  653. \fIx_rad\fR, \fIy_rad\fR and \fIz_rad\fR
  654. defines the size of the ellipsoid. \fIresolution\fR
  655. is the number of polygons that will be created around it's "equator".
  656. \fIsurface\fR is the surface description used by \fIshader()\fR
  657. which is the shading function used when shading the ellipsoid.
  658. X
  659. .IP \fIObject\ *sipp_sphere(radius,\ resolution,\ surface,\ shader)\fR
  660. .br
  661. \fIdouble\  radius;\fR
  662. .br
  663. \fIint\     resolution;\fR
  664. .br
  665. \fIvoid\   *surface;\fR
  666. .br
  667. \fIShader\ *shader;\fR
  668. .sp
  669. \fIsipp_sphere()\fR creates a sphere centered about the origin.
  670. \fIradius\fR defines the size of the sphere. \fIresolution\fR
  671. is the number of polygons that will be created around it's "equator".
  672. \fIsurface\fR is the surface description used by \fIshader()\fR
  673. which is the shading function used when shading the sphere.
  674. X
  675. .IP \fIObject\ *sipp_prism(num_points,\ points,\ length,\ surface,\ shader)\fR
  676. .br
  677. \fIint\     num_points;\fR
  678. .br
  679. \fIVector\ *points;\fR
  680. .br
  681. \fIdouble\  length;\fR
  682. .br
  683. \fIvoid\   *surface;\fR
  684. .br
  685. \fIShader\ *shader;\fR
  686. .sp
  687. \fIsipp_prism()\fR creates a prism defined by the polygon in
  688. \fIpoints\fR. Only the x and y values are used and the prism will
  689. ascend and descend equally far (\fIlength\fR / 2.0) from the x-y plane
  690. along the z axis.  The number of points in the polygon is determined
  691. by \fInum_points\fR.  \fIsurface\fR is the surface description used by
  692. \fIshader()\fR which is the shading function used when shading the
  693. prism.
  694. X
  695. .IP \fIObject\ *sipp_block(x_size,\ y_size,\ z_size,\ surface,\ shader)\fR
  696. .br
  697. \fIdouble\  x_size;\fR
  698. .br
  699. \fIdouble\  y_size;\fR
  700. .br
  701. \fIdouble\  z_size;\fR
  702. .br
  703. \fIvoid\   *surface;\fR
  704. .br
  705. \fIShader\ *shader;\fR
  706. .sp
  707. \fIsipp_block()\fR creates a square block with the size defined by
  708. \fIx_size\fR, \fIz_size\fR and \fIz_size\fR. The block is centered
  709. about the origin. \fIsurface\fR is the surface description used by
  710. \fIshader()\fR which is the shading function used when shading the
  711. block.
  712. X
  713. .IP \fIObject\ *sipp_cube(side,\ surface,\ shader)\fR
  714. .br
  715. \fIdouble\  side;\fR
  716. .br
  717. \fIvoid\   *surface;\fR
  718. .br
  719. \fIShader\ *shader;\fR
  720. .sp
  721. \fIsipp_cube()\fR creates a cube with the side of length \fIside\fR.  The
  722. cube is centered about the origin. \fIsurface\fR is the surface description
  723. used by \fIshader()\fR which is the shading function used when shading the
  724. cube.
  725. X
  726. .IP \fIObject\ *sipp_bezier(file,\ res,\ surface,\ shader)\fR
  727. .br
  728. \fIFILE\   *file;\fR
  729. .br
  730. \fIint\     res;\fR
  731. .br
  732. \fIvoid\   *surface;\fR
  733. .br
  734. \fIShader\ *shader;\fR
  735. .sp
  736. \fIsipp_bezier()\fR reads a file containing descriptions of a set of bezier
  737. patches or bezier curves. If the file contains descriptions of patches, these
  738. patches will be tesselated into \fIres\fR by \fIres\fR polygons and installed
  739. in a \fIsipp\fR object as one surface. The surface will be shaded by
  740. \fIshader\fR using the surface description \fIsurface\fR.
  741. .sp
  742. If the file contains descriptions of curves, a rotational surface will be
  743. created by rotating these curves about the y-axis. The resulting surface will
  744. be tesselated into polygons and installed in a \fIsipp\fR object as one
  745. surface. The surface will be shaded by \fIshader\fR using the surface
  746. description \fIsurface\fR.
  747. .sp
  748. The format of the description file is rather simple. First a keyword defining
  749. the type of description in the file, \fIbezier_curves:\fR or
  750. \fIbezier_patches:\fR. Then follows a description of the vertices (control
  751. points). First the word \fIvertices:\fR followed by an integer number that
  752. tells how many vertices there are in the description, then the word
  753. \fIvertex_list:\fR followed by the x, y and z coordinates for each vertex. The
  754. number of vertices must be same as the number given above. This is, however,
  755. not checked for. 
  756. .sp
  757. If the file contains curves, the keyword \fIcurves:\fR followed by the number
  758. of bezier curves in the file stand on the next line. After this line, a line
  759. with the single keyword \fIcurve_list:\fR follows. Lastly, the bezier curves
  760. themselves follow as numbers in groups of four by four. Each number is an
  761. index into the vertex list with the first index having number 1.
  762. .sp
  763. If the file contains patches, the format is the same with the following
  764. exceptions: The word \fIpatches:\fR is substituted for \fIcurves:\fR, the word
  765. \fIpatch_list:\fR is substituted for \fIcurve_list:\fR and the indices into
  766. the vertex list are grouped 16 by 16 instead of 4 by 4.
  767. .sp
  768. Comments can be inserted anywhere in a bezier curve/patch description file by
  769. using the hashmark character, #. The comment lasts to the end of the line.
  770. .sp
  771. See any standard computer graphics reference, e.g. Newman & Sproull, for a
  772. more detailed description of Bezier curves and patches.
  773. .sp
  774. Example: the body of a standard Newell teapot.
  775. .sp
  776. .nf
  777. # Bezier curves (rotational body) for teapot body.
  778. X
  779. bezier_curves:
  780. X
  781. vertices: 10
  782. vertex_list:
  783. X    3.500000E-01    5.625000E-01    0.000000E+00
  784. X    3.343750E-01    5.953125E-01    0.000000E+00
  785. X    3.593750E-01    5.953125E-01    0.000000E+00
  786. X    3.750000E-01    5.625000E-01    0.000000E+00
  787. X    4.375000E-01    4.312500E-01    0.000000E+00
  788. X    5.000000E-01    3.000000E-01    0.000000E+00
  789. X    5.000000E-01    1.875000E-01    0.000000E+00
  790. X    5.000000E-01    7.500000E-02    0.000000E+00
  791. X    3.750000E-01    1.875000E-02    0.000000E+00
  792. X    3.750000E-01    0.000000E+00    0.000000E+00
  793. X
  794. curves:    3
  795. curve_list:
  796. X
  797. X  1 2 3 4
  798. X
  799. X  4 5 6 7
  800. X
  801. X  7 8 9 10
  802. X
  803. #End of teapot bezier file
  804. .fi
  805. X
  806. .SH SEE ALSO
  807. sipp(3X) - simple polygon processor, a 3d-graphics library
  808. .br
  809. shaders(3X) - a collection of shaders for \fIsipp\fR.
  810. .br
  811. geometric(3X) - Vector and matrix functions for the sipp(3X) library
  812. .br
  813. sipp_pixmap(3X) - pixmap handling code for \fIsipp\fR.
  814. .br
  815. sipp_bitmap(3X) - bitmap handling code for \fIsipp\fR.
  816. X
  817. .SH AUTHORS
  818. Jonas Yngvesson\    \    (jonas-y@isy.liu.se)
  819. .br
  820. Inge Wallin\        (ingwa@isy.liu.se)
  821. X
  822. .SH BUGS
  823. The format for the bezier patches and curves is prohibitively ugly.
  824. SHAR_EOF
  825. chmod 0664 doc/primitives.man ||
  826. echo 'restore of doc/primitives.man failed'
  827. Wc_c="`wc -c < 'doc/primitives.man'`"
  828. test 9153 -eq "$Wc_c" ||
  829.     echo 'doc/primitives.man: original size 9153, current size' "$Wc_c"
  830. fi
  831. # ============= doc/shaders.man ==============
  832. if test -f 'doc/shaders.man' -a X"$1" != X"-c"; then
  833.     echo 'x - skipping doc/shaders.man (File already exists)'
  834. else
  835. echo 'x - extracting doc/shaders.man (Text)'
  836. sed 's/^X//' << 'SHAR_EOF' > 'doc/shaders.man' &&
  837. .\" Copyright 1990, Jonas Yngvesson, Inge Wallin
  838. .\" This program and documentation may be distributed freely under
  839. .\" the terms of GNU GENERAL PUBLIC LICENSE.
  840. .TH SHADERS 3X "December , 1990" 3X
  841. .SH NAME
  842. shaders - a collection of shaders for \fIsipp\fR.
  843. .SH SYNOPSIS
  844. \fI#include <sipp.h>\fR
  845. .br
  846. \fI#include <shaders.h>\fR
  847. .sp
  848. [g]cc [\fIflags\fR] \fIfiles\fR -lsipp -lm [ \fIlibraries\fR ]
  849. X
  850. .SH DESCRIPTION
  851. \fIsipp\fR provides, internally, a simple shading model and a shading
  852. function called \fIbasic_shader()\fR. If this shader is not sufficient for a
  853. particular surface, the user can
  854. implement his/her own shading function and have \fIsipp\fR call that one
  855. instead. Different shaders usually 
  856. need different parameters to describe the surface. \fIsipp\fR supports this by
  857. allowing every shader to have it's own unique kind of structure stored with
  858. the surface that is to be shaded with that shader.
  859. The structure used for \fIbasic_shader()\fR
  860. is called \fISurf_desc\fR. See \fIsipp\fR(3X) for more details about
  861. shaders and their parameters.
  862. .sp
  863. This manual describes the parameters for a \fIsipp\fR shading function and a
  864. set of shaders beside \fIbasic_shader()\fR that are included in the library.
  865. All shaders described here, except \fIstrauss_shader()\fR, provide some kind of
  866. special effect on a surface and call \fIbasic_shader()\fR to do the actual
  867. shading calculations.
  868. X
  869. .SH SIPP SHADING FUNCTIONS
  870. Each surface in a scene has a shading function associated with it.
  871. This function is called by \fIsipp\fR as the surface is
  872. rendered. \fIsipp\fR has an internal basic shading function called
  873. \fIbasic_shader\fR that can be used in most cases. \fIbasic_shader\fR
  874. provides a somewhat modified and simplified version of Blinn's shading
  875. model, taking a \fISurf_desc\fR as a description of the surface. 
  876. .sp
  877. If the user is not satisfied with the builtin shader, he can provide
  878. his own shader and surface description struct. All shaders take
  879. the same parameters and must be defined as follows:
  880. .sp
  881. \fIvoid\ myshader(nx,\ ny,\ nz,\ \ u,\ v,\ w,\ view_vec,\fR
  882. .br
  883. \fI        lights,\ surface,\ color)\fR
  884. .br
  885. \fI    double nx, ny, nz;\fR
  886. .br
  887. \fI    double u, v, w;\fR
  888. .br
  889. \fI    Vector\ view_vec;\fR
  890. .br
  891. \fI    Lightsource *lights;\fR
  892. .br
  893. \fI    my_surf_desc *surface;\fR
  894. .br
  895. \fI    Color\ *color;\fR
  896. .sp
  897. \fInx, ny\fR and \fInz\fR is the \fInon-normalized\fR surface normal at the
  898. point that should be rendered.
  899. .br
  900. \fIu, v\fR and \fIw\fR are the interpolated texture coordinates at the rendered
  901. point. If no texture coordinates have been given at some vertices these
  902. values are undefined and contains garbage at best.
  903. .br
  904. \fIview_vec\fR is a normalized vector, pointing from the rendered
  905. point at the viewpoint.
  906. .br
  907. \fIlights\fR is a pointer to a linked list of lightsource descriptions. See
  908. the function \fIlightsource_push()\fR for a description of the structure of
  909. the links.
  910. .br
  911. \fIsurface\fR is the same \fIsurface\fR-pointer that was sent to the
  912. function \fIsurface_create()\fR. In the case of \fIbasic_shader\fR this is
  913. a pointer to a \fISurf_desc\fR. If the user provides his own shader, he
  914. can also provide his own surface description.
  915. .br
  916. Upon return, the shader should place the calculated rgb colour
  917. components in the areas pointed to by \fIcolor\fR. The rgb components
  918. must be values between 0 and 1.
  919. X
  920. .SH SHADERS AND SURFACE DESCRIPTORS
  921. The following shader functions are provided with the \fIsipp\fR library. 
  922. X
  923. .IP \fIstrauss_shader()\fR
  924. \fIstrauss_shader()\fR is an implementation of a shader described by Paul
  925. Strauss in IEEE CG&A Nov. 1990. In his article he explains that most shading
  926. models in use today, ie Phong, Cook-Torrance, are difficult to use for
  927. non-experts, and this for several reasons. The parameters and their effect on
  928. a surface are non-intuitive and/or complicated. The shading model Strauss
  929. designed has parameters that is easy to grasp and have a reasonably
  930. deterministic effect on a surface, but yet produces very realistic results.
  931. .sp
  932. The surface description used in \fIstrauss_shader()\fR is called
  933. \fIStrauss_desc\fR and looks like this:
  934. .br
  935. \fItypedef struct {\fR
  936. .br
  937. \fI\    double  ambient;\fR
  938. .br
  939. \fI\    double  smoothness;\fR
  940. .br
  941. \fI\    double  metalness;\fR
  942. .br
  943. \fI\    Color   color;\fR
  944. .br
  945. \fI} Strauss_desc;\fR
  946. .sp
  947. \fIambient\fR is a value between 0 and 1 which determines how much of the base
  948. color of a surface that is visible when it is not illuminated by any
  949. lightsource.
  950. .br
  951. \fIsmoothness\fR is a value between 0 and 1 that describes how smooth the
  952. surface is. This parameter controls both diffuse and specular reflections. 0
  953. means a dull surface while 1 means a very smooth and shiny one.
  954. .br
  955. \fImetalness\fR is alo a value between 0 and 1. It describes how metallic the
  956. material is. It controls among other things how much of the surface color
  957. should be mixed into the specular reflections at different angles. 0 means a
  958. non-metal while 1 means a very metallic surface.
  959. .br
  960. \fIcolor\fR is (of course) the base color of the surface.
  961. X
  962. .IP \fIwood_shader()\fR
  963. \fIwood_shader()\fR creates a simulated wood texture on a surface.
  964. It uses two colors, one as the base (often lighter) color of the wood
  965. and one as the color of the (often darker) rings in it.
  966. The rings is put into the base color about the x-axis and are then distorted 
  967. using \fInoise()\fR and \fIturbulence()\fR. A similar pattern is repeated at
  968. regular intervals to create an illusion of logs or boards.
  969. .sp
  970. The surface description for a wood surface is called
  971. \fIWood_desc\fR and is defined as follows:
  972. .br
  973. \fItypedef struct {\fR
  974. .br
  975. \fI\    double   ambient;\fR
  976. .br
  977. \fI\    double   specular;\fR
  978. .br
  979. \fI\    double   c3;\fR
  980. .br
  981. \fI\    double   scale;\fR
  982. .br
  983. \fI\    Color    base;\fR
  984. .br
  985. \fI\    Color    ring;\fR
  986. .br
  987. \fI} Wood_desc;\fR
  988. .sp
  989. Except for the two colors and the field \fIscale\fR, \fIWood_desc\fR
  990. looks exactly like a \fISurf_desc\fR and the fields are used in the
  991. same way. 
  992. .br
  993. \fIscale\fR is a factor which determines the size of the
  994. wood pattern depending on the size of the texture coordinate system
  995. in relation to the world coordinate system. You will have to
  996. experiment some to get this right.
  997. .br
  998. \fIbase\fR is the color of the base material, and \fIring\fR is the
  999. color of the darker rings.
  1000. X
  1001. .IP \fImarble_shader()\fR
  1002. \fImarble_shader()\fR creates a simulated marble texture on a surface.
  1003. It uses two colors, one as the base material and one as the
  1004. interspersed material. The interspersed material is put into the
  1005. base material in strips that are distorted using \fInoise()\fR and
  1006. \fIturbulence()\fR. 
  1007. .sp
  1008. The surface description for a marble surface is called
  1009. \fIMarble_desc\fR and is defined as follows:
  1010. .br
  1011. \fItypedef struct {\fR
  1012. .br
  1013. \fI\    double   ambient;\fR
  1014. .br
  1015. \fI\    double   specular;\fR
  1016. .br
  1017. \fI\    double   c3;\fR
  1018. .br
  1019. \fI\    double   scale;\fR
  1020. .br
  1021. \fI\    Color    base;\fR
  1022. .br
  1023. \fI\    Color    strip;\fR
  1024. .br
  1025. \fI} Marble_desc;\fR
  1026. .sp
  1027. Except for the two colors and the field \fIscale\fR, \fIMarble_desc\fR
  1028. looks exactly like a \fISurf_desc\fR and the fields are used in the
  1029. same way. 
  1030. .br
  1031. \fIscale\fR is a factor which determines the size of the
  1032. marble pattern depending on the size of the texture coordinate system
  1033. in relation to the world coordinate system. 
  1034. .br
  1035. \fIbase\fR is the color of the base material, and \fIstrip\fR is the
  1036. color of the interspersed material.
  1037. X
  1038. .IP \fIgranite_shader()\fR
  1039. \fIgranite_shader()\fR is very similar to \fImarble_shader()\fR in
  1040. that it also
  1041. mixes two colors using \fInoise()\fR and \fIturbulence()\fR. The
  1042. difference is in 
  1043. how the mixing is done. The two colors are mixed whithout treating
  1044. them separately in any way. 
  1045. .sp
  1046. The surface description used in \fIgranite_shader()\fR is called
  1047. \fIGranite_desc\fR and is defined as follows:
  1048. .br
  1049. \fItypedef struct {\fR
  1050. .br
  1051. \fI\    double   ambient;\fR
  1052. .br
  1053. \fI\    double   specular;\fR
  1054. .br
  1055. \fI\    double   c3;\fR
  1056. .br
  1057. \fI\    double   scale;\fR
  1058. .br
  1059. \fI\    Color    col1;\fR
  1060. .br
  1061. \fI\    Color    col2;\fR
  1062. .br
  1063. \fI} Granite_desc;\fR
  1064. .sp
  1065. The fields have the same meaning as in \fIMarble_desc\fR.
  1066. X
  1067. .IP \fIbozo_shader()\fR
  1068. \fIbozo_shader()\fR uses \fInoise()\fR to chose a color from a fixed set.
  1069. The range of possible return value from \fInoise()\fR are divided into parts
  1070. of equal size and each part is assigned a color. The size of the parts
  1071. are dependent on the number of colors.
  1072. .sp
  1073. The surface description is called \fIBozo_desc\fR and is defined as
  1074. follows:
  1075. .br
  1076. \fItypedef struct {\fR
  1077. .br
  1078. \fI\    Color   *colors;\fR
  1079. .br
  1080. \fI\    int      no_of_cols;\fR
  1081. .br
  1082. \fI\    double   ambient;\fR
  1083. .br
  1084. \fI\    double   specular;\fR
  1085. .br
  1086. \fI\    double   c3;\fR
  1087. .br
  1088. \fI\    double   scale;
  1089. .br
  1090. \fI} Bozo_desc;\fR
  1091. .sp
  1092. \fIcolors\fR is a pointer to an array of \fIColor\fR structs and
  1093. \fIno_of_cols\fR defines the number of entries in this array. The other
  1094. fields have the same function as in the prevoiusly described shaders.
  1095. X
  1096. .IP \fImask_shader()\fR
  1097. \fImask_shader()\fR uses another image (ususally a bitmap) as a mask,
  1098. and calls two different shaders depending on the values in this image.
  1099. The mask image can be of any format. The user supplies a pointer
  1100. to the image and a function that tests the value of a certain pixel in it.
  1101. The mapping uses only the \fIu\fR and \fIv\fR texture coordinates.
  1102. .sp
  1103. The surface description is called \fIMask_desc\fR and has the
  1104. following definition:
  1105. .br
  1106. \fItypedef struct {\fR
  1107. .br
  1108. \fI\    Shader *fg_shader;\fR
  1109. .br
  1110. \fI\    void   *fg_surface;\fR
  1111. .br
  1112. \fI\    Shader *bg_shader;\fR
  1113. .br
  1114. \fI\    void   *bg_surface;\fR
  1115. .br
  1116. \fI\    void   *mask;\fR
  1117. .br
  1118. \fI\    bool  (*pixel_test)();\fR
  1119. .br
  1120. \fI\    int x0, y0;\fR
  1121. .br
  1122. \fI\    int xsize, ysize;\fR
  1123. .br
  1124. \fI\    double xscale, yscale;\fR
  1125. .br
  1126. \fI} Mask_desc;\fR
  1127. .sp
  1128. \fIfg_shader\fR is used together with the surface description
  1129. \fIfg_surface\fR when \fIpixel_test\fR (see below) returns TRUE.
  1130. .br
  1131. \fIbg_shader\fR is used together with the surface description
  1132. \fIbg_surface\fR when \fIpixel_test\fR (see below) returns FALSE.
  1133. .br
  1134. \fImask\fR is a pointer to the image. This could be a pointer to a raw array
  1135. of pixels or a complicated struct, the image representation is completely up
  1136. to the user.
  1137. .br
  1138. \fIpixel_test\fR is a function that is called to evaluate pixels in the mask
  1139. image. This function should be declared as follows:
  1140. .br
  1141. \fI\ bool my_pixel_test(image, x, y)\fR
  1142. .br
  1143. \fI\     my_image_struct *image;\fR
  1144. .br
  1145. \fI\     int              x, y;\fR
  1146. .br
  1147. \ \ \fIimage\fR is the same pointer that is stored in the \fIMask_desc\fR.
  1148. .br
  1149. \ \ \fIx\fR and \fIy\fR are the coordinates of the pixel that should be
  1150. tested.
  1151. .br
  1152. \fIx0\fR and \fIy0\fR define where (in mask image coordinates) the
  1153. origo of the texture coordinate system should be placed.
  1154. .br
  1155. \fIxsize\fR and \fIysize\fR is the size of the mask image.
  1156. .br
  1157. \fIxscale\fR and \fIyscale\fR scales the texture coordinate system
  1158. relative the mask image coordinates.
  1159. X
  1160. .IP \fIbumpy_shader()\fR
  1161. \fIbumpy_shader()\fR is a function that perturbates the normal of a
  1162. surface using \fIDnoise()\fR. Any other shader can be used to do the final
  1163. shading calculations. 
  1164. .sp
  1165. The surface description is called \fIBumpy_desc\fR and is defined as
  1166. follows:
  1167. .br
  1168. \fItypedef struct {\fR
  1169. .br
  1170. \fI\    Shader *shader;\fR
  1171. .br
  1172. \fI\    void   *surface;\fR
  1173. .br
  1174. \fI\    double scale;\fR
  1175. .br
  1176. \fI\    bool   bumpflag;\fR
  1177. .br
  1178. \fI\    bool   holeflag;\fR
  1179. .br
  1180. \fI} Bumpy_desc;\fR
  1181. .sp
  1182. \fIshader\fR and \fIsurface\fR define the shader to be used for the
  1183. final shading calculations. 
  1184. .br
  1185. \fIscale\fR has the same meaning as in previous shaders using \fInoise()\fR.
  1186. .br
  1187. \fIbumpflag\fR and \fIholeflag\fR make it possible to flatten out
  1188. half of the bumps. If only \fIbumpflag\fR is TRUE only bumps "standing
  1189. out" from the surface are visible. The rest of the surface will be smooth.
  1190. If, on the other hand, only \fIholeflag\fR is TRUE only bumps going
  1191. "into" the surface will be visible, thus giving the surface an
  1192. eroded look. If both flags are true, the whole surface will get a
  1193. bumpy appearence, rather like an orange.
  1194. X
  1195. .IP \fIplanet_shader()\fR
  1196. \fIplanet_shader()\fR is a somewhat specialized shader that produces a texture
  1197. that resembles a planet surface. The planet is of the Tellus type with a
  1198. mixture of oceans and continents. Some of the surface is covered by
  1199. semi-transparent clouds which enhances the effect greatly. On the other hand,
  1200. no polar caps are provided and this decreases the realism.
  1201. .sp
  1202. The texture is 3-dimensional, so it is possible to create cube planets or even
  1203. planets with cut-out parts that still have surfaces that resemble the earth
  1204. surface. The texture is not scalable, and is designed to be used with texture
  1205. coordinats in the range -1.0 to 1.0, e.g. a unit sphere. Of course the world
  1206. coordinats need not have the same order of magnitude.
  1207. .sp
  1208. \fIplanet_shader()\fR uses an ordinary \fISurf_desc\fR in which the
  1209. \fIcolor\fR field is ignored.
  1210. X
  1211. .SH SEE ALSO
  1212. sipp(3X) - simple polygon processor, a 3d-graphics library
  1213. .br
  1214. geometric - Vector and matrix functions for the sipp(3X) library
  1215. .br
  1216. primitives(3X) - a collection of geometric primitives for \fIsipp\fR.
  1217. .br
  1218. sipp_pixmapq(3X) - pixmap handling code for \fIsipp\fR.
  1219. .br
  1220. sipp_bitmap(3X) - bitmap handling code for \fIsipp\fR.
  1221. X
  1222. .SH AUTHORS
  1223. Jonas Yngvesson\    \    (jonas-y@isy.liu.se)
  1224. .br
  1225. Inge Wallin\        (ingwa@isy.liu.se)
  1226. X
  1227. .SH BUGS
  1228. The planet texture should be enhanced with polar caps and it should be
  1229. possible to give parameters to control, among other factors, the ratio of
  1230. ocean/land and the cloudiness.
  1231. SHAR_EOF
  1232. chmod 0664 doc/shaders.man ||
  1233. echo 'restore of doc/shaders.man failed'
  1234. Wc_c="`wc -c < 'doc/shaders.man'`"
  1235. test 13374 -eq "$Wc_c" ||
  1236.     echo 'doc/shaders.man: original size 13374, current size' "$Wc_c"
  1237. fi
  1238. true || echo 'restore of doc/sipp.man failed'
  1239. echo End of part 6, continue with part 7
  1240. exit 0
  1241.  
  1242. exit 0 # Just in case...
  1243.