【发布时间】:2009-08-03 13:24:30
【问题描述】:
好吧 - 看来我的问题和我的头脑一样模糊。让我们再试一次。
在为 D3D 设备配置视口时,我有 3 个属性: - 设备运行的分辨率(全屏)。 - 显示器的物理纵横比(分数和浮点数:1,例如 4:3 和 1.33)。 - 源分辨率的纵横比(源分辨率本身没有实际意义,它只告诉我们渲染所需的纵横比和理想运行的分辨率类型)。
然后我们遇到这个:
// -- figure out aspect ratio adjusted VPs --
m_nativeVP.Width = xRes;
m_nativeVP.Height = yRes;
m_nativeVP.X = 0;
m_nativeVP.Y = 0;
m_nativeVP.MaxZ = 1.f;
m_nativeVP.MinZ = 0.f;
FIX_ME // this does not cover all bases -- fix!
uint xResAdj, yResAdj;
if (g_displayAspectRatio.Get() < g_renderAspectRatio.Get())
{
xResAdj = xRes;
yResAdj = (uint) ((float) xRes / g_renderAspectRatio.Get());
}
else if (g_displayAspectRatio.Get() > g_renderAspectRatio.Get())
{
xResAdj = (uint) ((float) yRes * g_renderAspectRatio.Get());
yResAdj = yRes;
}
else // ==
{
xResAdj = xRes;
yResAdj = yRes;
}
m_fullVP.Width = xResAdj;
m_fullVP.Height = yResAdj;
m_fullVP.X = (xRes - xResAdj) >> 1;
m_fullVP.Y = (yRes - yResAdj) >> 1;
m_fullVP.MaxZ = 1.f;
m_fullVP.MinZ = 0.f;
现在只要 g_displayAspectRatio 等于 xRes/yRes 的比率(= 适应设备分辨率),一切都很好,这段代码将完成预期的工作。但是一旦这两个值不再相关(例如,有人在 16:10 的屏幕上运行 4:3 的分辨率,硬件拉伸),就需要另一个步骤来补偿,我很难弄清楚到底如何.
(并且 p.s 我在原子类型上使用 C 风格的强制转换,并接受它 :-))
【问题讨论】:
-
我不明白你到底想做什么。
标签: c++ math graphics aspect-ratio direct3d