从 3D 到 2D 的平滑过渡

发布于 2024-09-28 16:05:58 字数 792 浏览 4 评论 0原文

我正在编写自己的 3D 引擎,并且我有这个矩阵来制作透视图。 (这是一个标准矩阵,所以没有什么有趣的)

public static Matrix3D PrespectiveFromHV(double fieldOfViewY, double aspectRatio, double zNearPlane, double zFarPlane, double mod)
    {
        double height = 1.0 / Math.Tan(fieldOfViewY / 2.0);
        double width = height / aspectRatio;
        double d = zNearPlane - zFarPlane;

        var rm = Math.Round(mod, 1);

        var m = new Matrix3D(
                width, 0, 0, 0,
                0, height, 0, 0,
                0, 0, (zFarPlane / d) * rm, (zNearPlane * zFarPlane / d) * rm,
                0, 0, (-1 * rm), (1 - rm)
            );

        return m;
    }

我可以通过忽略该矩阵使我的场景看起来像 2D 一样。

但想要做的是从 3D 到 2D 平滑过渡并返回...

有人有什么想法吗?我必须对此矩阵进行哪些更改才能实现平滑过渡?

I'm writing my own 3D engine and I have this matrix to make a perspective look. (It's a standard matrix so there is nothing interesting)

public static Matrix3D PrespectiveFromHV(double fieldOfViewY, double aspectRatio, double zNearPlane, double zFarPlane, double mod)
    {
        double height = 1.0 / Math.Tan(fieldOfViewY / 2.0);
        double width = height / aspectRatio;
        double d = zNearPlane - zFarPlane;

        var rm = Math.Round(mod, 1);

        var m = new Matrix3D(
                width, 0, 0, 0,
                0, height, 0, 0,
                0, 0, (zFarPlane / d) * rm, (zNearPlane * zFarPlane / d) * rm,
                0, 0, (-1 * rm), (1 - rm)
            );

        return m;
    }

I could make my scene look 2D like just by ignoring that matrix.

But want to do is to make smooth transition from 3D to 2D and back...

Any one have any idea? What do I have to change in this matrix to make smooth transitions possible?

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

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

发布评论

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

评论(2

め可乐爱微笑 2024-10-05 16:05:58

我会在 m 和缩进矩阵 I 之间使用插值,如下所示:

Let alpha go from 1 to 0 in alpha*m+(1-alpha)*I

编辑:

请详细说明

我可以让我的场景看起来像 2D
只需忽略该矩阵即可。

这个想法是在 2D(通过忽略矩阵)和 3D(使用矩阵)之间进行插值。如果你解释一下你到底是如何忽略矩阵的,那么插值应该是直接的。

I would use interpolation between m and the indentity matrix I, like so:

Let alpha go from 1 to 0 in alpha*m+(1-alpha)*I

EDIT:

could you please elaborate on

I could make my scene look 2D like
just by ignoring that matrix.

The idea is to intpolate between 2D (by ignoring the matrix) and 3D (using the matrix). If you explain how exactly you ignore the matrix, the interpolation should be straigtforward.

≈。彩虹 2024-10-05 16:05:58

好吧..为了忽略“预见”矩阵,我做了两件事......首先,我忽略矩阵计算中的预见矩阵


变量矩阵=
Matrix3DHelper.RotateByDegrees(renderParams.AngleX, renderParams.AngleY, renderParams.AngleZ) *
透视矩阵;

我只是不使用perspectiveMatrix...

第二步..当progeectin指向屏幕时我忽略'W'参数


私有 Point3D GetTransformedPoint(Point3D p, Matrix3D m)
{
双 w = (((m.M41 * pX) + (m.M42 * pY)) + (m.M43 * pZ)) + m.M44;
双 x = ((((m.M11 * pX) + (m.M12 * pY)) + (m.M13 * pZ)) + m.M14) / (w);
双 y = ((((m.M21 * pX) + (m.M22 * pY)) + (m.M23 * pZ)) + m.M24) / (w);
双 z = (((m.M31 * pX) + (m.M32 * pY)) + (m.M33 * pZ)) + m.M34;
返回新的 Point3D(x, y, z, w);
}

Well.. to ignore "prespective" matrix i do two things... first of all i ignore prespective matrix in matrix callculation


var matrix =
Matrix3DHelper.RotateByDegrees(renderParams.AngleX, renderParams.AngleY, renderParams.AngleZ) *
perspectiveMaterix;

i just don't use perspectiveMatrix...

and second step.. i ignore 'W' parameter when progectin point to the screen


private Point3D GetTransformedPoint(Point3D p, Matrix3D m)
{
double w = (((m.M41 * p.X) + (m.M42 * p.Y)) + (m.M43 * p.Z)) + m.M44;
double x = ((((m.M11 * p.X) + (m.M12 * p.Y)) + (m.M13 * p.Z)) + m.M14) / (w);
double y = ((((m.M21 * p.X) + (m.M22 * p.Y)) + (m.M23 * p.Z)) + m.M24) / (w);
double z = (((m.M31 * p.X) + (m.M32 * p.Y)) + (m.M33 * p.Z)) + m.M34;
return new Point3D(x, y, z, w);
}

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