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; テスト = ToScreenSpace(テスト);
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 に配置されると、2 倍の量のスクリーン スペース座標が提供されることです。
つまり、ToScreenSpace がテキストを 3D スペース 50,0,50 に正しく配置するには、テキストに値 25,0,25 を与える必要があります。90,10,70? 45、5、35など
なぜこのようなことが起こるのか、私はただ疑問に思っています。