如何在DirectX 9中设置左上角坐标

How to set top-left coordinates in DirectX 9?

本文关键字:设置 左上角 坐标 DirectX      更新时间:2023-10-16

我需要在DirectX 9中画一些东西。我有兴趣以一种将坐标调整为像素的方式工作,而(0,0)将是TopLeft角。我是这样做的:

RECT clientRect;
::GetClientRect(m_hWIN, &clientRect);
D3DXMATRIX matOrtho2D, matIdentity;    
D3DXMatrixOrthoOffCenterLH(&matOrtho2D, 0, clientRect.right, 0, clientRect.bottom, 0.0f, 1.0f);
D3DXMatrixIdentity(&matIdentity);
g_pDirect3D_Device->SetTransform(D3DTS_PROJECTION, &matOrtho2D);
g_pDirect3D_Device->SetTransform(D3DTS_WORLD, &matIdentity);
g_pDirect3D_Device->SetTransform(D3DTS_VIEW, &matIdentity);

这很好,除了(0,0)是BottomLeft角。我怎样才能改变呢?谢谢!

应该添加到代码中:

D3DXMATRIX matTranslate, matFlip;  
D3DXMatrixTranslation(&matTranslate, 0, clientRect.bottom, 0.0f);
D3DXMatrixRotationX(&matFlip, D3DXToRadian(180));
D3DXMATRIX matCoordTransform = matFlip * matTranslate;
g_pDirect3D_Device->SetTransform(D3DTS_WORLD, &matCoordTransform);