]> icculus.org git repositories - btb/d2x.git/blob - arch/win32/d3dframe/d3dutil.h
apply patch from bluecow to fix hmiplay sync issues and lack of midi reset (d1x r1.5)
[btb/d2x.git] / arch / win32 / d3dframe / d3dutil.h
1 //-----------------------------------------------------------------------------
2 // File: D3DUtil.h
3 //
4 // Desc: Helper functions and typing shortcuts for Direct3D programming.
5 //
6 //
7 // Copyright (C) 1997 Microsoft Corporation. All rights reserved
8 //-----------------------------------------------------------------------------
9
10 #ifndef D3DUTIL_H
11 #define D3DUTIL_H
12
13 #include <ddraw.h>
14 #include <d3d.h>
15
16
17 //-----------------------------------------------------------------------------
18 // Typing shortcuts for deleting and freeing objects.
19 //-----------------------------------------------------------------------------
20 #define SAFE_DELETE(p)  { if(p) { delete (p);     (p)=NULL; } }
21 #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
22
23
24
25
26 //-----------------------------------------------------------------------------
27 // Short cut functions for creating and using DX structures
28 //-----------------------------------------------------------------------------
29 VOID D3DUtil_InitDeviceDesc( D3DDEVICEDESC& ddDevDesc );
30 VOID D3DUtil_InitSurfaceDesc( DDSURFACEDESC2& ddsd, DWORD dwFlags=0,
31                               DWORD dwCaps=0 );
32 VOID D3DUtil_InitViewport( D3DVIEWPORT2& vdViewData, DWORD dwWidth=0,
33                            DWORD dwHeight=0 );
34 VOID D3DUtil_InitMaterial( D3DMATERIAL& mdMtrlData, FLOAT r=0.0f, FLOAT g=0.0f,
35                            FLOAT b=0.0f );
36 VOID D3DUtil_InitLight( D3DLIGHT& ldLightData, D3DLIGHTTYPE ltType, 
37                         FLOAT x=0.0f, FLOAT y=0.0f, FLOAT z=0.0f );
38
39
40
41
42 //-----------------------------------------------------------------------------
43 // Miscellaneous helper functions
44 //-----------------------------------------------------------------------------
45 LPDIRECTDRAW4 D3DUtil_GetDirectDrawFromDevice( LPDIRECT3DDEVICE3 pd3dDevice );
46 DWORD         D3DUtil_GetDeviceMemoryType( LPDIRECT3DDEVICE3 pd3dDevice );
47 DWORD         D3DUtil_GetDisplayDepth( LPDIRECTDRAW4 pDD4=NULL );
48
49
50
51
52 //-----------------------------------------------------------------------------
53 // D3D Matrix functions. For performance reasons, some functions are inline.
54 //-----------------------------------------------------------------------------
55 HRESULT D3DUtil_SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom, 
56                                D3DVECTOR& vAt, D3DVECTOR& vUp );
57 HRESULT D3DUtil_SetProjectionMatrix( D3DMATRIX& mat, FLOAT fFOV = 1.570795f,
58                                      FLOAT fAspect = 1.0f, 
59                                      FLOAT fNearPlane = 1.0f,
60                                      FLOAT fFarPlane = 1000.0f );
61
62 inline VOID D3DUtil_SetIdentityMatrix( D3DMATRIX& m )
63 {
64     m._12 = m._13 = m._14 = m._21 = m._23 = m._24 = 0.0f;
65     m._31 = m._32 = m._34 = m._41 = m._42 = m._43 = 0.0f;
66     m._11 = m._22 = m._33 = m._44 = 1.0f;
67 }
68
69 inline VOID D3DUtil_SetTranslateMatrix( D3DMATRIX& m, FLOAT tx, FLOAT ty,
70                                         FLOAT tz )
71 { D3DUtil_SetIdentityMatrix( m ); m._41 = tx; m._42 = ty; m._43 = tz; }
72
73 inline VOID D3DUtil_SetTranslateMatrix( D3DMATRIX& m, D3DVECTOR& v )
74 { D3DUtil_SetTranslateMatrix( m, v.x, v.y, v.z ); }
75
76 inline VOID D3DUtil_SetScaleMatrix( D3DMATRIX& m, FLOAT sx, FLOAT sy,
77                                     FLOAT sz )
78 { D3DUtil_SetIdentityMatrix( m ); m._11 = sx; m._22 = sy; m._33 = sz; }
79
80 inline VOID SetScaleMatrix( D3DMATRIX& m, D3DVECTOR& v )
81 { D3DUtil_SetScaleMatrix( m, v.x, v.y, v.z ); }
82
83 VOID    D3DUtil_SetRotateXMatrix( D3DMATRIX& mat, FLOAT fRads );
84 VOID    D3DUtil_SetRotateYMatrix( D3DMATRIX& mat, FLOAT fRads );
85 VOID    D3DUtil_SetRotateZMatrix( D3DMATRIX& mat, FLOAT fRads );
86 VOID    D3DUtil_SetRotationMatrix( D3DMATRIX& mat, D3DVECTOR& vDir,
87                                    FLOAT fRads );
88
89
90
91
92 //-----------------------------------------------------------------------------
93 // Debug printing support
94 //-----------------------------------------------------------------------------
95
96 HRESULT _DbgOut( TCHAR*, DWORD, HRESULT, TCHAR* );
97
98 #if defined(DEBUG) | defined(_DEBUG)
99     #define DEBUG_MSG(str)    _DbgOut( __FILE__, (DWORD)__LINE__, 0, str )
100     #define DEBUG_ERR(hr,str) _DbgOut( __FILE__, (DWORD)__LINE__, hr, str )
101 #else
102     #define DEBUG_MSG(str)    (0L)
103     #define DEBUG_ERR(hr,str) (hr)
104 #endif
105
106
107
108
109 #endif // D3DUTIL_H
110