# Where is the error in my perspective projection implementation?

My question is not really a game development question, but since it's based on 3D programming, I thought it would fit best here.

I've got a line made out of Point3D objects where the value of x, y, and z are somewhere in those regions:

x: 0 - 640
y: 0 - 480
z: 0 - 4000


I'd like to project those lines into a plane with the size of 640 * 480 (the same size as the base x * y values were) using a oerspective projection. I found some information about the matrix I should use in an old computer graphics script (there are a lot of different matrixes around the net too), but could not get it to work.

Based on this tutorial, I'm using the following parameters:

float n = 1000; // near plane
float f = 4000; // far plane
float l = 0;    // left side
float r = 640;  // right side
float b = 480;  // bottom
float t = 0;    // top

float m11 = (2 * n) / (r - l);
float m22 = (2 * n) / (t - b);
float m31 = (r + l) / (r - l);
float m32 = (t + b) / (t - b);
float m33 = (-1 * (f + n)) / (f - n);
float m43 = (-2 * f * n) / (f - n);
float m34 = (-2 * f * n) / (f - n);

m = new Matrix3D(m11,   0,   0,   0,
0, m22,   0,   0,
m31, m32, m33,  -1,
0,   0, m43,   0);


Now all the result-points I receive from doing a m.Transform(myPoint3D) are in ranges like:

x = -1,015 to -1,694
y = 1,568 to 1,572


In my understanding those values should be in ranges from -1 to 1, and I would scale them to fit into my plane, but those results look totally chaotic... Also, the resulting z-values aren't "flat" but ranging from 2.903 to 2.996.

Any ideas where my error is?

xy = xy * 0.5 + 0.5;