home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 8 / Test / Main.cpp next >
Encoding:
C/C++ Source or Header  |  2004-06-21  |  3.0 KB  |  83 lines

  1. //-----------------------------------------------------------------------------
  2. // System Includes
  3. //-----------------------------------------------------------------------------
  4. #include <windows.h>
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Engine Includes
  8. //-----------------------------------------------------------------------------
  9. #include "..\Engine\Engine.h"
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Test State Class
  13. //-----------------------------------------------------------------------------
  14. class TestState : public State
  15. {
  16. public:
  17.     //-------------------------------------------------------------------------
  18.     // Allows the test state to preform any pre-processing construction.
  19.     //-------------------------------------------------------------------------
  20.     virtual void Load()
  21.     {
  22.         m_mesh = new Mesh( "Gun.x", "./Assets/" );
  23.  
  24.         // Set a suitable view matrix for viewing the test mesh.
  25.         D3DXMATRIX view;
  26.         D3DXMatrixLookAtLH( &view, &D3DXVECTOR3( -50.0f, 50.0f, -150.0f ), &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
  27.         g_engine->GetDevice()->SetTransform( D3DTS_VIEW, &view );    
  28.     };
  29.  
  30.     //-------------------------------------------------------------------------
  31.     // Allows the test state to preform any post-processing destruction.
  32.     //-------------------------------------------------------------------------
  33.     virtual void Close()
  34.     {
  35.         SAFE_DELETE( m_mesh );
  36.     };
  37.  
  38.     //-------------------------------------------------------------------------
  39.     // Returns the view setup details for the given frame.
  40.     //-------------------------------------------------------------------------
  41.     virtual void RequestViewer( ViewerSetup *viewer )
  42.     {
  43.         viewer->viewClearFlags = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER;
  44.     }
  45.  
  46.     //-------------------------------------------------------------------------
  47.     // Renders the test state.
  48.     //-------------------------------------------------------------------------
  49.     virtual void Render()
  50.     {
  51.         m_mesh->Render();
  52.     };
  53.  
  54. private:
  55.     Mesh *m_mesh; // The test mesh.
  56. };
  57.  
  58. //-----------------------------------------------------------------------------
  59. // Application specific state setup.
  60. //-----------------------------------------------------------------------------
  61. void StateSetup()
  62. {
  63.     g_engine->AddState( new TestState, true );
  64. }
  65.  
  66. //-----------------------------------------------------------------------------
  67. // Entry point for the application.
  68. //-----------------------------------------------------------------------------
  69. int WINAPI WinMain( HINSTANCE instance, HINSTANCE prev, LPSTR cmdLine, int cmdShow )
  70. {
  71.     // Create the engine setup structure.
  72.     EngineSetup setup;
  73.     setup.instance = instance;
  74.     setup.name = "Mesh/Material Test";
  75.     setup.scale = 0.01f;
  76.     setup.StateSetup = StateSetup;
  77.  
  78.     // Create the engine (using the setup structure), then run it.
  79.     new Engine( &setup );
  80.     g_engine->Run();
  81.  
  82.     return true;
  83. }