[ Pobierz całość w formacie PDF ] .0;aMatrix[0][1] = (D3DVALUE) 0.0;aMatrix[0][2] = (D3DVALUE) 0.0;aMatrix[0][3] = (D3DVALUE) 0.0;aMatrix[1][0] = (D3DVALUE) 0.0;aMatrix[1][1] = (D3DVALUE) 1.0;aMatrix[1][2] = (D3DVALUE) 0.0;aMatrix[1][3] = (D3DVALUE) 0.0;aMatrix[2][0] = (D3DVALUE) 0.0;aMatrix[2][1] = (D3DVALUE) 0.0;aMatrix[2][2] = (D3DVALUE) 1.0;aMatrix[2][3] = (D3DVALUE) 0.0;aMatrix[3][0] = (D3DVALUE) 0.0;aMatrix[3][1] = (D3DVALUE) 0.0;aMatrix[3][2] = (D3DVALUE) 0.0;aMatrix[3][3] = (D3DVALUE) 1.0;return;}The local transformA retained mode frame is located and oriented by a 4 X 4 matrix located in the frame object itself.In this sense the terms local or model coordinates refer to the points in 3D space that define themodeled object.Consistently, the matrix associated with each frame is sometimes called the localtransform.The default state of the local transform for a frame is the identity matrix.Applicationscan obtain the 4 X 4 affine matrix that is the local transform matrix for a frame by means of theGetTransform() function of IDirect3DRMFrame3.The function has the following generalform:HRESULT GetTransform(LPDIRECT3DRMFRAME lpRefFrame, // 1D3DRMMATRIX4D rmMatrix // 2);The first parameter designates the frame that serves as the root of the scene.If this argument isNULL, the current root frame is used.The second parameter is an array of type D3DRMMATRIX4Dthat receives the frame's local transform.The function returns DD_OK if it succeeds.Applying frame-level transformationsSeveral retained mode functions serve to simplify and implement matrix transfor-mations.Themost general one is named AddTransform().The AddTransform() function applies theframe's local transform matrix to the coordinates of each point of the object contained in the frame.The result is a general transformation.The function's general form is as follows:HRESULT AddTransform(D3DRMCOMBINETYPE rctCombine, // 1D3DRMMATRIX4D rmMatrix // 2);The first parameter is one of the members of the D3DRMCOMBINETYPE enumeration describedpreviously in this chapter.This determines how to combine the new transformation with anypreviously existing one.The second parameter is an array of type D3DRMMATRIX4D that definesthe transformation matrix to be combined.The function returns D3DRM_OK if it succeeds, or anerror otherwise.Note that for the transformation to preserve its affine property the last column of the matrix passedin the call must contain the values:Application code should carefully preserve this matrix column.Transformation can be applied tothe frame at any point in the code, although the results are not visible until the frame is rendered.The following code fragment shows the processing operations required for performing an x- and y-axis translation using the AddTranslate() function.// Translation matrix for x- and y-axisD3DRMMATRIX4D transXY ={ D3DVAL(1), 0, 0, 0,0, D3DVAL(1), 0, 0,0, 0, D3DVAL(1), 0,D3DVAL(0.5), D3DVAL(0.5), 0, D3DVAL(1)};.FrameTransform(transXY);.//***************************************************// name: FrameTransform()// desc: Applies a transformation matrix to the// frame//***************************************************BOOL FrameTransform(){// Add translationif(xTrans + yTrans + zTrans != 0){retval = childframe->AddTranslation(CTTrans,D3DVAL(xTrans), // AxesD3DVAL(yTrans),D3DVAL(zTrans));if(FAILED(retval)){RMError(retval);return FALSE;}}return TRUE;}3DRM Matrix Ops Demo projectThe project named 3DRM Matrix Ops Demo, in the book's CD-ROM, shows the action of theAddRotation(), AddTranslation(), and AddScale() functions and also illustrates matrixtransformations.The program is intended as a minimal laboratory for experimenting with frame-level movements and matrix-based transformations.All transformations are applied to the sceneframe.As the program executes it displays a modeless dialog box that contains the patterns forthe matrices used in translation, scaling, and rotation transformations listed previously in thischapter.In addition, code reads and displays the current local transform.Figure 19-5 is a screensnapshot of the initial program display.Figure 19-5: Initial screen of the 3DRM Matrix Ops Demo programNotice in Figure 19-5 that the initial value for the local transform is the identity matrix.For thisreason no change takes place in the frame object if the unmodified local transform is applied.Figure 19-5 also shows the program's main menu, which contains commands to execute some ofthe movements and transformation functions discussed in this chapter.The first three menucommands allow executing the AddRotation(), AddTranslation(), and AddScaling()functions of IDirect3D_RMFrame3.Figure 19-6 shows the dialog boxes for each of these menucommands.Figure 19-6: Dialog boxes for the first three commands in the 3DRM Matrix Ops Demo programAll three dialogs contain check boxes for selecting the axes on which the transformations areperformed.They also contain radio buttons for selecting the combine type to be applied in thetransformation.Consistently with the functions themselves, the Add Rotation Setup dialog boxscaling transformations enable the user to select a positive or negative value for each axis.Thisvalue determines the amount of transformations applied in each case.As the transformations areapplied, the resulting local transform is shown in the program's Matrix Tranformations window.The Add Transform command in the program's Operations menu allows applying an arbitrarytransformation defined by the user.The command displays the dialog box shown in Figure 19-7.Figure 19-7: Add Transform dialog in the 3DRM Matrix Ops Demo programWhen the Add Transform command executes the dialog box displays the values in the currentlocal transform.The edit boxes allow entering new values in the matrix.The entries for therightmost matrix columns are grayed to ensure that the result-ing transformation preserves theaffine characteristic.The button labeled Make Identity Matrix is used to change the matrix to theidentity form, that is, with 1s in the main diagonal and 0s everywhere else.The button labled Applycloses the dialog box and produces the transformation.The one labeled Cancel closes the dialogbox restoring the previous local transform.Here again, the user can select the combine type usedin the call to the AddTransform() function
[ Pobierz całość w formacie PDF ] zanotowane.pldoc.pisz.plpdf.pisz.plmikr.xlx.pl
|