Smooth transition from 3D to 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 * zFarPla开发者_如何学运维ne / 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?
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.
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);
}
精彩评论