home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / pplane / d3dutils.h < prev    next >
C/C++ Source or Header  |  1997-07-14  |  6KB  |  219 lines

  1. #ifndef D3DUTILS_H
  2. #define D3DUTILS_H
  3. /*
  4. **-----------------------------------------------------------------------------
  5. ** Name:    D3DUtils.h
  6. ** Purpose: Various D3D utility functions
  7. ** Notes:
  8. **
  9. ** Copyright (c) 1995 - 1997 by Microsoft, all rights reserved
  10. **-----------------------------------------------------------------------------
  11. */
  12.  
  13. #define D3D_OVERLOADS
  14. #include <d3d.h>
  15. #include <d3dtypes.h>
  16.  
  17. extern const float pi;
  18.  
  19. /*
  20. **-----------------------------------------------------------------------------
  21. ** Function Prototypes
  22. **-----------------------------------------------------------------------------
  23. */
  24.  
  25. // generic simple matrix routines
  26. extern D3DMATRIX ZeroMatrix(void);
  27. extern D3DMATRIX IdentityMatrix(void);
  28.  
  29. extern D3DMATRIX ProjectionMatrix(const float near_plane, const float far_plane, const float fov);
  30. extern D3DMATRIX ViewMatrix(const D3DVECTOR & from, const D3DVECTOR & at, 
  31.                             const D3DVECTOR & up, const float roll=0.0f);
  32.  
  33. extern D3DMATRIX RotateXMatrix(const float rads);
  34. extern D3DMATRIX RotateYMatrix(const float rads);
  35. extern D3DMATRIX RotateZMatrix(const float rads);
  36. extern D3DMATRIX TranslateMatrix(const float dx, const float dy, const float dz);
  37. extern D3DMATRIX TranslateMatrix(const D3DVECTOR & v);
  38. extern D3DMATRIX ScaleMatrix(const float size);
  39. extern D3DMATRIX ScaleMatrix(const float a, const float b, const float c);
  40. extern D3DMATRIX ScaleMatrix(const D3DVECTOR & v);
  41.  
  42. extern D3DMATRIX MatrixMult(const D3DMATRIX & a, const D3DMATRIX & b);
  43. extern D3DMATRIX MatrixInverse(const D3DMATRIX & m);
  44. extern D3DMATRIX MatrixTranspose(const D3DMATRIX & m);
  45.  
  46. extern D3DVECTOR TransformVector(const D3DVECTOR & v, const D3DMATRIX & m);
  47. extern D3DVECTOR TransformNormal(const D3DVECTOR & v, const D3DMATRIX & m);
  48.  
  49. // Other stuff
  50. extern float rnd(void);
  51.  
  52.  
  53. /*
  54. **-----------------------------------------------------------------------------
  55. ** Classes
  56. **-----------------------------------------------------------------------------
  57. */
  58.  
  59. /*
  60. **-----------------------------------------------------------------------------
  61. **    Class:        Light
  62. **    Purpose:    
  63. **-----------------------------------------------------------------------------
  64. */
  65.  
  66. class Light {
  67. protected:
  68. public:
  69.     D3DLIGHT2            light;        // structure defining the light
  70.     LPDIRECT3DLIGHT        lpD3DLight;    // object pointer for the light
  71.     int                    changed;
  72. public:
  73.     Light(LPDIRECT3D2 lpD3D);
  74.     ~Light();
  75.  
  76.     HRESULT        AddToViewport(LPDIRECT3DVIEWPORT2 lpView);
  77.     HRESULT        RemoveFromViewport(LPDIRECT3DVIEWPORT2 lpView);
  78.     HRESULT        Set(void);
  79.  
  80.     void        SetColor(const D3DVECTOR& color);
  81.     D3DVECTOR    GetColor(void) const;
  82.     void        SetPosition(const D3DVECTOR& position);
  83.     D3DVECTOR    GetPosition(void) const;
  84.     void        SetDirection(const D3DVECTOR& direction);
  85.     D3DVECTOR    GetDirection(void) const;
  86.     void        SetAttenuation(const D3DVECTOR& attenuation);
  87.     D3DVECTOR    GetAttenuation(void) const;
  88.     void        SetRange(const float range);
  89.     float        GetRange(void) const;
  90.     void        SetFalloff(const float falloff);
  91.     float        GetFalloff(void) const;
  92.     void        SetUmbra(const float falloff);
  93.     float        GetUmbra(void) const;
  94.     void        SetPenumbra(const float falloff);
  95.     float        GetPenumbra(void) const;
  96.     void        SetFlags(const DWORD flags);
  97.     DWORD        GetFlags(void) const;
  98. }; // End Light
  99.  
  100.  
  101. /*
  102. **-----------------------------------------------------------------------------
  103. **    Class:        PointLight
  104. **    Purpose:    
  105. **-----------------------------------------------------------------------------
  106. */
  107.  
  108. class PointLight : public Light {
  109.     public:
  110.         PointLight(LPDIRECT3D2 lpD3D, 
  111.                     const D3DVECTOR & color, 
  112.                     const D3DVECTOR & position);
  113. }; // End PointLight
  114.  
  115.  
  116. /*
  117. **-----------------------------------------------------------------------------
  118. **    Class:        SpotLight
  119. **    Purpose:    
  120. **-----------------------------------------------------------------------------
  121. */
  122.  
  123. class SpotLight : public Light {
  124.     public:
  125.         SpotLight(LPDIRECT3D2 lpD3D, 
  126.                 const D3DVECTOR& color, 
  127.                 const D3DVECTOR& position, 
  128.                 const D3DVECTOR& direction, 
  129.                 const float umbra_angle, 
  130.                 const float penumbra_angle);
  131. }; // End SpotLight
  132.  
  133.  
  134.  
  135. /*
  136. **-----------------------------------------------------------------------------
  137. **    Class:        DirectionalLight
  138. **    Purpose:    
  139. **-----------------------------------------------------------------------------
  140. */
  141.  
  142. class DirectionalLight : public Light {
  143.     public:
  144.         DirectionalLight(LPDIRECT3D2 lpD3D, 
  145.             const D3DVECTOR& color, const D3DVECTOR& direction);
  146. };
  147.  
  148.  
  149.  
  150. /*
  151. **-----------------------------------------------------------------------------
  152. **    Class:        ParallelPointLight
  153. **    Purpose:    
  154. **-----------------------------------------------------------------------------
  155. */
  156.  
  157. class ParallelPointLight : public Light {
  158.     public:
  159.         ParallelPointLight(LPDIRECT3D2 lpD3D, const D3DVECTOR& color, const D3DVECTOR& position);
  160. }; // End ParallelPointLight
  161.  
  162.  
  163.  
  164. /*
  165. **-----------------------------------------------------------------------------
  166. **    Class:        Material
  167. **    Purpose:    
  168. **-----------------------------------------------------------------------------
  169. */
  170.  
  171. class Material 
  172. {
  173. protected:
  174.     D3DMATERIAL            Mat;
  175.     D3DMATERIALHANDLE    hMat;
  176.     LPDIRECT3DMATERIAL2 lpMat;
  177.     int                    changed;
  178. public:
  179.     Material(LPDIRECT3D2 lpD3D, LPDIRECT3DDEVICE2 lpDev);
  180.     ~Material();
  181.  
  182.     HRESULT        SetAsCurrent(LPDIRECT3DDEVICE2 lpDev);
  183.     HRESULT        SetAsBackground(LPDIRECT3DVIEWPORT2 lpView);
  184.     HRESULT        Set(void);
  185.  
  186.     void        SetDiffuse(const D3DVECTOR& color);
  187.     D3DVECTOR    GetDiffuse(void) const;
  188.     void        SetAlpha(const float& alpha);
  189.     float        GetAlpha(void) const;
  190.     void        SetAmbient(const D3DVECTOR& color);
  191.     D3DVECTOR    GetAmbient(void) const;
  192.     void        SetEmissive(const D3DVECTOR& color);
  193.     D3DVECTOR    GetEmissive(void) const;
  194.     void        SetSpecular(const D3DVECTOR& color);
  195.     D3DVECTOR    GetSpecular(void) const;
  196.     void        SetPower(const D3DVALUE& power);
  197.     D3DVALUE    GetPower(void) const;
  198.     void        SetRampSize(const DWORD& ramp);
  199.     DWORD        GetRampSize(void) const;
  200.     void        SetTextureHandle(const D3DTEXTUREHANDLE& hTexture);
  201.     D3DTEXTUREHANDLE    GetTextureHandle(void);
  202. }; // End Material
  203.  
  204.  
  205. //
  206. // include the inline functions for the classes
  207. //
  208. #include "d3dutils.inl"
  209.  
  210.  
  211. /*
  212. **-----------------------------------------------------------------------------
  213. **    End of File
  214. **-----------------------------------------------------------------------------
  215. */
  216. #endif // D3DUTILS_H
  217.  
  218.  
  219.