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

  1. /*
  2.  * jittered.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.  * jittered.c,v 4.1 1994/08/09 07:57:00 explorer Exp
  17.  *
  18.  * jittered.c,v
  19.  * Revision 4.1  1994/08/09  07:57:00  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:04  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:34:43  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "light.h"
  30. #include "jittered.h"
  31.  
  32. static LightMethods *iJitteredMethods = NULL;
  33.  
  34. Jittered *
  35. JitteredCreate(pos, e1, e2)
  36. Vector *pos, *e1, *e2;
  37. {
  38.     Jittered *j;
  39.  
  40.     j = (Jittered *)share_malloc(sizeof(Jittered));
  41.  
  42.     j->pos = *pos;
  43.     j->e1 = *e1;
  44.     j->e2 = *e2;
  45.  
  46.     return j;
  47. }
  48.  
  49. LightMethods *
  50. JitteredMethods()
  51. {
  52.     if (iJitteredMethods == (LightMethods *)NULL) {
  53.         iJitteredMethods = LightMethodsCreate();
  54.         iJitteredMethods->intens = JitteredIntens;
  55.         iJitteredMethods->dir = JitteredDirection;
  56.     }
  57.     return iJitteredMethods;
  58. }
  59.  
  60. int
  61. JitteredIntens(jit, lcolor, cache, ray, dist, noshadow, color)
  62. Jittered *jit;
  63. Color *lcolor, *color;
  64. ShadowCache *cache;
  65. Ray *ray;
  66. Float dist;
  67. int noshadow;
  68. {
  69.     return !Shadowed(color, lcolor, cache, ray, dist, noshadow);
  70. }
  71.  
  72. void
  73. JitteredDirection(lp, pos, dir, dist)
  74. Jittered *lp;
  75. Vector *pos, *dir;
  76. Float *dist;
  77. {
  78.     /*
  79.      * Choose a location with the area define by corner, e1
  80.      * and e2 at which this sample will be taken.
  81.      */
  82.     VecAddScaled(lp->pos, nrand(), lp->e1, &lp->curpos);
  83.     VecAddScaled(lp->curpos, nrand(), lp->e2, &lp->curpos);
  84.     VecSub(lp->curpos, *pos, dir);
  85.     *dist = VecNormalize(dir);
  86. }
  87.  
  88. JitteredMethodRegister(meth)
  89. UserMethodType meth;
  90. {
  91.     if (iJitteredMethods)
  92.         iJitteredMethods->user = meth;
  93. }
  94.