home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 3DTOSHI2.ZIP / mpg3d / source / G3dlight.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-01  |  1.5 KB  |  62 lines

  1.  
  2. // g3dlight.cpp
  3. //
  4. // Copyright (c) 1996 by Toshiaki Tsuji, all rights reserved.
  5.  
  6. #include "stdgfx.h"
  7. #include "g3dlight.h"
  8.  
  9. G3DLIGHT::G3DLIGHT () : G3DOBJECT ()
  10.   {
  11.     ShadeTable = NULL;
  12.     MinIntensity = (float)0;
  13.     MaxIntensity = (float)0;
  14.     ScaleFactor = (float)0;
  15.     Moved = Rotated = FALSE;
  16.   } // End of Constructor for G3DLIGHT
  17.  
  18. G3DLIGHT::~G3DLIGHT ()
  19.   {
  20.   } // End of Destructor for G3DLIGHT
  21.  
  22. VOID G3DLIGHT::SetPosition ( float x, float y, float z )
  23.   {
  24.     G3DOBJECT::SetPosition ( (float)0, (float)0, (float)0 );
  25.     Move ( x, y, z );
  26.   } // End of SetPosition for G3DLIGHT
  27.  
  28. VOID G3DLIGHT::SetShadeTable ( COLORTABLE *NewShadeTable )
  29.   {
  30.     ShadeTable = NewShadeTable;
  31.     if (ShadeTable!=NULL)
  32.       {
  33.         MinIntensity = (float)0;
  34.         MaxIntensity = (float)ShadeTable->GetNumLevels()*65536;
  35.         ScaleFactor = (float)ShadeTable->GetNumLevels ()*65536;  
  36.       } // End if
  37.   } // End of SetShadeTable for G3DLIGHT
  38.  
  39. float G3DLIGHT::ComputeIntensity ( FLPVECTOR3D *Point, FLPVECTOR3D *Normal )
  40.   {
  41.     FLPVECTOR3D Dir;
  42.     float DotProduct;
  43.  
  44.     FLPVectorSub ( &FLPWorldPosition, Point, &Dir );
  45.     FLPVectorNormalize ( &Dir );
  46.  
  47.     DotProduct = FLPVectorDot ( &Dir, Normal );
  48.     if (DotProduct<0)
  49.       return MinIntensity;
  50.  
  51.     float Intensity;
  52.  
  53.     Intensity = ScaleFactor*DotProduct;
  54.     if (Intensity<MinIntensity)
  55.       return MinIntensity;
  56.     else if (Intensity>MaxIntensity)
  57.       return MaxIntensity;
  58.     return Intensity;  
  59.   } // End of ComputeIntensity for G3DLIGHT
  60.  
  61.  
  62.