Skip to content
Snippets Groups Projects
Commit a62a283a authored by Christoph-Anton Schwierz's avatar Christoph-Anton Schwierz
Browse files

matrix4Product()

parent 86d79449
No related branches found
No related tags found
No related merge requests found
...@@ -142,8 +142,30 @@ export type Matrix4 = [ ...@@ -142,8 +142,30 @@ export type Matrix4 = [
export function multVec3Matrix4(v: Vec3, m: Matrix4):Vec3 { export function multVec3Matrix4(v: Vec3, m: Matrix4):Vec3 {
const v4: Vec4 = [v[0], v[1], v[2], 1] const v4: Vec4 = [v[0], v[1], v[2], 1]
return [v4[0]*m[0] + v4[1]*m[4] + v4[2]*m[8] + v4[3]*m[12], return [
v4[0]*m[0] + v4[1]*m[4] + v4[2]*m[8] + v4[3]*m[12],
v4[0]*m[1] + v4[1]*m[5] + v4[2]*m[9] + v4[3]*m[13], v4[0]*m[1] + v4[1]*m[5] + v4[2]*m[9] + v4[3]*m[13],
v4[0]*m[2] + v4[1]*m[6] + v4[2]*m[10] + v4[3]*m[14]]; v4[0]*m[2] + v4[1]*m[6] + v4[2]*m[10] + v4[3]*m[14]];
} }
export function matrix4Product(a: Matrix4, b: Matrix4):Matrix4 {
// for 4x4 matrix only
//[
// 0 1 2 3
// 4 5 6 7
// 8 9 10 11
// 12 13 14 15
// ]
return [
//row 1
a[0]*b[0] + a[1]*b[4] + a[2]*b[8] + a[3]*b[12], a[0]*b[1] + a[1]*b[5] + a[2]*b[9] + a[3]*b[13], a[0]*b[2] + a[1]*b[6] + a[2]*b[10] + a[3]*b[14], a[0]*b[3] + a[1]*b[7] + a[2]*b[11] + a[3]*b[15],
//row 2
a[4]*b[0] + a[5]*b[4] + a[6]*b[8] + a[7]*b[12], a[4]*b[1] + a[5]*b[5] + a[6]*b[9] + a[7]*b[13], a[4]*b[2] + a[5]*b[6] + a[6]*b[10] + a[7]*b[14], a[4]*b[3] + a[5]*b[7] + a[6]*b[11] + a[7]*b[15],
//row 3
a[8]*b[0] + a[9]*b[4] + a[10]*b[8] + a[11]*b[12], a[8]*b[1] + a[9]*b[5] + a[10]*b[9] + a[11]*b[13], a[8]*b[2] + a[9]*b[6] + a[10]*b[10] + a[11]*b[14], a[8]*b[3] + a[9]*b[7] + a[10]*b[11] + a[11]*b[15],
//row 4
a[12]*b[0] + a[13]*b[4] + a[14]*b[8] + a[15]*b[12], a[12]*b[1] + a[13]*b[5] + a[14]*b[9] + a[15]*b[13], a[12]*b[2] + a[13]*b[6] + a[14]*b[10] + a[15]*b[14], a[12]*b[3] + a[13]*b[7] + a[14]*b[11] + a[15]*b[15]
]
}
// //
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment