0001:
0002:
0003:
0004:
0005:
0006: #ifndef D3DUTIL_H
0007: #define D3DUTIL_H
0008: #include <D3D9.h>
0009: #include <D3DX9Math.h>
0010:
0011:
0012:
0013:
0014:
0015:
0016:
0017:
0018:
0019: VOID D3DUtil_InitMaterial( D3DMATERIAL9& mtrl, FLOAT r=0.0f, FLOAT g=0.0f,
0020: FLOAT b=0.0f, FLOAT a=1.0f );
0021:
0022:
0023:
0024:
0025:
0026:
0027:
0028:
0029:
0030: VOID D3DUtil_InitLight( D3DLIGHT9& light, D3DLIGHTTYPE ltType,
0031: FLOAT x=0.0f, FLOAT y=0.0f, FLOAT z=0.0f );
0032:
0033:
0034:
0035:
0036:
0037:
0038:
0039:
0040:
0041: HRESULT D3DUtil_CreateTexture( LPDIRECT3DDEVICE9 pd3dDevice, TCHAR* strTexture,
0042: LPDIRECT3DTEXTURE9* ppTexture,
0043: D3DFORMAT d3dFormat = D3DFMT_UNKNOWN );
0044:
0045:
0046:
0047:
0048:
0049:
0050:
0051:
0052: D3DXMATRIX D3DUtil_GetCubeMapViewMatrix( DWORD dwFace );
0053:
0054:
0055:
0056:
0057:
0058:
0059:
0060:
0061:
0062: D3DXQUATERNION D3DUtil_GetRotationFromCursor( HWND hWnd,
0063: FLOAT fTrackBallRadius=1.0f );
0064:
0065:
0066:
0067:
0068:
0069:
0070:
0071:
0072: HRESULT D3DUtil_SetDeviceCursor( LPDIRECT3DDEVICE9 pd3dDevice, HCURSOR hCursor,
0073: BOOL bAddWatermark );
0074:
0075:
0076:
0077:
0078:
0079:
0080:
0081: TCHAR* D3DUtil_D3DFormatToString( D3DFORMAT format, bool bWithPrefix = true );
0082:
0083:
0084:
0085:
0086:
0087:
0088: class CD3DArcBall
0089: {
0090: INT m_iWidth;
0091: INT m_iHeight;
0092: FLOAT m_fRadius;
0093: FLOAT m_fRadiusTranslation;
0094:
0095: D3DXQUATERNION m_qDown;
0096: D3DXQUATERNION m_qNow;
0097: D3DXMATRIX m_matRotation;
0098: D3DXMATRIX m_matRotationDelta;
0099: D3DXMATRIX m_matTranslation;
0100: D3DXMATRIX m_matTranslationDelta;
0101: BOOL m_bDrag;
0102: BOOL m_bRightHanded;
0103:
0104: D3DXVECTOR3 ScreenToVector( int sx, int sy );
0105:
0106: public:
0107: LRESULT HandleMouseMessages( HWND, UINT, WPARAM, LPARAM );
0108:
0109: D3DXMATRIX* GetRotationMatrix() { return &m_matRotation; }
0110: D3DXMATRIX* GetRotationDeltaMatrix() { return &m_matRotationDelta; }
0111: D3DXMATRIX* GetTranslationMatrix() { return &m_matTranslation; }
0112: D3DXMATRIX* GetTranslationDeltaMatrix() { return &m_matTranslationDelta; }
0113: BOOL IsBeingDragged() { return m_bDrag; }
0114:
0115: VOID SetRadius( FLOAT fRadius );
0116: VOID SetWindow( INT w, INT h, FLOAT r=0.9 );
0117: VOID SetRightHanded( BOOL bRightHanded ) { m_bRightHanded = bRightHanded; }
0118:
0119: CD3DArcBall();
0120: VOID Init();
0121: };
0122:
0123:
0124:
0125:
0126:
0127:
0128:
0129:
0130: class CD3DCamera
0131: {
0132: D3DXVECTOR3 m_vEyePt;
0133: D3DXVECTOR3 m_vLookatPt;
0134: D3DXVECTOR3 m_vUpVec;
0135:
0136: D3DXVECTOR3 m_vView;
0137: D3DXVECTOR3 m_vCross;
0138:
0139: D3DXMATRIX m_matView;
0140: D3DXMATRIX m_matBillboard;
0141:
0142: FLOAT m_fFOV;
0143: FLOAT m_fAspect;
0144: FLOAT m_fNearPlane;
0145: FLOAT m_fFarPlane;
0146: D3DXMATRIX m_matProj;
0147:
0148: public:
0149:
0150: D3DXVECTOR3 GetEyePt() { return m_vEyePt; }
0151: D3DXVECTOR3 GetLookatPt() { return m_vLookatPt; }
0152: D3DXVECTOR3 GetUpVec() { return m_vUpVec; }
0153: D3DXVECTOR3 GetViewDir() { return m_vView; }
0154: D3DXVECTOR3 GetCross() { return m_vCross; }
0155:
0156: FLOAT GetFOV() { return m_fFOV; }
0157: FLOAT GetAspect() { return m_fAspect; }
0158: FLOAT GetNearPlane() { return m_fNearPlane; }
0159: FLOAT GetFarPlane() { return m_fFarPlane; }
0160:
0161: D3DXMATRIX GetViewMatrix() { return m_matView; }
0162: D3DXMATRIX GetBillboardMatrix() { return m_matBillboard; }
0163: D3DXMATRIX GetProjMatrix() { return m_matProj; }
0164:
0165: VOID SetViewParams( D3DXVECTOR3 &vEyePt, D3DXVECTOR3& vLookatPt,
0166: D3DXVECTOR3& vUpVec );
0167: VOID SetProjParams( FLOAT fFOV, FLOAT fAspect, FLOAT fNearPlane,
0168: FLOAT fFarPlane );
0169:
0170: CD3DCamera();
0171: };
0172:
0173:
0174:
0175:
0176: #endif
0177: