将 3D 模型与 2D 视频合成需要更复杂的视图矩阵计算

发布于 2024-09-01 23:02:12 字数 287 浏览 4 评论 0原文

我正在利用一些 2d / 3d 跟踪数据(由 pfHoe 提供)来帮助将一些 3d 模型集成到播放一些二维视频。

一切正常......好吧......但是模型在视频背景下仍然存在一些明显的“滑动”,我怀疑这可能是因为 XNA CreatePerspective 辅助方法没有考虑一些附加数据由 pfHoe 提供,例如独立的水平/垂直视野角度和焦距。

有人能向我指出一些构建包含此类细节的视图矩阵的示例吗?

I'm utilising some 2d / 3d tracking data (provided by pfHoe) to help integrate some 3d models into the playback of some 2d video.

Things are working.... okay... but there's still some visible 'slipping' of the models against the video background and I suspect this is may be because the XNA CreatePerspective helper method isn't taking into account some of the additional data supplied by pfHoe such as independent horizontal / vertical field of view angles and focal length.

Would anyone be able to point me towards some examples of constructing view matrices that include such details?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伏妖词 2024-09-08 23:02:12

这篇 MSDN 文章向您展示了如何编写一种方法来创建独立考虑水平和垂直 FOV 的透视矩阵(尽管是在 C++ 中)
http://msdn.microsoft.com/en- us/library/bb147302%28VS.85%29.aspx

D3DXMATRIX 
ProjectionMatrix(const float near_plane, // Distance to near clipping 
                                         // plane
                 const float far_plane,  // Distance to far clipping 
                                         // plane
                 const float fov_horiz,  // Horizontal field of view 
                                         // angle, in radians
                 const float fov_vert)   // Vertical field of view 
                                         // angle, in radians
{
    float    h, w, Q;

    w = (float)1/tan(fov_horiz*0.5);  // 1/tan(x) == cot(x)
    h = (float)1/tan(fov_vert*0.5);   // 1/tan(x) == cot(x)
    Q = far_plane/(far_plane - near_plane);

    D3DXMATRIX ret;
    ZeroMemory(&ret, sizeof(ret));

    ret(0, 0) = w;
    ret(1, 1) = h;
    ret(2, 2) = Q;
    ret(3, 2) = -Q*near_plane;
    ret(2, 3) = 1;
    return ret;
}   // End of ProjectionMatrix

上面链接的文章中进一步解释了数学原理,以帮助您编写此方法的 C# 版本。祝你好运 :-)

This MSDN article shows you how to write a method which creates a perspective matrix that takes into account horizontal and vertical FOV independently (albeit, in C++)
http://msdn.microsoft.com/en-us/library/bb147302%28VS.85%29.aspx

D3DXMATRIX 
ProjectionMatrix(const float near_plane, // Distance to near clipping 
                                         // plane
                 const float far_plane,  // Distance to far clipping 
                                         // plane
                 const float fov_horiz,  // Horizontal field of view 
                                         // angle, in radians
                 const float fov_vert)   // Vertical field of view 
                                         // angle, in radians
{
    float    h, w, Q;

    w = (float)1/tan(fov_horiz*0.5);  // 1/tan(x) == cot(x)
    h = (float)1/tan(fov_vert*0.5);   // 1/tan(x) == cot(x)
    Q = far_plane/(far_plane - near_plane);

    D3DXMATRIX ret;
    ZeroMemory(&ret, sizeof(ret));

    ret(0, 0) = w;
    ret(1, 1) = h;
    ret(2, 2) = Q;
    ret(3, 2) = -Q*near_plane;
    ret(2, 3) = 1;
    return ret;
}   // End of ProjectionMatrix

The math is further explained in the article linked above to aid you in writing a C# version of this method. Good luck :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文