0001:
0002:
0003:
0004:
0005:
0006: #pragma once
0007:
0008: #define frand() ((FLOAT)rand()/(FLOAT)(RAND_MAX+1))
0009:
0010:
0011:
0012:
0013:
0014:
0015:
0016: struct UserInput
0017: {
0018: BOOL bRotateUp;
0019: BOOL bRotateDown;
0020: BOOL bRotateLeft;
0021: BOOL bRotateRight;
0022: BOOL bZ;
0023: BOOL bX;
0024: };
0025:
0026:
0027:
0028:
0029: D3DVERTEXELEMENT9 decl[] =
0030: {
0031: {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
0032: {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
0033: {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
0034: {0, 32, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_LOOKUP, D3DDECLUSAGE_SAMPLE, 0},
0035: D3DDECL_END()
0036: };
0037:
0038:
0039:
0040:
0041:
0042:
0043: #define PARTICLE_MAX 64
0044:
0045: class CParticle{
0046: private:
0047: int id;
0048: CD3DMesh *pMesh;
0049: public:
0050:
0051: CParticle(){
0052: pMesh = new CD3DMesh();
0053: }
0054: ~CParticle(){Delete();}
0055:
0056: void CreateMesh(LPDIRECT3DDEVICE9 pd3dDevice, TCHAR *filename);
0057: void RestoreDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice);
0058: void InvalidateDeviceObjects(){pMesh->InvalidateDeviceObjects();}
0059: void Destroy(){pMesh->Destroy();}
0060: void Delete(){SAFE_DELETE(pMesh);}
0061:
0062:
0063:
0064: inline void SetId(int i) {id=i;}
0065: inline CD3DMesh *GetMesh() {return pMesh;}
0066:
0067: };
0068:
0069:
0070:
0071: class CParticleMgr{
0072: private:
0073: CParticle object[PARTICLE_MAX];
0074: public:
0075: CParticleMgr(){for(DWORD i=0;i<PARTICLE_MAX;i++) object[i].SetId(i);}
0076: ~CParticleMgr(){for(DWORD i=0;i<PARTICLE_MAX;i++) object[i].Delete();}
0077: void CreateMesh(LPDIRECT3DDEVICE9 pd3dDevice, TCHAR *filename){
0078: for(DWORD i=0;i<PARTICLE_MAX;i++){
0079: object[i].CreateMesh(pd3dDevice, filename);
0080: }
0081: }
0082: void RestoreDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice){
0083: for(DWORD i=0;i<PARTICLE_MAX;i++){
0084: object[i].RestoreDeviceObjects(pd3dDevice);
0085: }
0086: }
0087: void InvalidateDeviceObjects(){
0088: for(DWORD i=0;i<PARTICLE_MAX;i++){
0089: object[i].InvalidateDeviceObjects();
0090: }
0091: }
0092: void Destroy(){
0093: for(DWORD i=0;i<PARTICLE_MAX;i++){
0094: object[i].Destroy();
0095: }
0096: }
0097:
0098: CParticle *GetObj(DWORD i){return &object[i];}
0099: };
0100:
0101:
0102:
0103:
0104:
0105:
0106: class CMyD3DApplication : public CD3DApplication
0107: {
0108: LPDIRECT3DVERTEXDECLARATION9 m_pDecl;
0109: CD3DMesh* m_pMeshBg;
0110: CParticleMgr* m_pParticle;
0111: FLOAT m_TexWorldScale;
0112:
0113:
0114: LPD3DXEFFECT m_pEffect;
0115: D3DXHANDLE m_hTechnique;
0116: D3DXHANDLE m_hmWVP;
0117: D3DXHANDLE m_hvVector;
0118:
0119:
0120: LPDIRECT3DTEXTURE9 m_pParticleTex;
0121: LPDIRECT3DSURFACE9 m_pParticleSurf;
0122:
0123:
0124: BOOL m_bLoadingApp;
0125: CD3DFont* m_pFont;
0126: UserInput m_UserInput;
0127:
0128: D3DXMATRIX m_mView;
0129: D3DXMATRIX m_mProj;
0130: FLOAT m_fWorldRotX;
0131: FLOAT m_fWorldRotY;
0132: FLOAT m_zoom;
0133:
0134:
0135: protected:
0136: virtual HRESULT OneTimeSceneInit();
0137: virtual HRESULT InitDeviceObjects();
0138: virtual HRESULT RestoreDeviceObjects();
0139: virtual HRESULT InvalidateDeviceObjects();
0140: virtual HRESULT DeleteDeviceObjects();
0141: virtual HRESULT Render();
0142: virtual HRESULT FrameMove();
0143: virtual HRESULT FinalCleanup();
0144: virtual HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT, D3DFORMAT );
0145:
0146: HRESULT RenderText();
0147:
0148: void UpdateInput( UserInput* pUserInput );
0149: void InitParticleMap();
0150: void UpdateParticleMap();
0151:
0152: public:
0153: LRESULT MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
0154: CMyD3DApplication();
0155: virtual ~CMyD3DApplication();
0156: };
0157:
0158: