如何转换XMMATRIX到D3DMATRIX在DirectX 9? [英] how to convert XMMATRIX to D3DMATRIX in DirectX 9?

查看:772
本文介绍了如何转换XMMATRIX到D3DMATRIX在DirectX 9?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从www.directxtutorial.com学习DirectX(DirectX 9),并在Windows 8中使用visual studio 2012。
d3dx9(d3dx)替换为其他标题,如DirectXMath,因此我替换了所有需要的,但是是一个问题 - 将XMMATRIX转换为D3DMATRIX。

I learn DirectX (DirectX 9) from www.directxtutorial.com and using visual studio 2012 in windows 8. d3dx9 (d3dx) replace by other header like DirectXMath, therefore I replaced all that is needed, but there is a problem - convert XMMATRIX to D3DMATRIX.

问题代码(编写的问题 - / 问题! b
$ b

The problem code (The problem written - /problem!/):

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 */ }


推荐答案

您可以使用 XMStoreFloat4x4 XMMATRIX 转换为 XMFLOAT4X4

You can use XMStoreFloat4x4 to convert XMMATRIX to a XMFLOAT4X4.

您应该能够通过转换将XMFLOAT4X4传递给setTransform。

You should be able to pass in XMFLOAT4X4 to setTransform by casting.

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

这篇关于如何转换XMMATRIX到D3DMATRIX在DirectX 9?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆