home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Graphics / graphics-16000.iso / msdos / raytrace / rayshade / src / point.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  2KB  |  82 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.  * $Id: point.c,v 4.0 91/07/17 14:35:20 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    point.c,v $
  19.  * Revision 4.0  91/07/17  14:35:20  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "light.h"
  24. #include "point.h"
  25.  
  26. static LightMethods *iPointMethods = NULL;
  27.  
  28. Pointlight *
  29. PointCreate(pos)
  30. Vector *pos;
  31. {
  32.     Pointlight *p;
  33.  
  34.     p = (Pointlight *)share_malloc(sizeof(Pointlight));
  35.     p->pos = *pos;
  36.     return p;
  37. }
  38.  
  39. LightMethods *
  40. PointMethods()
  41. {
  42.     if (iPointMethods == (LightMethods *)NULL) {
  43.         iPointMethods = LightMethodsCreate();
  44.         iPointMethods->intens = PointIntens;
  45.         iPointMethods->dir = PointDirection;
  46.     }
  47.     return iPointMethods;
  48. }
  49.  
  50. int
  51. PointIntens(lp, lcolor, cache, ray, dist, noshadow, color)
  52. Pointlight *lp;
  53. Color *lcolor, *color;
  54. ShadowCache *cache;
  55. Ray *ray;
  56. Float dist;
  57. int noshadow;
  58. {
  59.     return !Shadowed(color, lcolor, cache, ray, dist, noshadow);
  60. }
  61.  
  62. void
  63. PointDirection(lp, pos, dir, dist)
  64. Pointlight *lp;
  65. Vector *pos, *dir;
  66. Float *dist;
  67. {
  68.     /*
  69.      * Calculate dir from position to center of
  70.      * light source.
  71.      */
  72.     VecSub(lp->pos, *pos, dir);
  73.     *dist = VecNormalize(dir);
  74. }
  75.  
  76. PointMethodRegister(meth)
  77. UserMethodType meth;
  78. {
  79.     if (iPointMethods)
  80.         iPointMethods->user = meth;
  81. }
  82.