2013-06-18 3 views
1

Я изучаю DirectX (DirectX 9) с сайта www.directxtutorial.com и используя visual studio 2012 в Windows 8. d3dx9 (d3dx) заменить другим заголовком, как DirectXMath, поэтому я заменил все, что необходимо, но есть проблема - конвертировать XMMATRIX в D3DMATRIX.Как преобразовать XMMATRIX в D3DMATRIX в DirectX 9?

Код задачи (! Проблема написано -/проблема /):

void render_frame(void) { 
// clear the window to a deep blue 
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); 

d3ddev->BeginScene(); // begins the 3D scene 

// select which vertex format we are using 
d3ddev->SetFVF(CUSTOMFVF); 

// SET UP THE PIPELINE 

DirectX::XMMATRIX matRotateY; // a matrix to store the rotation information 

static float index = 0.0f; index+=0.05f; // an ever-increasing float value 

// build a matrix to rotate the model based on the increasing float value 
matRotateY = DirectX::XMMatrixRotationY(index); 

D3DMATRIX D3DMatRotateY = matRotateY.r; 

// tell Direct3D about our matrix 
d3ddev->SetTransform(D3DTS_WORLD, &matRotateY); /*problem!*/ 

DirectX::XMMATRIX matView; // the view transform matrix 

DirectX::XMVECTOR CameraPosition = {0.0f,0.0f,10.0f}; 
DirectX::XMVECTOR LookAtPosition = {0.0f,0.0f,0.0f}; 
DirectX::XMVECTOR TheUpDirection = {0.0f,1.0f,0.0f}; 

matView = DirectX::XMMatrixLookAtLH(CameraPosition, // the camera position 
    LookAtPosition, // the look-at position 
    TheUpDirection); // the up direction 

d3ddev->SetTransform(D3DTS_VIEW, &matView); /*problem!*/ // set the view transform to matView 

DirectX::XMMATRIX matProjection;  // the projection transform matrix 

DirectX::XMMatrixPerspectiveFovLH(&matProjection, 
    DirectX::XMConvertToRadians(45), // the horizontal field of view 
          1.0f, // the near view-plane 
          100.0f); // the far view-plane 

d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection); /*problem!*/ // set the projection 

// select the vertex buffer to display 
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); 

// copy the vertex buffer to the back buffer 
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); 

d3ddev->EndScene(); // ends the 3D scene 

d3ddev->Present(NULL, NULL, NULL, NULL); /* displays the created frame on the screen */ } 

ответ

1

Вы можете использовать XMStoreFloat4x4 для преобразования XMMATRIX в XMFLOAT4X4.

Вы должны быть в состоянии передать XMFLOAT4X4 в setTransform путем литья.

DirectX::XMMATRIX matProjection;   
DirectX::XMFLOAT4X4 projectionMatrix; 
DirectX::XMMatrixPerspectiveFovLH(&matProjection,DirectX::XMConvertToRadians(45),1.0f,100.0f); 
XMStoreFloat4x4(&projectionMatrix, matProjection); 
d3ddev->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&projectionMatrix);  /*problem!*/   // set the projection 
+0

Я должен преобразовать в D3DMATRIX для SetTransform. – arlu

+0

Добавлен пример кода, iirc вы можете использовать 'XMFLOAT4X4' для' D3DXMATRIX' –