![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Three more data members have been added: view1setting, view2setting, and view3setting. These values will be used to indicate how each viewport is to be placed. These data members are used in conjunction with the following constants (defined in resource.h):
Two private member functions have been added: ConfigViewport() and CreateViewports(). The ConfigViewport() function is used to assign specific orientations for a viewport, given its current configuration. The CreateViewports() function is used to initialize the three viewports. The reminder of added member functions are menu message handlers that were added to the class with ClassWizard. As youll see, these functions are used to change the viewports positions and orientations. The RMWin::CreateDevice() FunctionAdditional data members and functions arent the only way that the RMWin class has changed. One of the functions that has changed is the CreateDevice() function. The CreateDevice() function is responsible for the creation of several key elements to Direct3D programs. The version of CreateDevice() used by the MultiView demo appears as Listing 9.6. Listing 9.6 The RMWin::CreateDevice() function. BOOL RMWin::CreateDevice() { HRESULT r; r = DirectDrawCreateClipper( 0, &clipper, NULL ); if (r!=D3DRM_OK) { AfxMessageBox( "DirectDrawCreateClipper() failed" ); return FALSE; } r = clipper->SetHWnd( NULL, m_hWnd ); if (r!=DD_OK) { AfxMessageBox( "clipper->SetHWnd() failed" ); return FALSE; } RECT rect; ::GetClientRect( m_hWnd, &rect ); r = d3drm->CreateDeviceFromClipper( clipper, GetGUID(), rect.right, rect.bottom, &device ); if (r!=D3DRM_OK) { AfxMessageBox( "CreateDeviceFromClipper() failed" ); return FALSE; } device->SetQuality( D3DRMRENDER_GOURAUD ); HDC hdc = ::GetDC( m_hWnd ); int bpp = ::GetDeviceCaps( hdc, BITSPIXEL ); ::ReleaseDC( m_hWnd, hdc ); switch ( bpp ) { case 1: device->SetShades( 4 ); d3drm->SetDefaultTextureShades( 4 ); device->SetDither( TRUE ); break; case 8: // ... break; case 16: device->SetShades( 32 ); d3drm->SetDefaultTextureColors( 64 ); d3drm->SetDefaultTextureShades( 32 ); device->SetDither( FALSE ); break; case 24: case 32: device->SetShades( 256 ); d3drm->SetDefaultTextureColors( 64 ); d3drm->SetDefaultTextureShades( 256 ); device->SetDither( FALSE ); break; } d3drm->CreateFrame( NULL, &scene ); if (CreateScene()==FALSE) { AfxMessageBox( "CreateScene() failed" ); return FALSE; } d3drm->CreateFrame( scene, &camera1 ); ConfigViewport( camera1, view1setting ); d3drm->CreateFrame( scene, &camera2 ); ConfigViewport( camera2, view2setting ); d3drm->CreateFrame( scene, &camera3 ); ConfigViewport( camera3, view3setting ); CreateViewports(); return TRUE; } Rather than discuss the entire function here, well concentrate on the modifications. The portion of the function that is of interest to us is the last portion, following the initialization of the scene frame pointer: if (CreateScene()==FALSE) { AfxMessageBox( "CreateScene() failed" ); return FALSE; } d3drm->CreateFrame( scene, &camera1 ); ConfigViewport( camera1, view1setting ); d3drm->CreateFrame( scene, &camera2 ); ConfigViewport( camera2, view2setting ); d3drm->CreateFrame( scene, &camera3 ); ConfigViewport( camera3, view3setting ); CreateViewports(); This portion of code first calls the CreateScene() function. If the CreateScene() function returns FALSE, a message box is displayed, and the CreateDevice() function returns FALSE as well. If the CreateScene() function is successful, the CreateDevice() function initializes three frames: camera1, camera2, and camera3. These frames will be used to create and position the demos three viewports. After each frame is created, it is passed to the ConfigViewport() function along with the integer that stores the viewports configuration. The ConfigViewport() function positions the frames differently, depending on the value that is used as the second argument. The values shown are initialized like this: view1setting=VIEWPORT_FRONT; view2setting=VIEWPORT_LEFT; view3setting=VIEWPORT_TOP; The values indicate that the first viewport will provide a front view of the scene. The second viewport will view the scene from the left, and the third viewport will provide a top-down view. After the three camera frames are initialized, and ConfigViewport() is called for each one, the actual viewport creation is performed by the CreateViewports() function.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |