DisplaySurface.prototype.projectionMatrix = function(eye, znear, zfar){
var mat = new Mat4();
mat.loadIdentity();
var br = new Vec3.add(this.u, this.origin),
tl = new Vec3.add(this.v, this.origin);
var bre = new Vec3.subtract(br, eye),
tle = new Vec3.subtract(tl, eye);
var u = this.u.normalize(),
v = this.v.normalize(),
n = this.n.normalize(),
eyedist = Vec3.dot(bre, n);
var l = Vec3.dot(tle, u)*znear/eyedist,
r = Vec3.dot(bre, u)*znear/eyedist,
b = Vec3.dot(bre, v)*znear/eyedist,
t = Vec3.dot(tle, v)*znear/eyedist;
console.log(r-l);
mat.frustum(l, r, b, t, znear, zfar);
console.log(mat);
return mat;
};
Mat4.prototype.frustum = function(left, right, bottom, top, near, far){
var a = this._;
var n2 = 2.0*near,
diffX = right - left,
diffY = top - bottom,
diffZ = far - near;
a[0] = n2/diffX;
a[1] = 0;
a[2] = 0;
a[3] = 0;
a[4] = 0;
a[5] = n2/diffY;
a[6] = 0;
a[7] = 0;
a[8] = (right + left) / diffX;
a[9] = (top + bottom) / diffY;
a[10] = -(far + near) / diffZ;
a[11] = -1.0;
a[12] = 0.0;
a[13] = 0.0;
a[14] = -(n2 * far) / diffZ;
a[15] = 0.0;
};
What I have tried:
So... this is supposed to return a projection matrix. Everything runs smoothly on the firts frame, then I start getting weird results. I never worked with javascript, and I have been trying for a while to figure it out - the only clue I got is that (l-r) seems to be producing the strange results, though (l) by itself is fine.
@Edit. Yeah, t and r are the problem. Though why? :(