![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The RMWin::ConfigViewport() FunctionThe ConfigViewport() function takes two arguments: a pointer to a Direct3DRMFrame interface and an integer value that indicates the frames desired positioning. The function looks like this: void RMWin::ConfigViewport(LPDIRECT3DRMFRAME camera, int view) { if (view==VIEWPORT_FRONT) { camera->SetPosition( scene, D3DVALUE(0), D3DVALUE(0), D3DVALUE(-50) ); camera->SetOrientation( scene, D3DVALUE(0), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0) ); } else if (view==VIEWPORT_LEFT) { camera->SetPosition( scene, D3DVALUE(-50), D3DVALUE(0), D3DVALUE(0) ); camera->SetOrientation( scene, D3DVALUE(1), D3DVALUE(0), D3DVALUE(0), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0) ); } else if (view==VIEWPORT_RIGHT) { camera->SetPosition( scene, D3DVALUE(50), D3DVALUE(0), D3DVALUE(0) ); camera->SetOrientation( scene, D3DVALUE(-1), D3DVALUE(0), D3DVALUE(0), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0) ); } else if (view==VIEWPORT_TOP) { camera->SetPosition( scene, D3DVALUE(0), D3DVALUE(50), D3DVALUE(0) ); camera->SetOrientation( scene, D3DVALUE(0), D3DVALUE(-1), D3DVALUE(0), D3DVALUE(0), D3DVALUE(0), D3DVALUE(1) ); } } The function uses the SetPosition() and SetOrientation() functions to place the frame. The position and orientation depend on the view parameter. The ConfigViewport() function is used both in the CreateDevice() function (as we have seen) and in the Viewport menu message handling functions (as you will see). The RMWin::CreateViewports() FunctionThe CreateViewports() function creates the demos three viewports: void RMWin::CreateViewports() { int newwidth = device->GetWidth(); int newheight = device->GetHeight(); int onethird=newwidth/3; int halfheight=newheight/2; d3drm->CreateViewport( device, camera1, 0, 0, onethird*2, newheight, &viewport1 ); d3drm->CreateViewport( device, camera2, onethird*2, 0, onethird, halfheight, &viewport2 ); d3drm->CreateViewport( device, camera3, onethird*2, halfheight, onethird, halfheight, &viewport3 ); } The function divides the space available on the device into three parts. The first viewport occupies the first two thirds of the device space, and the last two viewports share the remaining third. The viewports are each created with the Direct3DRM CreateViewport() function. The RMWin::Render() FunctionWeve discussed the code that creates and configures the demos scene and internal components. Now, we need to address what happens after initialization. An important issue is updating the scene and rendered output during the programs execution. In the other demos, this task is performed by the RMApp::OnIdle() function. The OnIdle() function for the regular demos look like this: BOOL RMApp::OnIdle(LONG count) { ASSERT( RMWin::d3drm ); ASSERT( rmwin ); rmwin->OnIdle( count ); RMWin::d3drm->Tick( D3DVALUE(1) ); return TRUE; } The Direct3DRM Tick() function is used to update the programs data and produce a new image based on the changes. This method works fine when you have only one viewport, but for our purposes, we need more control. The MultiView demo uses this version of RMApp::OnIdle(): BOOL RMApp::OnIdle(LONG lCount) { ASSERT( rmwin ); rmwin->Render(); return TRUE; } This version passes the responsibility of updating the program to the RMWin::Render() function, which looks like this: void RMWin::Render() { scene->Move( D3DVALUE(1.0) ); if (view1setting!=VIEWPORT_DISABLED) { viewport1->Clear(); viewport1->Render( scene ); } if (view2setting!=VIEWPORT_DISABLED) { viewport2->Clear(); viewport2->Render( scene ); } if (view3setting!=VIEWPORT_DISABLED) { viewport3->Clear(); viewport3->Render( scene ); } device->Update(); } Recall that the Direct3DRM Tick() function handles both updating the programs data and producing new visual output. Because we arent using the Tick() function, we have to handle this task ourselves. First, the Direct3DRMFrame Move() function is used to update the programs data. This function applies motion attributes and invokes callback functions for a frame hierarchy. We are using the scenes root frame (scene), so this function call ensures that the entire scene is updated. Next, we must produce new visual output. This is done with the Direct3DRMViewport Clear() and Render() functions. Unless the viewport is disabled, the Clear() function is used to reset the viewport, and the Render() function is used to produce new output. Although new visual output is produced with the Direct3DRMViewport Render() function, it is not visible yet. The Direct3DRMDevice Update() function is used to perform the actual display of the rendered output.
|
![]() |
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. |