实时3D地形引擎——Chapter6_01——初读
来源:互联网 发布:会计帮软件下载 编辑:程序博客网 时间:2024/06/16 00:37
坑已经开几天了,就从今天开始吧。书的第六章只有一个例子,而且不长,但实际上这个例子用到的框架也需要阅读,所以估计也要看很久。
class cMyHost:public cGameHost{public:cMyHost(){};~cMyHost(){};HRESULT InitDeviceObjects();HRESULT RestoreDeviceObjects();HRESULT InvalidateDeviceObjects();HRESULT DeleteDeviceObjects();HRESULT updateScene();HRESULT renderScene();HRESULT OneTimeSceneInit(); LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );cTerrain m_terrainSystem;cTexture* m_pHeightMap;cRenderMethod* m_pRenderMethod;cSurfaceMaterial* m_pSurfaceMaterial;};
以上就是这章用到的类,可以看到该类继承了cGameHost,所以接下来看看cGameHost类。
class cGameHost : public CD3DApplication, public cSingleton<cGameHost>{public:// Creators... cGameHost(); ~cGameHost();// Mutators...const cSystemInfo& systemInfo()const;cResourcePoolManager& resourceManager();cDisplayManager& displayManager();cLightManager& lightManager();void setupWorldQuadTree(const cRect3d& worldExtents); const D3DPRESENT_PARAMETERS& presentParams()const; // Parameters for CreateDevice/Reset HWND appWindow()const; // The main app window HWND focusWindow()const; // The D3D focus window (usually same as m_hWnd) LPDIRECT3D9 d3dInterface()const; LPDIRECT3DDEVICE9 d3dDevice()const; // The D3D rendering device const D3DCAPS9& d3dCaps()const; // Caps for the device const D3DSURFACE_DESC& d3dsdBackBuffer()const; // Surface desc of the backbuffer const RECT& rcWindowClient()const; // Saved client area size for mode switches const TCHAR* windowTitle()const; bool hardwareVertexShadersAllowed()const; void setActiveCamera(cCamera* pCamera); void beginRenderStage(uint8 stage); void endRenderStage();const tchar* rootPath()const {return m_rootPath;}cCamera& defaultCamera() {return m_defaultCamera;}cCamera* activeCamera() {return m_pActiveCamera;}cSceneNode& rootNode() {return m_rootNode;}cQuadTree& quadTree() {return m_quadTree;}cRect3d& worldExtents() {return m_worldExtents;}uint32 currentRenderStage()const {return m_activeRenderStage;}protected:virtual HRESULT OneTimeSceneInit();virtual HRESULT InitDeviceObjects();virtual HRESULT RestoreDeviceObjects();virtual HRESULT InvalidateDeviceObjects();virtual HRESULT DeleteDeviceObjects();virtual HRESULT Render();virtual HRESULT FrameMove();virtual HRESULT FinalCleanup(); virtual HRESULT ConfirmDevice(D3DCAPS9* pCaps,DWORD behavior,D3DFORMAT display,D3DFORMAT backbuffer);virtual HRESULT updateScene();virtual HRESULT renderScene();// helper function to provide basic user inputvirtual void updateCamera(float lateralSpeed, float rotationSpeed, cTerrain* pTerrain = 0,float groundOffset = 0,bool forceUpdate = 0);private:// Private Data...cSystemInfo m_systemInfo;CD3DFont* m_pFont; floatm_updateTimeCount;uint32 m_activeRenderStage;cResourcePoolManagerm_resourceManager;cDisplayManagerm_displayManager;cLightManagerm_lightManager;cSceneNodem_rootNode;cCameram_defaultCamera;cCamera*m_pActiveCamera;cQuadTreem_quadTree;cRect3dm_worldExtents;tcharm_rootPath[MAX_PATH];boolm_frameReady;// Invalid Functions... cGameHost(const cGameHost& Src); cGameHost& operator=(const cGameHost& Src);};这一次的代码的确非常多。然后就是再次的继承,CD3DApplication和cSingleton。Singleton就不用说了,再次看看CD3DApplication。(看来这一章要分好几篇了,涉及到两个框架的阅读。。。)
//-----------------------------------------------------------------------------// Name: class CD3DApplication// Desc: A base class for creating sample D3D9 applications. To create a simple// Direct3D application, simply derive this class into a class (such as// class CMyD3DApplication) and override the following functions, as // needed:// OneTimeSceneInit() - To initialize app data (alloc mem, etc.)// InitDeviceObjects() - To initialize the 3D scene objects// FrameMove() - To animate the scene// Render() - To render the scene// DeleteDeviceObjects() - To cleanup the 3D scene objects// FinalCleanup() - To cleanup app data (for exitting the app)// MsgProc() - To handle Windows messages//-----------------------------------------------------------------------------class CD3DApplication{protected: CD3DEnumeration m_d3dEnumeration; CD3DSettings m_d3dSettings; // Internal variables for the state of the app bool m_bWindowed; bool m_bActive; bool m_bDeviceLost; bool m_bMinimized; bool m_bMaximized; bool m_bIgnoreSizeChange; bool m_bDeviceObjectsInited; bool m_bDeviceObjectsRestored; // Internal variables used for timing bool m_bFrameMoving; bool m_bSingleStep; // Internal error handling function HRESULT DisplayErrorMsg( HRESULT hr, DWORD dwType ); // Internal functions to manage and render the 3D scene static bool ConfirmDeviceHelper( D3DCAPS9* pCaps, VertexProcessingType vertexProcessingType, D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat ); void BuildPresentParamsFromSettings(); bool FindBestWindowedMode( bool bRequireHAL, bool bRequireREF ); bool FindBestFullscreenMode( bool bRequireHAL, bool bRequireREF ); HRESULT ChooseInitialD3DSettings(); HRESULT Initialize3DEnvironment(); HRESULT HandlePossibleSizeChange(); HRESULT Reset3DEnvironment(); HRESULT ToggleFullscreen(); HRESULT ForceWindowed(); HRESULT UserSelectNewDevice(); void Cleanup3DEnvironment(); HRESULT Render3DEnvironment(); virtual HRESULT AdjustWindowForChange(); virtual void UpdateStats();protected: // Main objects used for creating and rendering the 3D scene D3DPRESENT_PARAMETERS m_d3dpp; // Parameters for CreateDevice/Reset HWND m_hWnd; // The main app window HWND m_hWndFocus; // The D3D focus window (usually same as m_hWnd) HMENU m_hMenu; // App menu bar (stored here when fullscreen) LPDIRECT3D9 m_pD3D; // The main D3D object LPDIRECT3DDEVICE9 m_pd3dDevice; // The D3D rendering device D3DCAPS9 m_d3dCaps; // Caps for the device D3DSURFACE_DESC m_d3dsdBackBuffer; // Surface desc of the backbuffer DWORD m_dwCreateFlags; // Indicate sw or hw vertex processing DWORD m_dwWindowStyle; // Saved window style for mode switches RECT m_rcWindowBounds; // Saved window bounds for mode switches RECT m_rcWindowClient; // Saved client area size for mode switches // Variables for timing FLOAT m_fTime; // Current time in seconds FLOAT m_fElapsedTime; // Time elapsed since last frame FLOAT m_fFPS; // Instanteous frame rate TCHAR m_strDeviceStats[90];// String to hold D3D device stats TCHAR m_strFrameStats[90]; // String to hold frame stats // Overridable variables for the app TCHAR* m_strWindowTitle; // Title for the app's window DWORD m_dwCreationWidth; // Width used to create window DWORD m_dwCreationHeight; // Height used to create window bool m_bShowCursorWhenFullscreen; // Whether to show cursor when fullscreen bool m_bClipCursorWhenFullscreen; // Whether to limit cursor pos when fullscreen bool m_bStartFullscreen; // Whether to start up the app in fullscreen mode // Overridable functions for the 3D scene created by the app virtual HRESULT ConfirmDevice(D3DCAPS9*,DWORD,D3DFORMAT,D3DFORMAT) { return S_OK; } virtual HRESULT OneTimeSceneInit() { return S_OK; } virtual HRESULT InitDeviceObjects() { return S_OK; } virtual HRESULT RestoreDeviceObjects() { return S_OK; } virtual HRESULT FrameMove() { return S_OK; } virtual HRESULT Render() { return S_OK; } virtual HRESULT InvalidateDeviceObjects() { return S_OK; } virtual HRESULT DeleteDeviceObjects() { return S_OK; } virtual HRESULT FinalCleanup() { return S_OK; }public: // Functions to create, run, pause, and clean up the application virtual HRESULT Create( HINSTANCE hInstance ); virtual INT Run(); virtual LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); virtual void Pause( bool bPause ); virtual ~CD3DApplication() { } // Internal constructor CD3DApplication();};
这次我把注释也贴上来了,因为这个注释很重要。从这个注释中我们也可以知道这个类的作用。限于篇幅,接下来的内容将新开一篇。下一篇是D3DAPP框架的阅读。
- 实时3D地形引擎——Chapter6_01——初读
- 实时3D地形引擎——Chapter6_02——D3DApp框架阅读1
- 实时3D地形引擎——Chapter6_03——D3DApp框架阅读2
- 实时3D地形引擎——Chapter6_04——GameHost框架阅读
- 实时3D地形引擎开坑
- 3D地形编程——之地形射线查询(修正)
- 3D地形编程——之GeoMipMap基础
- Genesis-3D学习手册——19.地形指南
- Genesis-3D学习手册——20.地形高度
- Genesis-3D学习手册——21.地形植被
- 3D地形编程——之GeoMipMap基础
- Genesis-3D 入门教程—11.地形系统
- Unity5.6大规模地形—地形资源构建(3)
- 3D地形编程——之GeoMipMap基础(3)
- 3D地形编程——之GeoMipMap基础(1)
- 3D地形编程——之GeoMipMap基础(2)
- 3D地形编程——之GeoMipMap基础(4)
- 3D地形编程——之GeoMipMap基础(5)
- 有关cvLaplace函数和cvSobel函数的参数及显示处理后的图片问题
- WinCE中的console重定向
- HttpservletResponse对象 作业
- [Shell]查找当前目录下的.svn并删除
- 获得三星(Samsung) Galaxy Note 10.1的root权限--(2)
- 实时3D地形引擎——Chapter6_01——初读
- 设计模式在综合前置中的运用--概述
- 网页游戏性能优化最佳实践:延迟策略
- 10个步骤让你成为高效的Web开发者
- J2EE常用的JAR及开源项目
- (转载)一位软件工程师的6年总结
- vs2010开发asp.net程序时cookie写入名称区分大小写
- Ubuntu共享xp系统文件-Vm tools的安装
- 磁盘读写原理