这个想法是在显示我的DiretXTK模型后将边界框绘制为屏幕上的 2D 角。
我从 DirectXKT 中得到了边界框角std::vector<DirectX::SimpleMath::Vector3>
,所以
auto mf = m_world * m_view * m_proj;
D3D11_VIEWPORT vp;
UINT j = 1;
ctx->RSGetViewports(&j,&vp);
for (auto& c : corners)
{
DirectX::SimpleMath::Vector3 ft = DirectX::XMVector3Transform(c, mf);
float scalex = vp.Width / 2;
float scaley = vp.Height / 2;
float screenx = ft.x * scalex;
float screeny = ft.y * scaley;
}
这些坐标无效,我在将每个角的 XYZ 转换为屏幕投影时做错了。
非常感谢你的帮助。