Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function (orig, dir, edge1, edge2, v1, vertInter) {
// moller trumbore intersection algorithm
vec3.cross(pvec, dir, edge2);
var det = vec3.dot(edge1, pvec);
if (det > -EPSILON && det < EPSILON)
return -1.0;
var invDet = 1.0 / det;
vec3.sub(tvec, orig, v1);
var u = vec3.dot(tvec, pvec) * invDet;
if (u < ZERO_MINUS_EPSILON || u > ONE_PLUS_EPSILON)
return -1.0;
vec3.cross(qvec, tvec, edge1);
var v = vec3.dot(dir, qvec) * invDet;
if (v < ZERO_MINUS_EPSILON || u + v > ONE_PLUS_EPSILON)
return -1.0;
var t = vec3.dot(edge2, qvec) * invDet;
if (t < ZERO_MINUS_EPSILON)
return -1.0;
if (vertInter)
let theta = degToRad(this.vfov); // vfov is top to bottom in degs
let halfHeight = Math.tan(theta/2.);
let halfWidth = this.aspect * halfHeight;
/*
* calc camera basis
*/
// vec3 w = normalize(this.lookFrom - this.lookAt);
this.w = vec3.create();
vec3.sub(this.w, this.lookFrom, this.lookAt);
this.w = vec3.normalize(this.w, this.w);
// vec3 u = normalize(cross(vUp, w));
this.u = vec3.create();
vec3.cross(this.u, this.vUp, this.w);
vec3.normalize(this.u, this.u);
// vec3 v = cross(w, u);
this.v = vec3.create();
vec3.cross(this.v, this.w, this.u);
/*
* adjust basis to aspect, focus distance and get starting pos (lowerLeft)
*/
this.lowerLeft = vec3.create();
vec3.sub(
this.lowerLeft,
this.lookFrom,
vec3.scale(vec3.create(), this.u, halfWidth*this.focusDist)
function getUp(out, front, right) {
vec3.cross(out, right, front);
}
realign() {
vec3.cross(this.right, this.forward, this.up);
vec3.cross(this.up, this.right, this.forward);
vec3.normalize(this.forward, this.forward);
vec3.normalize(this.right, this.right);
vec3.normalize(this.up, this.up);
}
tempAxis[2] += 1;
}
vec3.transformMat4(tempAxis, tempAxis, node.matrix);
vec3.sub(tempAxis, tempAxis, tempTransformedPivotPoint);
vec3.set(tempXAxis, 1, 0, 0);
vec3.add(tempXAxis, tempXAxis, node.node.PivotPoint as vec3);
vec3.transformMat4(tempXAxis, tempXAxis, node.matrix);
vec3.sub(tempXAxis, tempXAxis, tempTransformedPivotPoint);
vec3.set(tempCameraVec, -1, 0, 0);
vec3.transformQuat(tempCameraVec, tempCameraVec, this.rendererData.cameraQuat);
vec3.cross(tempCross0, tempAxis, tempCameraVec);
vec3.cross(tempCross1, tempAxis, tempCross0);
vec3.normalize(tempCross1, tempCross1);
quat.rotationTo(tempLockQuat, tempXAxis, tempCross1);
mat4fromRotationOrigin(tempLockMat, tempLockQuat, tempTransformedPivotPoint);
mat4.mul(node.matrix, tempLockMat, node.matrix);
}
for (let child of node.childs) {
this.updateNode(child);
}
}
const cross = (vec3a, vec3b) => vec3.cross(vec3.create(), vec3a, vec3b);
let DdN = vec3.dot(this.direction, normal);
let sign;
if (DdN > 0) {
if (backfaceCulling) { return null; }
sign = 1;
} else if (DdN < 0) {
sign = -1;
DdN = - DdN;
} else {
return null;
}
vec3.sub(diff, this.origin, a);
vec3.cross(edge2, diff, edge2);
const DdQxE2 = sign * vec3.dot(this.direction, edge2);
if (DdQxE2 < 0) { return null; }
vec3.cross(edge1, edge1, diff);
const DdE1xQ = sign * vec3.dot(this.direction, edge1);
if (DdE1xQ < 0) { return null; }
if(DdQxE2 + DdE1xQ > DdN) { return null; }
const Qdn = - sign * vec3.dot(diff, normal);
if(Qdn < 0) { return null; }
return this.at(Qdn / DdN);
}
return;
const numPoints = 60;
this.warpPathPoints = [];
const delta = vec3.create();
vec3.sub(delta, this.pairedWarpPod.translation, this.translation);
const mag = vec3.length(delta);
const upVec = vec3.create();
calcUpVec(upVec, this);
const negUpVec = vec3.create();
vec3.negate(negUpVec, upVec);
const crossA = vec3.create(), crossB = vec3.create();
vec3.cross(crossA, delta, negUpVec);
vec3.normalize(crossA, crossA);
vec3.cross(crossB, crossA, delta);
vec3.normalize(crossB, crossB);
const halfway = vec3.create();
vec3.scale(halfway, delta, 0.5);
vec3.add(halfway, this.translation, halfway);
const mag2 = 0.5 * mag;
const b = mag2 / Math.sin(MathConstants.TAU / 8);
let a = (b * b) - (mag2 * mag2);
if (a >= 0) {
const norm = 1 / Math.sqrt(a);
const anorm = a * norm;
const cubic = (anorm * norm) - 3.0;
a = -cubic * anorm * 0.5;
triangleArea(a, b, c) {
vec3.sub(this._v1, b, a)
vec3.sub(this._v2, c, a)
vec3.cross(this._v1, this._v1, this._v2)
return 0.5 * vec3.len(this._v1)
}
triangleArea(a, b, c) {
vec3.sub(this._v1, b, a)
vec3.sub(this._v2, c, a)
vec3.cross(this._v1, this._v1, this._v2)
return 0.5 * vec3.len(this._v1)
}