I eventually, figured out a way to do this here's what I've written about this subject on my youtube channel:
Basically the idea with perspective projection
your clipping and or attaching the znear and or zfar plane on the x (width), y (height) and z (depth) axis with the clipping (perspective boundary) and perspective volume (perspective shape which is kinda like a 3D weird cube with a pyramid at the top) which is helped by the distance between zfar and znear planes but the equations are weird and confusing.
- translation = positioning
- transforms = various kinds of visual transformations
(rotation,size,etc)
First lets understand the matrix :
var matrix = [
xx, xy, xz, xw,
yx, yy, yz, yw,
zx , zy, zz, zw,
wx, wy, wz, ww
];
x(anything) is for width and any other transform including projection.
y(anything) is for height and any other transform including
projection.
z(anything) is for depth (not perspective) and any other
transform including projection.
w is for perspective (growing and shrinking geometry) and any
other transforms including projection
any combination of xyzw are just obvious xy will work on width of height or yz will work on the depth of height, I think, etc.
Now depending on if it's in row or column order.
will determine which w's are used for translation
in this case for WebGL row is
var matrix = [
xx, xy, xz, xw,
yx, yy, yz, yw,
zx , zy, zz, zw,
(wx, wy, wz, ww)
];
if it was column then it would be
var matrix = [
xx, xy, xz, (xw,
yx, yy, yz, yw,
zx , zy, zz, zw,
wx, wy, wz, ww)
];
To create the actual plane you use variables
float top = 1.0,
bottom = -1.0
left = -1.0
right = 1.0
These are all the variable declarations:
var top = 1.0; // top of cube
var bottom = -1.0; // bottom of cube
var zfar = -2.0; // distance of furthest boundary of perspective shape
var znear = 4.0; // distance of closest boundary of perspective shape
var width = 1.0; // width of cube
var height = 1.0; // height of cube
var left = -1.0; // left side of cube
var right = 1.0; // right side of cube
var zoomfactor = 2.0; // amount zoomed in and out
The cube formation is a consequence of creating a plane with these equations (I think) and the pyramid part and perspective projection is all in these equations also zfar and znear equations are here too:
var PersMat = [
//ROW 1
znear / width / 4.0 * zoomfactor, 0.0, left+right/width/2, 0.0,
//ROW 2
0.0, znear / height / 4.0 * zoomfactor , top+bottom/height/2, 0.0,
//ROW 3
0.0, 0.0, - (zfar + znear) / (zfar - znear), 2*zfar*znear / zfar - znear,
// ROW 4
0.0, 0.0, -1.0, 0.0
];
Hope that helps.