![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The MeshPickWin::PickMesh() FunctionAs we saw in the OnLButtonDown() function, the PickMesh() function is used to check if an object has been selected: BOOL MeshPickWin::PickMesh( const CPoint& point ) { HRESULT r; LPDIRECT3DRMPICKEDARRAY pickarray; viewport->Pick( point.x, point.y, &pickarray ); BOOL ret=FALSE; DWORD numpicks=pickarray->GetSize(); if (numpicks>0) { LPDIRECT3DRMVISUAL visual; LPDIRECT3DRMFRAMEARRAY framearray; D3DRMPICKDESC pickdesc; r=pickarray->GetPick( 0, &visual, &framearray, &pickdesc ); if (r==D3DRM_OK) { framearray->GetElement( framearray->GetSize()-1, &drag.frame ); D3DVECTOR pos; drag.frame->GetPosition( 0, &pos ); drag.origx=pos.x; drag.origy=pos.y; drag.mousedown.x=point.x; drag.mousedown.y=point.y; visual->Release(); framearray->Release(); ret=TRUE; } } pickarray->Release(); return ret; } The first step that the MeshPick() function performs is calling the Direct3DRMViewport Pick() function. The Pick() function takes three arguments. The first two arguments indicate the location within the viewport that is to be checked. The third argument is a pointer to the Direct3DRMPickedArray interface. This pointer is initialized with an array of objects that appear at the given viewport location (even if the objects are completely hidden by other objects). The Direct3DRMPickedArray interface supports two member functions: GetSize() and GetPick(). The GetSize() member returns the number of elements in the array. The GetPick() function retrieves a pointer to the visual object that was picked and a pointer to an array from Direct3DRMFrame pointers. The array of frames retrieved by the GetPick() function is a list of all of the selected objects frames, starting with the root frame. The last frame in the array is the frame to which the object is attached. We retrieve this array and use the GetElement() function to retrieve a pointer to the last frame in the array. Once it has been determined that a new drag operation is to be initiated, the members of the DragData structure are assigned. The drag.frame member is used to store a pointer to the frame that is to be moved by the drag operation. The frames position and the mouse click coordinate are also stored. This data will be required later when we are calculating new positions for the frame based on mouse movement. Once the drag structure has been prepared, the pointers to the various interfaces are released. The MeshPick() function returns TRUE if an object has been picked. The MeshPickWin::UpdateDrag() FunctionThe UpdateDrag() function is a callback function that is installed by the CreateScene() function. Well use it to poll the status of the application and to relocate meshes when a drag operation is underway. void MeshPickWin::UpdateDrag(LPDIRECT3DRMFRAME frame, void*, D3DVALUE) { if (drag.frame) { int x=GetMouseX(); int y=GetMouseY(); D3DVALUE newx= -D3DVALUE(drag.mousedown.x-x)*D3DVALUE(.07)+drag.origx; D3DVALUE newy= D3DVALUE(drag.mousedown.y-y)*D3DVALUE(.07)+drag.origy; drag.frame->SetPosition( 0, newx, newy, D3DVALUE(0) ); } } The UpdateDrag() function checks the drag.frame member function to determine if a frame (and the object that is attached to the frame) is being dragged. If so, the GetMouseX() and GetMouseY() functions are used to retrieve the current mouse position (the GetMouseX() and GetMouseY() functions are inherited from the RMWin class). A new location for the frame is calculated based on the current location of the mouse, the location of the mouse when the drag sequence started, and the frames original location. The frame is repositioned with the Direct3DRMFrame SetPosition() 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. |