![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The ZoomWin::AdjustField() FunctionThe AdjustField() function is the callback function that controls the viewports field-of-view. The function looks like this: void ZoomWin::AdjustField(LPDIRECT3DRMFRAME, void*, D3DVALUE) { static D3DVALUE time; time+=D3DVALUE(.5); animation->SetTime( time ); D3DVECTOR pos; zoomframe->GetPosition( 0, &pos ); viewport->SetField( pos.x ); } The function uses a static variable (time) to control the animation sequence. The time variable is incremented each time that the AdjustField() function is invoked. Once the time variable has been incremented, the new time is installed into the animation with the Direct3DRMAnimation SetTime() function. Next, the position of the animated frame (zoomframe) is retrieved. Recall that the zoomframe frames position is controlled by the animation. When we set the new animation time with the SetTime() function, the zoomframe was repositioned according to the animation sequence. The frames new position is retrieved with the GetPosition() function. Finally, the X axis position of the frame is used as a new field-of-view setting for the viewport. The new setting is installed with the Direct3DRMViewport SetField() function. Recall that viewport is a static RMWin class data member. This is why we have access to it from within a callback function. The ZoomWin Animation FunctionsThe Zoom demo allows you to change animation sequence settings (linear versus spline) from the Animation menu. This is done by setting different options using the Direct3DRMAnimation SetOptions() function. The two functions that respond to Animation menu entries appear like this: void ZoomWin::OnAnimationLinear() { animation->SetOptions( D3DRMANIMATION_LINEARPOSITION | D3DRMANIMATION_CLOSED | D3DRMANIMATION_POSITION ); } void ZoomWin::OnAnimationSpline() { animation->SetOptions( D3DRMANIMATION_SPLINEPOSITION | D3DRMANIMATION_CLOSED | D3DRMANIMATION_POSITION ); } The Animation menu functionality is made complete with the addition of check marks that appear on the menu to the left of the currently active animation mode. The two functions that determine if the check marks are to be displayed appear here: void ZoomWin::OnUpdateAnimationLinear(CCmdUI* pCmdUI) { D3DRMANIMATIONOPTIONS options = animation->GetOptions(); pCmdUI->SetCheck( options & D3DRMANIMATION_LINEARPOSITION ); } void ZoomWin::OnUpdateAnimationSpline(CCmdUI* pCmdUI) { D3DRMANIMATIONOPTIONS options = animation->GetOptions(); pCmdUI->SetCheck( options & D3DRMANIMATION_SPLINEPOSITION ); } The functions use the Direct3DRMAnimation GetOptions() function to retrieve the active animation settings. The SetCheck() function is used to activate the check marks if the setting of interest is detected. PickingDirect3D viewports provide support for picking. Picking is the selecting of an object through the selection of a location on the viewport. Typically, the mouse is used to select a location within the viewport. The viewport uses the location of the mouse to determine which object, if any, was picked. Picking is useful for applications that require precise and intuitive object selection. Picking brings a performance hit. Picking requires that Direct3D sorts though its internal structures and buffering data. This search is nontrivial. In fact, there is often a visible delay in animation when a picking operation is executed. On the other hand, picking is accurate to the pixel. Direct3D can determine exactly which object was selected based on the mouses location. If the object is visible, then the object can be selected with a pick operation.
|
![]() |
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. |