【问题标题】:How do you create an off-center PerspectiveCamera in WPF?如何在 WPF 中创建一个偏心的 PerspectiveCamera?
【发布时间】:2018-02-03 12:21:57
【问题描述】:

我正在尝试或多或少地重新创建 Johnny Lee's Wii head tracking app,但使用增强现实工具包进行跟踪,并使用 WPF 进行图形。为此,我需要使用顶部、底部、右侧和左侧参数来创建透视相机,而不是视野和纵横比(对于熟悉 OpenGL 的人,我想使用 WPF 等效项) glFrustum 而不是 gluPerspective)

问题是,这些选项在 WPF 的 PerspectiveCamera 类上似乎不可用。如果必须使用 MatrixCamera,我可能可以手动创建投影矩阵,但我想避免这种情况。有谁知道更好的方法吗?

【问题讨论】:

  • “更好”是什么意思?
  • 我的意思是一些可以为我做数学的方法,而不是像我在下面的答案中那样强迫我这样做。

标签: wpf opengl graphics augmented-reality


【解决方案1】:

我从来没有找到内置的方法来做到这一点,所以我自己写了。 The math behind it can be found in the OpenGL glFrustum docs。如果其他人遇到这个问题,这应该对你有用:

public Matrix3D CreateFrustumMatrix(double left, double right, double bottom, double top, double near, double far)
{
    var a = (right + left) / (right - left);
    var b = (top + bottom) / (top - bottom);
    var c = -(far + near) / (far - near);
    var d = -2 * far * near / (far - near);

    return new Matrix3D(
        2 * near / (right - left), 0,                         0, 0,
        0,                         2 * near / (top - bottom), 0, 0,
        a,                         b,                         c, -1,
        0,                         0,                         d, 0);
}

只需将 MatrixCamera.ProjectionMatrix 设置为该方法的返回值,一切就绪。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2022-07-19
    相关资源
    最近更新 更多