0001: //-------------------------------------------------------------
0002: // File: main.h
0003: //
0004: // Desc: Real-Time Global Illumination
0005: // Copyright (c) 2004 IMAGIRE Takashi. All rights reserved.
0006: //-------------------------------------------------------------
0007: #pragma once
0008: 
0009: //-------------------------------------------------------------
0010: // Defines, and constants(定義や定数)
0011: //-------------------------------------------------------------
0012: 
0013: // uncomment this if you want to build for nv3x
0014: //#define NV3X 1
0015: 
0016: // Struct to store the current input state(現在の入力データを保存する構造体)
0017: struct UserInput
0018: {
0019:     BOOL bRotateUp;
0020:     BOOL bRotateDown;
0021:     BOOL bRotateLeft;
0022:     BOOL bRotateRight;
0023:     BOOL bZoomIn;
0024:     BOOL bZoomOut;
0025:     BOOL bChangeShader;
0026:     BOOL bPause;
0027: };
0028: 
0029: 
0030: 
0031: 
0032: //-------------------------------------------------------------
0033: // Name: class CMyD3DApplication
0034: // Desc: Main class to run this application. Most functionality is inherited
0035: //       from the CD3DApplication base class.
0036: //       (アプリケーションのクラス)
0037: //-------------------------------------------------------------
0038: class CMyD3DApplication : public CD3DApplication
0039: {
0040:     enum{
0041:         L_MAX = 1,                          // The maximum expansion degree(最大の計算次数)
0042:         TEX_MAX = ((L_MAX+1)*(L_MAX+1)+3)/4,// The number of texture for SH expansion(SHのテクスチャ枚数)
0043: 
0044:         REDUCTION_MAPS = 3,                 // The number of times of reduction(縮小回数)
0045:     };
0046:     
0047:     // Scene management(シーン管理)
0048:     int                     m_iState;       // State(状態変数)
0049:     int                     m_iChangeState; // 
0050:     int                     m_iCount;       // Increment per rendering(状態変数管理用時間変数)
0051:     bool                    m_bPause;       // Pause
0052: 
0053:     // Model
0054:     CD3DMesh                *m_pMesh;
0055:     CD3DMesh                *m_pMeshBg;
0056:     CD3DMesh                *m_pMeshEnv;
0057:     
0058:     // Dynamics for a ball
0059:     D3DXVECTOR3             m_pos;          // Position(位置)
0060:     D3DXVECTOR3             m_vel;          // Velocity(速度)
0061:     D3DXVECTOR3             m_rot;          // Rotation(位置)
0062:     D3DXVECTOR3             m_omega;        // Angler velocity(位置)
0063: 
0064:     // Shader
0065:     int                     m_Shader;       // Type of shader(シェーダの種類)
0066:     LPD3DXEFFECT            m_pEffect;      // Effect for the sample(エフェクト)
0067:     D3DXHANDLE              m_hTechnique;   // Technique handle for RenderScene(テクニック)
0068:     D3DXHANDLE              m_hmWV;         // Handle for world+view matrix in effect(変換行列)
0069:     D3DXHANDLE              m_hmWVP;        // Handle for world+view+projection matrix in effect(変換行列)
0070:     D3DXHANDLE              m_htSrcTex;     // Handle for the scene texture in effect(テクスチャ)
0071:     D3DXHANDLE              m_fWidth;       // Handle for the texture width in effect(テクスチャ幅)
0072:     D3DXHANDLE              m_fHeight;      // Handle for the texture height in effect(テクスチャ高さ)
0073: 
0074:     // Rendering targets (レンダリングターゲット)
0075:     LPDIRECT3DSURFACE9      m_pMapZ;                    // Depth buffer
0076:     LPDIRECT3DTEXTURE9      m_pPosTex;                  // Height map(高さマップ)
0077:     LPDIRECT3DSURFACE9      m_pPosSurf;                 // 
0078:     LPDIRECT3DTEXTURE9      m_pPosLockTex;              // 
0079:     LPDIRECT3DSURFACE9      m_pPosLockSurf;             // 
0080:     LPDIRECT3DTEXTURE9      m_pNormalTex;               // Normal map(法線マップ)
0081:     LPDIRECT3DSURFACE9      m_pNormalSurf;              // 
0082:     LPDIRECT3DTEXTURE9      m_pNormalLockTex;           // 
0083:     LPDIRECT3DSURFACE9      m_pNormalLockSurf;          // 
0084: 
0085:     LPDIRECT3DTEXTURE9      m_pParaboloidTex[2];        // Environment map
0086:     LPDIRECT3DSURFACE9      m_pParaboloidSurf[2];
0087:     LPDIRECT3DTEXTURE9      m_pJacobianTex[TEX_MAX][2]; // SH coefficient of incoming light
0088: 
0089:     LPDIRECT3DTEXTURE9      m_pReductionTex [REDUCTION_MAPS];// Reduction buffer
0090:     LPDIRECT3DSURFACE9      m_pReductionSurf[REDUCTION_MAPS];
0091: 
0092:     LPDIRECT3DTEXTURE9      m_p64Tex ;// Reduction buffer
0093:     LPDIRECT3DSURFACE9      m_p64Surf;
0094:     LPDIRECT3DTEXTURE9      m_p8Tex ;// Reduction buffer
0095:     LPDIRECT3DSURFACE9      m_p8Surf;
0096: 
0097:     LPDIRECT3DTEXTURE9      m_pFinalTex[TEX_MAX];// PRT テクスチャ
0098:     LPDIRECT3DSURFACE9      m_pFinalSurf[TEX_MAX];
0099:     LPDIRECT3DTEXTURE9      m_pMaskTex;         // 係数計算
0100: #ifdef NV3X
0101:     LPDIRECT3DTEXTURE9      m_pPrtTex;          // 係数計算
0102: #endif // NV3X
0103: 
0104:     // Geometry (通常の座標変換行列)
0105:     D3DXMATRIX              m_mWorld;       // World matrix
0106:     D3DXMATRIX              m_mView;        // View matrix
0107:     D3DXMATRIX              m_mProj;        // Projection matrix
0108: 
0109:     FLOAT                   m_fWorldRotX;   // World rotation state X-axis(X軸回転)
0110:     FLOAT                   m_fWorldRotY;   // World rotation state Y-axis(Y軸回転)
0111:     FLOAT                   m_fViewZoom;    // Distance to lookat (視点の距離)
0112: 
0113:     BOOL                    m_bLoadingApp;  // TRUE, if the app is loading(ロード中?)
0114:     CD3DFont*               m_pFont;        // Font for drawing text(フォント)
0115:     UserInput               m_UserInput;    // Struct for storing user input (入力データ)
0116: 
0117: protected:
0118:     virtual HRESULT OneTimeSceneInit();
0119:     virtual HRESULT InitDeviceObjects();
0120:     virtual HRESULT RestoreDeviceObjects();
0121:     virtual HRESULT InvalidateDeviceObjects();
0122:     virtual HRESULT DeleteDeviceObjects();
0123:     virtual HRESULT Render();
0124:     virtual HRESULT FrameMove();
0125:     virtual HRESULT FinalCleanup();
0126:     virtual HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT );
0127: 
0128:     int  FrameMoveCreateMap();
0129:     void RenderCreateMap();
0130:     int  FrameMovePRT();
0131:     void RenderPRT();
0132:     void RenderParaboloidMap();
0133: 
0134:     HRESULT RenderText();
0135: 
0136:     void    UpdateInput( UserInput* pUserInput );
0137: public:
0138:     LRESULT MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
0139:     CMyD3DApplication();
0140:     virtual ~CMyD3DApplication();
0141: };
0142: 
0143: