Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.6 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: D3DUtil.h
  3. //
  4. // Desc: Helper functions and typing shortcuts for Direct3D programming.
  5. //
  6. // Copyright (c) 1997-1999 Microsoft Corporation. All rights reserved
  7. //-----------------------------------------------------------------------------
  8. #ifndef D3DUTIL_H
  9. #define D3DUTIL_H
  10. #include <ddraw.h>
  11. #include <d3d.h>
  12. //-----------------------------------------------------------------------------
  13. // Miscellaneous helper functions
  14. //-----------------------------------------------------------------------------
  15. const TCHAR* D3DUtil_GetDXSDKMediaPath();
  16. #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
  17. #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
  18. //-----------------------------------------------------------------------------
  19. // Short cut functions for creating and using DX structures
  20. //-----------------------------------------------------------------------------
  21. VOID D3DUtil_InitDeviceDesc(D3DDEVICEDESC7& ddDevDesc);
  22. VOID D3DUtil_InitSurfaceDesc(DDSURFACEDESC2& ddsd, DWORD dwFlags=0,
  23. DWORD dwCaps=0);
  24. VOID D3DUtil_InitMaterial(D3DMATERIAL7& mtrl, FLOAT r=0.0f, FLOAT g=0.0f,
  25. FLOAT b=0.0f, FLOAT a=1.0f);
  26. VOID D3DUtil_InitLight(D3DLIGHT7& light, D3DLIGHTTYPE ltType,
  27. FLOAT x=0.0f, FLOAT y=0.0f, FLOAT z=0.0f);
  28. //-----------------------------------------------------------------------------
  29. // D3D Matrix functions. For performance reasons, some functions are inline.
  30. //-----------------------------------------------------------------------------
  31. HRESULT D3DUtil_SetViewMatrix(D3DMATRIX& mat, D3DVECTOR& vFrom,
  32. D3DVECTOR& vAt, D3DVECTOR& vUp);
  33. HRESULT D3DUtil_SetProjectionMatrix(D3DMATRIX& mat, FLOAT fFOV = 1.570795f,
  34. FLOAT fAspect = 1.0f,
  35. FLOAT fNearPlane = 1.0f,
  36. FLOAT fFarPlane = 1000.0f);
  37. inline VOID D3DUtil_SetIdentityMatrix(D3DMATRIX& m)
  38. {
  39. m._12 = m._13 = m._14 = m._21 = m._23 = m._24 = 0.0f;
  40. m._31 = m._32 = m._34 = m._41 = m._42 = m._43 = 0.0f;
  41. m._11 = m._22 = m._33 = m._44 = 1.0f;
  42. }
  43. inline VOID D3DUtil_SetTranslateMatrix(D3DMATRIX& m, FLOAT tx, FLOAT ty,
  44. FLOAT tz)
  45. { D3DUtil_SetIdentityMatrix(m); m._41 = tx; m._42 = ty; m._43 = tz; }
  46. inline VOID D3DUtil_SetTranslateMatrix(D3DMATRIX& m, D3DVECTOR& v)
  47. { D3DUtil_SetTranslateMatrix(m, v.x, v.y, v.z); }
  48. inline VOID D3DUtil_SetScaleMatrix(D3DMATRIX& m, FLOAT sx, FLOAT sy,
  49. FLOAT sz)
  50. { D3DUtil_SetIdentityMatrix(m); m._11 = sx; m._22 = sy; m._33 = sz; }
  51. inline VOID SetScaleMatrix(D3DMATRIX& m, D3DVECTOR& v)
  52. { D3DUtil_SetScaleMatrix(m, v.x, v.y, v.z); }
  53. VOID D3DUtil_SetRotateXMatrix(D3DMATRIX& mat, FLOAT fRads);
  54. VOID D3DUtil_SetRotateYMatrix(D3DMATRIX& mat, FLOAT fRads);
  55. VOID D3DUtil_SetRotateZMatrix(D3DMATRIX& mat, FLOAT fRads);
  56. VOID D3DUtil_SetRotationMatrix(D3DMATRIX& mat, D3DVECTOR& vDir,
  57. FLOAT fRads);
  58. //-----------------------------------------------------------------------------
  59. // Debug printing support
  60. //-----------------------------------------------------------------------------
  61. HRESULT _DbgOut(TCHAR*, DWORD, HRESULT, TCHAR*);
  62. #if defined(DEBUG) | defined(_DEBUG)
  63. #define DEBUG_MSG(str) _DbgOut(__FILE__, (DWORD)__LINE__, 0, str)
  64. #define DEBUG_ERR(hr,str) _DbgOut(__FILE__, (DWORD)__LINE__, hr, str)
  65. #else
  66. #define DEBUG_MSG(str) (0L)
  67. #define DEBUG_ERR(hr,str) (hr)
  68. #endif
  69. #endif // D3DUTIL_H