d3dUtility.h
资源名称:Direct3D.rar [点击查看]
上传用户:junlon
上传日期:2022-01-05
资源大小:39075k
文件大小:3k
源码类别:
DirextX编程
开发平台:
Visual C++
- //////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // File: d3dUtility.h
- //
- // Author: Zeng fancy (C) All Rights Reserved
- //
- // System: Pentium M 1.73G, 256 DDR, ATI X700, Windows XP, MSVC++ 7.0
- //
- // Desc: Provides some common d3d elements or functions.
- //
- //////////////////////////////////////////////////////////////////////////////////////////////////
- #ifndef __d3dUtilityH__
- #define __d3dUtilityH__
- //namespace myd3d
- //{
- //
- // Cleanup
- //
- template<class T> void Release(T t)
- {
- if( t )
- {
- t->Release();
- t = 0;
- }
- }
- template<class T> void Delete(T t)
- {
- if( t )
- {
- delete t;
- t = 0;
- }
- }
- //
- // Colors
- //
- const D3DXCOLOR WHITE( D3DCOLOR_XRGB(255, 255, 255) );
- const D3DXCOLOR BLACK( D3DCOLOR_XRGB( 0, 0, 0) );
- const D3DXCOLOR RED( D3DCOLOR_XRGB(255, 0, 0) );
- const D3DXCOLOR GREEN( D3DCOLOR_XRGB( 0, 255, 0) );
- const D3DXCOLOR BLUE( D3DCOLOR_XRGB( 0, 0, 255) );
- const D3DXCOLOR YELLOW( D3DCOLOR_XRGB(255, 255, 0) );
- const D3DXCOLOR CYAN( D3DCOLOR_XRGB( 0, 255, 255) );
- const D3DXCOLOR MAGENTA( D3DCOLOR_XRGB(255, 0, 255) );
- //
- // d3d Object and Device, Windowed = TRUE, Stencil Format = D3DFORMAT_D24S8
- //
- bool Initd3dDevice( IDirect3D9* pD3D, IDirect3DDevice9** ppD3DDevice, HWND hWnd);
- //
- // Lights
- //
- D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color);
- D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color);
- D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color);
- //
- // Materials
- //
- D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);
- const D3DMATERIAL9 WHITE_MTRL = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f);
- const D3DMATERIAL9 RED_MTRL = InitMtrl(RED, RED, RED, BLACK, 2.0f);
- const D3DMATERIAL9 GREEN_MTRL = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f);
- const D3DMATERIAL9 BLUE_MTRL = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f);
- const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f);
- //
- // Bounding Objects
- //
- struct BoundingBox
- {
- BoundingBox();
- BoundingBox(D3DXVECTOR3 minPoint, D3DXVECTOR3 maxPoint);
- bool isPointInside(D3DXVECTOR3& p);
- D3DXVECTOR3 _minPoint;
- D3DXVECTOR3 _maxPoint;
- };
- struct BoundingSphere
- {
- BoundingSphere(D3DXVECTOR3 center, float radius);
- D3DXVECTOR3 _center;
- float _radius;
- };
- //
- // Randomness
- //
- // Desc: Return random float in [lowBound, highBound] interval.
- float GetRandomFloat(float lowBound, float highBound);
- // Desc: Returns a random vector in the bounds specified by min and max.
- void GetRandomVector(
- D3DXVECTOR3* out,
- D3DXVECTOR3* min,
- D3DXVECTOR3* max);
- //
- // Conversion
- //
- DWORD FtoDw(float f);
- //}
- #endif // __d3dUtilityH__