Basic cross-product optimisation

This commit is contained in:
Lucas Dower 2021-07-12 00:47:27 +01:00
parent d465004132
commit 0018f53aa8
2 changed files with 20 additions and 16 deletions

View File

@ -14,10 +14,6 @@ function ceilTo(value, base) {
return Math.ceil(value / base) * base;
}
function fastCrossXAxis(vec) {
return Vector3.create(0.0, -vec[2], vec[1]);
}
function fastDotXAxis(vec) {
return vec[0];
}
@ -29,15 +25,21 @@ function fastDotYAxis(vec) {
function fastDotZAxis(vec) {
return vec[2];
}
*/
function fastCrossXAxis(vec) {
return new Vector3(0.0, -vec.z, vec.y);
}
function fastCrossYAxis(vec) {
return Vector3.create(vec[2], 0.0, -vec[0]);
return new Vector3(vec.z, 0.0, -vec.x);
}
function fastCrossZAxis(vec) {
return Vector3.create(-vec[1], vec[0], 0.0);
return new Vector3(-vec.y, vec.x, 0.0);
}
/*
function roundVector3To(vec, round) {
vec[0] = roundTo(vec[0], round);
vec[1] = roundTo(vec[1], round);
@ -47,11 +49,13 @@ function roundVector3To(vec, round) {
module.exports.floorTo = floorTo;
module.exports.ceilTo = ceilTo;
*/
module.exports.fastCrossXAxis = fastCrossXAxis;
module.exports.fastCrossYAxis = fastCrossYAxis;
module.exports.fastCrossZAxis = fastCrossZAxis;
/*
module.exports.fastDotXAxis = fastDotXAxis;
module.exports.fastDotYAxis = fastDotYAxis;
module.exports.fastDotZAxis = fastDotZAxis;

View File

@ -1,6 +1,6 @@
const { Vector3 } = require('./vector.js');
const { AABB } = require('./aabb.js');
const { xAxis, yAxis, zAxis } = require('./math.js');
const { xAxis, yAxis, zAxis, fastCrossXAxis, fastCrossYAxis, fastCrossZAxis } = require('./math.js');
class Triangle {
@ -52,15 +52,15 @@ class Triangle {
const f2 = Vector3.sub(v0, v2);
const axis = [
Vector3.cross(xAxis, f0),
Vector3.cross(xAxis, f1),
Vector3.cross(xAxis, f2),
Vector3.cross(yAxis, f0),
Vector3.cross(yAxis, f1),
Vector3.cross(yAxis, f2),
Vector3.cross(zAxis, f0),
Vector3.cross(zAxis, f1),
Vector3.cross(zAxis, f2),
fastCrossXAxis(f0),
fastCrossXAxis(f1),
fastCrossXAxis(f2),
fastCrossYAxis(f0),
fastCrossYAxis(f1),
fastCrossYAxis(f2),
fastCrossZAxis(f0),
fastCrossZAxis(f1),
fastCrossZAxis(f2),
xAxis,
yAxis,
zAxis,