source: GTP/trunk/App/Demos/Illum/Standalone/StochasticIteration [DirectX]/Stochastic_Rad1.cpp @ 1808

Revision 1808, 24.3 KB checked in by szirmay, 18 years ago (diff)
Line 
1//--------------------------------------------------------------------------------------
2// File: Stochastic_Rad1.cpp
3//
4// Starting point for new Direct3D applications
5//
6// Copyright (c) Microsoft Corporation. All rights reserved.
7//--------------------------------------------------------------------------------------
8#include "dxstdafx.h"
9#include "d3ddefs.h"
10#include <ctime>
11#include <fstream>
12#include <vector>
13#include "vector4d.h"
14#include "color.h"
15#include "object.h"
16#include "ObjectVector.h"
17#include "RadiosityAlgorithm.h"
18#include "resource.h"
19
20//#define DEBUG_VS   // Uncomment this line to debug vertex shaders
21//#define DEBUG_PS   // Uncomment this line to debug pixel shaders
22
23
24//--------------------------------------------------------------------------------------
25// Global variables
26//--------------------------------------------------------------------------------------
27ID3DXFont*              g_pFont = NULL;         // Font for drawing text
28ID3DXSprite*            g_pTextSprite = NULL;   // Sprite for batching draw text calls
29ID3DXEffect*            g_pEffect = NULL;       // D3DX effect interface
30CModelViewerCamera      g_Camera;               // A model viewing camera
31bool                    g_bShowHelp = true;     // If true, it renders the UI control text
32bool                                    firstRun = false;
33CDXUTDialog             g_HUD;                  // dialog for standard controls
34CDXUTDialog             g_SampleUI;             // dialog for sample specific controls
35RadiosityAlgorithm*         g_RadiosityAlgorithm;   // holds algorithm instance
36float xtranslate;
37float ytranslate;
38float ztranslate;
39float xrotate;
40float yrotate;
41float zrotate;
42D3DXVECTOR3 eye;
43D3DXVECTOR3 lookAt;
44int picnum=0;
45
46
47//--------------------------------------------------------------------------------------
48// UI control IDs
49//--------------------------------------------------------------------------------------
50#define IDC_TOGGLEFULLSCREEN    1
51#define IDC_TOGGLEREF           2
52#define IDC_CHANGEDEVICE        3
53
54
55
56//--------------------------------------------------------------------------------------
57// Forward declarations
58//--------------------------------------------------------------------------------------
59bool    CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed );
60void    CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps );
61HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
62HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
63void    CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
64void    CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
65LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing );
66void    CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown  );
67void    CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl );
68void    CALLBACK OnLostDevice();
69void    CALLBACK OnDestroyDevice();
70
71void    InitApp();
72HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, WCHAR* strFileName, ID3DXMesh** ppMesh );
73void    RenderText();
74
75
76//--------------------------------------------------------------------------------------
77// Entry point to the program. Initializes everything and goes into a message processing
78// loop. Idle time is used to render the scene.
79//--------------------------------------------------------------------------------------
80INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
81{
82    // Set the callback functions. These functions allow the sample framework to notify
83    // the application about device changes, user input, and windows messages.  The
84    // callbacks are optional so you need only set callbacks for events you're interested
85    // in. However, if you don't handle the device reset/lost callbacks then the sample
86    // framework won't be able to reset your device since the application must first
87    // release all device resources before resetting.  Likewise, if you don't handle the
88    // device created/destroyed callbacks then the sample framework won't be able to
89    // recreate your device resources.
90    DXUTSetCallbackDeviceCreated( OnCreateDevice );
91    DXUTSetCallbackDeviceReset( OnResetDevice );
92    DXUTSetCallbackDeviceLost( OnLostDevice );
93    DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
94    DXUTSetCallbackMsgProc( MsgProc );
95    DXUTSetCallbackKeyboard( KeyboardProc );
96    DXUTSetCallbackFrameRender( OnFrameRender );
97    DXUTSetCallbackFrameMove( OnFrameMove );
98
99    // Show the cursor and clip it when in full screen
100    DXUTSetCursorSettings( true, true );
101        //g_RadiosityAlgorithm=new RadiosityAlgorithm(256,256,9,D3DFMT_G16R16F,D3DFMT_A16B16G16R16F,D3DFMT_A32B32G32R32F,D3DFMT_R32F,D3DFMT_D24S8);
102    InitApp();
103
104    // Initialize the sample framework and create the desired Win32 window and Direct3D
105    // device for the application. Calling each of these functions is optional, but they
106    // allow you to set several options which control the behavior of the framework.
107    DXUTInit( true, true, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
108    DXUTCreateWindow( L"Stochastic Radiosity" );
109    DXUTCreateDevice( D3DADAPTER_DEFAULT, true, 800,600, IsDeviceAcceptable, ModifyDeviceSettings );
110       
111    // Pass control to the sample framework for handling the message pump and
112    // dispatching render calls. The sample framework will call your FrameMove
113    // and FrameRender callback when there is idle time between handling window messages.
114    DXUTMainLoop();
115
116    // Perform any application-level cleanup here. Direct3D device resources are released within the
117    // appropriate callback functions and therefore don't require any cleanup code here.
118        //SAFE_DELETE(g_RadiosityAlgorithm);
119    return DXUTGetExitCode();
120}
121
122
123//--------------------------------------------------------------------------------------
124// Initialize the app
125//--------------------------------------------------------------------------------------
126void InitApp()
127{
128    // Initialize dialogs
129    g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
130    g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );
131    g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22 );
132    g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22 );
133
134    g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;
135    g_SampleUI.AddComboBox( 19, 35, iY += 24, 125, 22 );
136    g_SampleUI.GetComboBox( 19 )->AddItem( L"Text1", NULL );
137    g_SampleUI.GetComboBox( 19 )->AddItem( L"Text2", NULL );
138    g_SampleUI.GetComboBox( 19 )->AddItem( L"Text3", NULL );
139    g_SampleUI.GetComboBox( 19 )->AddItem( L"Text4", NULL );
140    g_SampleUI.AddCheckBox( 21, L"Checkbox1", 35, iY += 24, 125, 22 );
141    g_SampleUI.AddCheckBox( 11, L"Checkbox2", 35, iY += 24, 125, 22 );
142    g_SampleUI.AddRadioButton( 12, 1, L"Radio1G1", 35, iY += 24, 125, 22 );
143    g_SampleUI.AddRadioButton( 13, 1, L"Radio2G1", 35, iY += 24, 125, 22 );
144    g_SampleUI.AddRadioButton( 14, 1, L"Radio3G1", 35, iY += 24, 125, 22 );
145    g_SampleUI.GetRadioButton( 14 )->SetChecked( true );
146    g_SampleUI.AddButton( 17, L"Button1", 35, iY += 24, 125, 22 );
147    g_SampleUI.AddButton( 18, L"Button2", 35, iY += 24, 125, 22 );
148    g_SampleUI.AddRadioButton( 15, 2, L"Radio1G2", 35, iY += 24, 125, 22 );
149    g_SampleUI.AddRadioButton( 16, 2, L"Radio2G3", 35, iY += 24, 125, 22 );
150    g_SampleUI.GetRadioButton( 16 )->SetChecked( true );
151    g_SampleUI.AddSlider( 20, 50, iY += 24, 100, 22 );
152    g_SampleUI.GetSlider( 20 )->SetRange( 0, 100 );
153    g_SampleUI.GetSlider( 20 )->SetValue( 50 );
154//    g_SampleUI.AddEditBox( 20, L"Test", 35, iY += 24, 125, 22 );
155}
156
157
158//--------------------------------------------------------------------------------------
159// Called during device initialization, this code checks the device for some
160// minimum set of capabilities, and rejects those that don't pass by returning false.
161//--------------------------------------------------------------------------------------
162bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat,
163                                  D3DFORMAT BackBufferFormat, bool bWindowed )
164{
165    // Skip backbuffer formats that don't support alpha blending
166    IDirect3D9* pD3D = DXUTGetD3DObject();
167    if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
168                    AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
169                    D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
170        return false;
171
172    return true;
173}
174
175
176//--------------------------------------------------------------------------------------
177// This callback function is called immediately before a device is created to allow the
178// application to modify the device settings. The supplied pDeviceSettings parameter
179// contains the settings that the framework has selected for the new device, and the
180// application can make any desired changes directly to this structure.  Note however that
181// the sample framework will not correct invalid device settings so care must be taken
182// to return valid device settings, otherwise IDirect3D9::CreateDevice() will fail. 
183//--------------------------------------------------------------------------------------
184void CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps )
185{
186    // If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW
187    // then switch to SWVP.
188    if( (pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
189         pCaps->VertexShaderVersion < D3DVS_VERSION(1,1) )
190    {
191        pDeviceSettings->BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
192    }
193    else
194    {
195        pDeviceSettings->BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
196    }
197
198    // This application is designed to work on a pure device by not using
199    // IDirect3D9::Get*() methods, so create a pure device if supported and using HWVP.
200    if ((pCaps->DevCaps & D3DDEVCAPS_PUREDEVICE) != 0 &&
201        (pDeviceSettings->BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) != 0 )
202        pDeviceSettings->BehaviorFlags |= D3DCREATE_PUREDEVICE;
203
204    // Debugging vertex shaders requires either REF or software vertex processing
205    // and debugging pixel shaders requires REF. 
206#ifdef DEBUG_VS
207    if( pDeviceSettings->DeviceType != D3DDEVTYPE_REF )
208    {
209        pDeviceSettings->BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
210        pDeviceSettings->BehaviorFlags &= ~D3DCREATE_PUREDEVICE;
211        pDeviceSettings->BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
212    }
213#endif
214#ifdef DEBUG_PS
215    pDeviceSettings->DeviceType = D3DDEVTYPE_REF;
216#endif
217
218}
219
220
221//--------------------------------------------------------------------------------------
222// This callback function will be called immediately after the Direct3D device has been
223// created, which will happen during application initialization and windowed/full screen
224// toggles. This is the best location to create D3DPOOL_MANAGED resources since these
225// resources need to be reloaded whenever the device is destroyed. Resources created 
226// here should be released in the OnDestroyDevice callback.
227//--------------------------------------------------------------------------------------
228HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc )
229{
230    HRESULT hr;
231        eye.x=0;
232        eye.y=0.5;
233        eye.z=15.0f;
234        lookAt.x=0;
235        lookAt.y=0.5f;
236        lookAt.z=10.0f;
237    // Initialize the font
238    V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
239                         OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
240                         L"Arial", &g_pFont ) );
241
242    D3DXVECTOR3 vecEye(0.0f, 0.0f, -5.0f);
243    D3DXVECTOR3 vecAt (0.0f, 0.0f, -0.0f);
244    g_Camera.SetViewParams( &vecEye, &vecAt );
245        /*
246        g_RadiosityAlgorithm->initObjects(pd3dDevice);
247       
248        g_RadiosityAlgorithm->doOriginalVisibilityMapPass(false,L"origvismap.hdr");
249        */
250               
251    return S_OK;
252}
253
254
255//--------------------------------------------------------------------------------------
256// This function loads the mesh and ensures the mesh has normals; it also optimizes the
257// mesh for the graphics card's vertex cache, which improves performance by organizing
258// the internal triangle list for less cache misses.
259//--------------------------------------------------------------------------------------
260HRESULT LoadMesh( IDirect3DDevice9* pd3dDevice, WCHAR* strFileName, ID3DXMesh** ppMesh )
261{
262    ID3DXMesh* pMesh = NULL;
263    WCHAR str[MAX_PATH];
264    HRESULT hr;
265
266    // Load the mesh with D3DX and get back a ID3DXMesh*.  For this
267    // sample we'll ignore the X file's embedded materials since we know
268    // exactly the model we're loading.  See the mesh samples such as
269    // "OptimizedMesh" for a more generic mesh loading example.
270    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, strFileName ) );
271
272    V_RETURN( D3DXLoadMeshFromX(str, D3DXMESH_MANAGED, pd3dDevice, NULL, NULL, NULL, NULL, &pMesh) );
273
274    DWORD *rgdwAdjacency = NULL;
275
276    // Make sure there are normals which are required for lighting
277    if( !(pMesh->GetFVF() & D3DFVF_NORMAL) )
278    {
279        ID3DXMesh* pTempMesh;
280        V( pMesh->CloneMeshFVF( pMesh->GetOptions(),
281                                  pMesh->GetFVF() | D3DFVF_NORMAL,
282                                  pd3dDevice, &pTempMesh ) );
283        V( D3DXComputeNormals( pTempMesh, NULL ) );
284
285        SAFE_RELEASE( pMesh );
286        pMesh = pTempMesh;
287    }
288
289    // Optimize the mesh for this graphics card's vertex cache
290    // so when rendering the mesh's triangle list the vertices will
291    // cache hit more often so it won't have to re-execute the vertex shader
292    // on those vertices so it will improve perf.     
293    rgdwAdjacency = new DWORD[pMesh->GetNumFaces() * 3];
294    if( rgdwAdjacency == NULL )
295        return E_OUTOFMEMORY;
296    V( pMesh->ConvertPointRepsToAdjacency(NULL, rgdwAdjacency) );
297    V( pMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, rgdwAdjacency, NULL, NULL, NULL) );
298    delete []rgdwAdjacency;
299
300    *ppMesh = pMesh;
301
302    return S_OK;
303}
304
305
306//--------------------------------------------------------------------------------------
307// This callback function will be called immediately after the Direct3D device has been
308// reset, which will happen after a lost device scenario. This is the best location to
309// create D3DPOOL_DEFAULT resources since these resources need to be reloaded whenever
310// the device is lost. Resources created here should be released in the OnLostDevice
311// callback.
312//--------------------------------------------------------------------------------------
313HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
314                                const D3DSURFACE_DESC* pBackBufferSurfaceDesc )
315{
316    HRESULT hr;
317
318    if( g_pFont )
319        V_RETURN( g_pFont->OnResetDevice() );
320    if( g_pEffect )
321        V_RETURN( g_pEffect->OnResetDevice() );
322
323    // Create a sprite to help batch calls when drawing many lines of text
324    V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pTextSprite ) );
325
326    // Setup the camera's projection parameters
327    float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height;
328    g_Camera.SetProjParams( D3DX_PI/4, fAspectRatio, 0.1f, 1000.0f );
329    g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
330
331    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width-170, 0 );
332    g_HUD.SetSize( 170, 170 );
333    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width-170, pBackBufferSurfaceDesc->Height-350 );
334    g_SampleUI.SetSize( 170, 300 );
335
336    return S_OK;
337}
338
339
340//--------------------------------------------------------------------------------------
341// This callback function will be called once at the beginning of every frame. This is the
342// best location for your application to handle updates to the scene, but is not
343// intended to contain actual rendering calls, which should instead be placed in the
344// OnFrameRender callback. 
345//--------------------------------------------------------------------------------------
346void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime )
347{
348    // Update the camera's position based on user input
349    g_Camera.FrameMove( fElapsedTime );
350}
351
352
353//--------------------------------------------------------------------------------------
354// This callback function will be called at the end of every frame to perform all the
355// rendering calls for the scene, and it will also be called if the window needs to be
356// repainted. After this function has returned, the sample framework will call
357// IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain
358//--------------------------------------------------------------------------------------
359void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime )
360{
361    HRESULT hr;
362    UINT iterationCount=5000;
363    srand(256);
364        /*
365        if(!firstRun){
366               
367                if(picnum<20){
368                        xtranslate-=0.1f;
369                }
370                if((picnum<40)&&(picnum>=20)){
371                        ztranslate+=0.1f;
372                }
373               
374                if((picnum<60)&&(picnum>=40)){
375                        ytranslate+=0.1f;
376                }
377               
378               
379                picnum=10;
380                //ztranslate=(picnum-8)*(0.1f);
381                //ytranslate=(picnum-8)*(0.1f);
382                xtranslate=-0.7f;
383                g_RadiosityAlgorithm->moveObjects(xtranslate,ytranslate,ztranslate);
384                hr=g_RadiosityAlgorithm->doEmissionMapPass(false,L"emissionMap.hdr");
385                hr=g_RadiosityAlgorithm->iterate(iterationCount,-1);
386                hr=g_RadiosityAlgorithm->doRadiosityAveragingPass(false,L"finalRadMap.hdr",iterationCount);
387                firstRun=true;
388        }
389       
390        g_RadiosityAlgorithm->moveCamera(eye.x,eye.y,eye.z,lookAt.x,lookAt.y,lookAt.z);
391        */
392        LPTSTR buffer=(LPTSTR)new TCHAR[200];
393       
394        wsprintf(buffer,L"picture%i.bmp",iterationCount);
395        /*
396        hr=g_RadiosityAlgorithm->doFinalPicturePass(true,buffer);
397        */
398        delete [] buffer;
399        //pd3dDevice->Present(NULL,NULL,NULL,NULL);
400}
401
402
403//--------------------------------------------------------------------------------------
404// Render the help and statistics text. This function uses the ID3DXFont interface for
405// efficient text rendering.
406//--------------------------------------------------------------------------------------
407void RenderText()
408{
409    // The helper object simply helps keep track of text position, and color
410    // and then it calls pFont->DrawText( m_pSprite, strMsg, -1, &rc, DT_NOCLIP, m_clr );
411    // If NULL is passed in as the sprite object, then it will work however the
412    // pFont->DrawText() will not be batched together.  Batching calls will improves performance.
413    const D3DSURFACE_DESC* pd3dsdBackBuffer = DXUTGetBackBufferSurfaceDesc();
414    CDXUTTextHelper txtHelper( g_pFont, g_pTextSprite, 15 );
415
416    // Output statistics
417    txtHelper.Begin();
418    txtHelper.SetInsertionPos( 5, 5 );
419    txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );
420    txtHelper.DrawTextLine( DXUTGetFrameStats() );
421    txtHelper.DrawTextLine( DXUTGetDeviceStats() );
422
423    txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
424    txtHelper.DrawTextLine( L"Put whatever misc status here" );
425   
426    // Draw help
427    if( g_bShowHelp )
428    {
429        txtHelper.SetInsertionPos( 10, pd3dsdBackBuffer->Height-15*6 );
430        txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 0.75f, 0.0f, 1.0f ) );
431        txtHelper.DrawTextLine( L"Controls (F1 to hide):" );
432
433        txtHelper.SetInsertionPos( 40, pd3dsdBackBuffer->Height-15*5 );
434        txtHelper.DrawTextLine( L"Blah: X\n"
435                                L"Quit: ESC" );
436    }
437    else
438    {
439        txtHelper.SetInsertionPos( 10, pd3dsdBackBuffer->Height-15*2 );
440        txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
441        txtHelper.DrawTextLine( L"Press F1 for help" );
442    }
443    txtHelper.End();
444}
445
446
447//--------------------------------------------------------------------------------------
448// Before handling window messages, the sample framework passes incoming windows
449// messages to the application through this callback function. If the application sets
450// *pbNoFurtherProcessing to TRUE, then the sample framework will not process this message.
451//--------------------------------------------------------------------------------------
452LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing )
453{
454    // Give the dialogs a chance to handle the message first
455    *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
456    if( *pbNoFurtherProcessing )
457        return 0;
458    *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
459    if( *pbNoFurtherProcessing )
460        return 0;
461
462    // Pass all remaining windows messages to camera so it can respond to user input
463    g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
464
465    return 0;
466}
467
468
469//--------------------------------------------------------------------------------------
470// As a convenience, the sample framework inspects the incoming windows messages for
471// keystroke messages and decodes the message parameters to pass relevant keyboard
472// messages to the application.  The framework does not remove the underlying keystroke
473// messages, which are still passed to the application's MsgProc callback.
474//--------------------------------------------------------------------------------------
475void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown )
476{
477    if( bKeyDown )
478    {
479        switch( nChar )
480        {
481            case VK_F1: g_bShowHelp = !g_bShowHelp; break;
482            case VK_NUMPAD8: eye.z-=0.1f; lookAt.z-=0.1f; break;
483            case VK_NUMPAD2: eye.z+=0.1f; lookAt.z+=0.1f; break;
484            case VK_NUMPAD4: eye.x+=0.1f; lookAt.x+=0.1f; break;
485            case VK_NUMPAD6: eye.x-=0.1f; lookAt.x-=0.1f; break;
486                        case 'H': ytranslate+=0.01f; break;
487                        case 'N': ytranslate-=0.01f; break;
488            case 'W': ztranslate+=0.01f; break;
489            case 'A': ztranslate-=0.01f; break;
490            case 'S': xtranslate+=0.01f; break;
491            case 'D': xtranslate-=0.01f; break;
492                       
493        }
494    }
495}
496
497
498//--------------------------------------------------------------------------------------
499// Handles the GUI events
500//--------------------------------------------------------------------------------------
501void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl )
502{
503    switch( nControlID )
504    {
505        case IDC_TOGGLEFULLSCREEN: DXUTToggleFullScreen(); break;
506        case IDC_TOGGLEREF:        DXUTToggleREF(); break;
507        case IDC_CHANGEDEVICE:     DXUTSetShowSettingsDialog( !DXUTGetShowSettingsDialog() ); break;
508    }
509}
510
511
512//--------------------------------------------------------------------------------------
513// This callback function will be called immediately after the Direct3D device has
514// entered a lost state and before IDirect3DDevice9::Reset is called. Resources created
515// in the OnResetDevice callback should be released here, which generally includes all
516// D3DPOOL_DEFAULT resources. See the "Lost Devices" section of the documentation for
517// information about lost devices.
518//--------------------------------------------------------------------------------------
519void CALLBACK OnLostDevice()
520{
521    if( g_pFont )
522        g_pFont->OnLostDevice();
523    if( g_pEffect )
524        g_pEffect->OnLostDevice();
525    SAFE_RELEASE( g_pTextSprite );
526}
527
528
529//--------------------------------------------------------------------------------------
530// This callback function will be called immediately after the Direct3D device has
531// been destroyed, which generally happens as a result of application termination or
532// windowed/full screen toggles. Resources created in the OnCreateDevice callback
533// should be released here, which generally includes all D3DPOOL_MANAGED resources.
534//--------------------------------------------------------------------------------------
535void CALLBACK OnDestroyDevice()
536{
537        /*
538        g_RadiosityAlgorithm->deleteObjects();
539    SAFE_RELEASE( g_pEffect );
540    SAFE_RELEASE( g_pFont );
541        */
542}
543
544
545
Note: See TracBrowser for help on using the repository browser.