从 3D 到 2D 的平滑过渡
我正在编写自己的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会在 m 和缩进矩阵 I 之间使用插值,如下所示:
Let alpha go from 1 to 0 in alpha*m+(1-alpha)*I
编辑:
请详细说明
这个想法是在 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
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.
好吧..为了忽略“预见”矩阵,我做了两件事......首先,我忽略矩阵计算中的预见矩阵
变量矩阵=
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);
}