简体   繁体   中英

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 * 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?

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 * pX) + (m.M42 * pY)) + (m.M43 * pZ)) + m.M44;
double x = ((((m.M11 * pX) + (m.M12 * pY)) + (m.M13 * pZ)) + m.M14) / (w);
double y = ((((m.M21 * pX) + (m.M22 * pY)) + (m.M23 * pZ)) + m.M24) / (w);
double z = (((m.M31 * pX) + (m.M32 * pY)) + (m.M33 * pZ)) + m.M34;
return new Point3D(x, y, z, w);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM