How do you create an off-center PerspectiveCamera in WPF?

喜欢而已 提交于 2019-12-05 17:33:45
Jonathan Schuster

I never did find a built-in way to do this, so I wrote my own. The math behind it can be found in the OpenGL glFrustum docs. If anyone else ever runs into this problem, this should work for you:

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);
}

Just set MatrixCamera.ProjectionMatrix to the return value of that method, and you're all set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!