![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Rendering OptionsDevices can be used to modify rendering options. The GetQuality() and SetQuality() member functions, for example, allow you to specify the rendering mode (Gouraud, flat, etc.) that the device will use to render scenes. Individual objects can override the device settings only if the rendering scheme they specify is more primitive than the device scheme. The default rendering setting is flat. The GetShades() and SetShades() member functions let you control how many different shades of a given color a device uses to render scenes. This setting often varies depending on the bit depth of the current video mode. The default number of shades is 32, but this is low for 24- and 32-bit modes. It pays to experiment with different shade values (values must be a power of 2) when determining the best setting for your application. The GetDither() and SetDither() member functions let you turn dithering on and off. Dithering is a technique that simulates a greater number of colors than are actually available and is useful for video modes that support few colors (usually 256 or fewer, but even video modes that support sixty-four thousand colors can benefit from this technique). Dithering is enabled by default. Direct3DWinDevice: The WinDevice InterfaceThe object that provides Direct3Ds device support is an example of a COM object that supports multiple interfaces. The Direct3DRMDevice interface that we discussed is one interface through which a device can be used. The Direct3DWinDevice is another. The Direct3DWinDevice interface represents devices that are supported by Windows. Figure 3.2 illustrates the Direct3D device object and its interfaces.
Because the Direct3DWinDevice interface is merely an alternative interface to a Direct3D device, applications use the existing device to retrieve the WinDevice interface. This is done with the QueryInterface() member function. The code looks like this: LPDIRECT3DRMWINDEVICE windev; device->QueryInterface( IID_IDirect3DRMWinDevice, (void**)&windev ); The device variable is a pre-initialized pointer to a Direct3DRMDevice interface. The devices QueryInterface() member function is used to retrieve a pointer to a Direct3DRMWinDevice interface. The IID_IDirect3DRMWinDevice is the GUID (Globally Unique Identifier) for the interface that is being requested. The WinDevice interface supports two member functions: HandleActivate() and HandlePaint(). Both of these functions notify Direct3D that certain Windows messages have been received. A Direct3D program should call the HandleActivate() function whenever a WM_ACTIVATE message is processed. Whenever a WM_PAINT message is processed, a Direct3D program should call the HandlePaint() function. Direct3DRMViewport: The Viewport InterfaceViewport is the Direct3D term for a camera. A viewport determines the location and orientation from which a scene is viewed. Viewports can be used to adjust field-of-view settings, front and back clipping, and perspective transformations. Viewports can also be animated to simulate situations where the user is traveling through a virtual environment. A viewport is represented by the Direct3DRMViewport interface and can be created using the Direct3DRM CreateViewport() member function as follows: d3drm->CreateViewport( device, camera, 0, 0, device->GetWidth(), device->GetHeight(), &viewport ); The d3drm variable is a pointer to a Direct3DRM interface. The device variable points to a Direct3DRMDevice interface. The camera variable is the frame that will determine the viewports location and orientation. Well talk about frames later in this chapter. Field of ViewThe field-of-view (FOV) setting can be adjusted with the SetField() member function. The default FOV is 0.5. Smaller values reduce the angle of the viewing frustum, causing a telephoto effect. Larger values increase the frustum angle and provide wide-angle effects. Negative values are not permitted. ClippingViewports control front and back 3D clipping. The SetFront() and SetBack() member functions can be used to define an area in front of the camera where objects will be visible. Objects located outside this area will not be rendered. The default front and back clipping settings are 1 and 100 respectively.
|
![]() |
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. |