0001: //-----------------------------------------------------------------------------
0002: // File: main.h
0003: //
0004: // Desc: Header file main sample app
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;      // unique id
0048:     CD3DMesh        *pMesh;
0049: public:
0050:     // constructor
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:     // Geter & Seter
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: // Name: class CMyD3DApplication
0102: // Desc: Application class. The base class (CD3DApplication) provides the 
0103: //       generic functionality needed in all Direct3D samples. CMyD3DApplication 
0104: //       adds functionality specific to this sample program.
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;     // Particle map
0121:     LPDIRECT3DSURFACE9      m_pParticleSurf;
0122: 
0123: 
0124:     BOOL                    m_bLoadingApp;  // TRUE, if the app is loading
0125:     CD3DFont*               m_pFont;        // Font for drawing text
0126:     UserInput               m_UserInput;    // Struct for storing user input 
0127: 
0128:     D3DXMATRIX              m_mView;        // View matrix
0129:     D3DXMATRIX              m_mProj;        // Projection matrix
0130:     FLOAT                   m_fWorldRotX;   // World rotation state X-axis
0131:     FLOAT                   m_fWorldRotY;   // World rotation state Y-axis
0132:     FLOAT                   m_zoom;         // Amount of track back of the camera
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: