-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7405 from holomorfo/matrix-api
[p5.js 2.0] Vector n-dimentional and Matrix Interface
- Loading branch information
Showing
17 changed files
with
3,920 additions
and
2,145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export let GLMAT_ARRAY_TYPE = Array; | ||
export let isMatrixArray = (x) => Array.isArray(x); | ||
if (typeof Float32Array !== "undefined") { | ||
GLMAT_ARRAY_TYPE = Float32Array; | ||
isMatrixArray = (x) => Array.isArray(x) || x instanceof Float32Array; | ||
} | ||
export class MatrixInterface { | ||
// Private field to store the matrix | ||
#matrix = null; | ||
constructor(...args) { | ||
if (this.constructor === MatrixInterface) { | ||
throw new Error("Class is of abstract type and can't be instantiated"); | ||
} | ||
const methods = [ | ||
"add", | ||
"setElement", | ||
"reset", | ||
"set", | ||
"get", | ||
"copy", | ||
"clone", | ||
"diagonal", | ||
"row", | ||
"column", | ||
"transpose", | ||
"mult", | ||
"multiplyVec", | ||
"invert", | ||
"createSubMatrix3x3", | ||
"inverseTranspose4x4", | ||
"apply", | ||
"scale", | ||
"rotate4x4", | ||
"translate", | ||
"rotateX", | ||
"rotateY", | ||
"rotateZ", | ||
"perspective", | ||
"ortho", | ||
"multiplyVec4", | ||
"multiplyPoint", | ||
"multiplyAndNormalizePoint", | ||
"multiplyDirection", | ||
"multiplyVec3", | ||
]; | ||
|
||
methods.forEach((method) => { | ||
if (this[method] === undefined) { | ||
throw new Error(`${method}() method must be implemented`); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.