tags:

views:

120

answers:

2

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?

+1  A: 

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.

Peter G.
Nope.. not work at all.. you "algoritm" work fine when alpha is 1... but for other values i get pretty messed up picture...
Ai_boy
Interpolation is the way to go here. You basically want to be changing the about of "scaling by depth" that is applied until you are no longer scaling things at all.
thecoshman
You need an orthographic projection, rather than the identity.
Courtney de Lautour
NOPE! I used orthographic and that's have no effect... i get 2D projection only! when i get 0.. there is no smoth translation
Ai_boy
A: 

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

Ai_boy
by igoring 'w' param i mean that i set 'w' to 1 as constant...
Ai_boy