home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libtext / checker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.5 KB  |  66 lines

  1. /*
  2.  * checker.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * checker.c,v 4.1 1994/08/09 08:02:20 explorer Exp
  17.  *
  18.  * checker.c,v
  19.  * Revision 4.1  1994/08/09  08:02:20  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:14  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:41:48  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "texture.h"
  30. #include "checker.h"
  31.  
  32. /*
  33.  * Create and return a reference to a "checker" texture.
  34.  */
  35. Checker *
  36. CheckerCreate(surf)
  37. Surface *surf;
  38. {
  39.     Checker *checker;
  40.     checker = (Checker *)Malloc(sizeof(Checker));
  41.     checker->surf = surf;
  42.     return checker;
  43. }
  44.  
  45. /*
  46.  * Apply a "checker" texture.
  47.  */
  48. void
  49. CheckerApply(checker, prim, ray, pos, norm, gnorm, surf)
  50. Checker *checker;
  51. Geom *prim;
  52. Ray *ray;
  53. Vector *pos, *norm, *gnorm;
  54. Surface *surf;
  55. {
  56.     int xp, yp, zp;
  57.  
  58.     xp = pos->x > 0. ? pos->x : 1. - pos->x;
  59.     yp = pos->y > 0. ? pos->y : 1. - pos->y;
  60.     zp = pos->z > 0. ? pos->z : 1. - pos->z;
  61.  
  62.     if ((xp + yp + zp) % 2)
  63.         *surf = *checker->surf;
  64.     /* else surface stays the same. */
  65. }
  66.