-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(matrices): update mat23to44, mat33to44
- Loading branch information
1 parent
db08cb8
commit 7dac1e6
Showing
2 changed files
with
54 additions
and
23 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,20 +1,34 @@ | ||
import { setC } from "@thi.ng/vectors"; | ||
import { MatOpM } from "./api"; | ||
|
||
/** | ||
* Converts M23 to M44 and writes result to `out`. | ||
* Converts 2x3 to 4x4 matrix and writes result to `out`. Creates new | ||
* matrix if `out` is `null`. | ||
* | ||
* @param out | ||
* @param m23 | ||
*/ | ||
export const mat23to44: MatOpM = (out, m23) => ( | ||
!out && (out = []), | ||
(out[0] = m23[0]), | ||
(out[1] = m23[1]), | ||
(out[4] = m23[2]), | ||
(out[5] = m23[3]), | ||
(out[12] = m23[4]), | ||
(out[13] = m23[5]), | ||
(out[10] = out[15] = 1), | ||
(out[2] = out[3] = out[6] = out[7] = out[8] = out[9] = out[11] = out[14] = 0), | ||
out | ||
); | ||
export const mat23to44: MatOpM = (out, m23) => | ||
setC( | ||
out || [], | ||
// x | ||
m23[0], | ||
m23[1], | ||
0, | ||
0, | ||
// y | ||
m23[2], | ||
m23[3], | ||
0, | ||
0, | ||
// z | ||
0, | ||
0, | ||
1, | ||
0, | ||
// w | ||
m23[4], | ||
m23[5], | ||
0, | ||
1 | ||
); |
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 |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import { setS3, setS4, ZERO4 } from "@thi.ng/vectors"; | ||
import { setC } from "@thi.ng/vectors"; | ||
import { MatOpM } from "./api"; | ||
|
||
/** | ||
* Converts M33 to M44 and writes result to `out`. | ||
* Converts 3x3 to 4x4 matrix and writes result to `out`. Creates new | ||
* matrix if `out` is `null`. | ||
* | ||
* @param out | ||
* @param m33 | ||
*/ | ||
export const mat33to44: MatOpM = (out, m33) => ( | ||
!out && (out = []), | ||
setS3(out, m33, 0, 0), | ||
setS3(out, m33, 4, 3), | ||
setS3(out, m33, 8, 6), | ||
setS3(out, ZERO4, 12), | ||
setS4(out, [0, 0, 0, 1], 3, 0, 4) | ||
); | ||
export const mat33to44: MatOpM = (out, m33) => | ||
setC( | ||
out || [], | ||
// x | ||
m33[0], | ||
m33[1], | ||
m33[2], | ||
0, | ||
// y | ||
m33[3], | ||
m33[4], | ||
m33[5], | ||
0, | ||
// z | ||
m33[6], | ||
m33[7], | ||
m33[8], | ||
0, | ||
// w | ||
0, | ||
0, | ||
0, | ||
1 | ||
); |