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

  1. /*
  2.  * point.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.  * point.c,v 4.1 1994/08/09 07:57:09 explorer Exp
  17.  *
  18.  * point.c,v
  19.  * Revision 4.1  1994/08/09  07:57:09  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:35:20  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "light.h"
  30. #include "point.h"
  31.  
  32. static LightMethods *iPointMethods = NULL;
  33.  
  34. Pointlight *
  35. PointCreate(pos)
  36. Vector *pos;
  37. {
  38.     Pointlight *p;
  39.  
  40.     p = (Pointlight *)share_malloc(sizeof(Pointlight));
  41.     p->pos = *pos;
  42.     return p;
  43. }
  44.  
  45. LightMethods *
  46. PointMethods()
  47. {
  48.     if (iPointMethods == (LightMethods *)NULL) {
  49.         iPointMethods = LightMethodsCreate();
  50.         iPointMethods->intens = PointIntens;
  51.         iPointMethods->dir = PointDirection;
  52.     }
  53.     return iPointMethods;
  54. }
  55.  
  56. int
  57. PointIntens(lp, lcolor, cache, ray, dist, noshadow, color)
  58. Pointlight *lp;
  59. Color *lcolor, *color;
  60. ShadowCache *cache;
  61. Ray *ray;
  62. Float dist;
  63. int noshadow;
  64. {
  65.     return !Shadowed(color, lcolor, cache, ray, dist, noshadow);
  66. }
  67.  
  68. void
  69. PointDirection(lp, pos, dir, dist)
  70. Pointlight *lp;
  71. Vector *pos, *dir;
  72. Float *dist;
  73. {
  74.     /*
  75.      * Calculate dir from position to center of
  76.      * light source.
  77.      */
  78.     VecSub(lp->pos, *pos, dir);
  79.     *dist = VecNormalize(dir);
  80. }
  81.  
  82. PointMethodRegister(meth)
  83. UserMethodType meth;
  84. {
  85.     if (iPointMethods)
  86.         iPointMethods->user = meth;
  87. }
  88.