【发布时间】:2012-07-30 00:59:25
【问题描述】:
我只是在编写一些代码来测试 D3DXVec3Project 函数,试图让它将文本与 3d 位置对齐。
3D转2D码:
D3DXVECTOR3 ToScreenSpace(D3DXVECTOR3 position)
{
D3DXVECTOR3 out;
D3DVIEWPORT9 view;
D3DXMATRIX matView;
D3DXMATRIX matWorld;
D3DXMATRIX matProj;
D3DXMATRIX worldPos;
D3DXMATRIX worldRotX;
D3DXMATRIX worldRotY;
D3DXMATRIX worldRotZ;
D3DXMATRIX worldScl;
graphicsDevice->GetViewport(&view); //view in debug is showing all the correct values.
graphicsDevice->GetTransform(D3DTS_VIEW, &matView); //view is set each frame from the camera
graphicsDevice->GetTransform(D3DTS_PROJECTION, &matProj); //this is set once in the scene manager
D3DXMatrixTranslation(&matWorld, position.x, position.y, position.z); //uses the given position for the world matrix
D3DXVec3Project(&out, &position, &view, &matProj, &matView, &matWorld);
return out;
}
测试代码: D3DXVECTOR3 测试; 测试.x = 90; 测试.y = 0; 测试.z = 70; test = ToScreenSpace(test);
RECT rct;
rct.left = test.x;
rct.right=test.x + 650;
rct.top = test.y;
rct.bottom=rct.top + 20;
m_font->DrawText(NULL, L"Hello World", -1, &rct, 0, fontColor );
问题是无论放在 test.xyz 中的任何值都会提供两倍数量的屏幕空间坐标。
即为了让 ToScreenSpace 将文本正确对齐到 3D 空间 50,0,50,我需要为文本提供值 25,0,25。 90,10,70? 45、5、35等
我只是想知道为什么会这样。
【问题讨论】:
标签: c++ directx transform viewport