|
@ -64,9 +64,13 @@ export default class Matrix { |
|
|
* @return The resulting translation matrix |
|
|
* @return The resulting translation matrix |
|
|
*/ |
|
|
*/ |
|
|
static translation(translation: Vector): Matrix { |
|
|
static translation(translation: Vector): Matrix { |
|
|
|
|
|
|
|
|
// TODO: Return a new Matrix that is translated according to the given Vector
|
|
|
// TODO: Return a new Matrix that is translated according to the given Vector
|
|
|
return Matrix.identity(); |
|
|
|
|
|
|
|
|
return new Matrix([ |
|
|
|
|
|
1, 0, 0, translation.x, |
|
|
|
|
|
0, 1, 0, translation.y, |
|
|
|
|
|
0, 0, 1, translation.z, |
|
|
|
|
|
0, 0, 0, 1 |
|
|
|
|
|
]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -82,7 +86,32 @@ export default class Matrix { |
|
|
// TODO: (1, 0, 0, 0) to specify the x-axis
|
|
|
// TODO: (1, 0, 0, 0) to specify the x-axis
|
|
|
// TODO: (0, 1, 0, 0) to specify the y-axis
|
|
|
// TODO: (0, 1, 0, 0) to specify the y-axis
|
|
|
// TODO: (0, 0, 1, 0) to specify the z-axis
|
|
|
// TODO: (0, 0, 1, 0) to specify the z-axis
|
|
|
return Matrix.identity(); |
|
|
|
|
|
|
|
|
if(axis.x == 1) { |
|
|
|
|
|
return new Matrix ([ |
|
|
|
|
|
1, 0, 0, 0, |
|
|
|
|
|
0, Math.cos(angle), -1 * Math.sin(angle), 0, |
|
|
|
|
|
0, Math.sin(angle), Math.cos(angle), 0, |
|
|
|
|
|
0, 0, 0, 1 |
|
|
|
|
|
]); |
|
|
|
|
|
} else |
|
|
|
|
|
if(axis.y == 1) { |
|
|
|
|
|
return new Matrix ([ |
|
|
|
|
|
Math.cos(angle), 0, Math.sin(angle), 0, |
|
|
|
|
|
0, 1, 0, 0, |
|
|
|
|
|
-1 * Math.sin(angle), 0, Math.cos(angle), 0, |
|
|
|
|
|
0, 0, 0, 1 |
|
|
|
|
|
]); |
|
|
|
|
|
} else |
|
|
|
|
|
if(axis.z == 1) { |
|
|
|
|
|
return new Matrix ([ |
|
|
|
|
|
Math.cos(angle), -1 * Math.sin(angle), 0, 0, |
|
|
|
|
|
Math.sin(angle), Math.cos(angle), 0, 0, |
|
|
|
|
|
0, 0, 1, 0, |
|
|
|
|
|
0, 0, 0, 1 |
|
|
|
|
|
]); |
|
|
|
|
|
} else { |
|
|
|
|
|
return Matrix.identity(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -92,7 +121,12 @@ export default class Matrix { |
|
|
*/ |
|
|
*/ |
|
|
static scaling(scale: Vector): Matrix { |
|
|
static scaling(scale: Vector): Matrix { |
|
|
// TODO: Return a new scaling Matrix with the scaling components of the Vector scale
|
|
|
// TODO: Return a new scaling Matrix with the scaling components of the Vector scale
|
|
|
return Matrix.identity(); |
|
|
|
|
|
|
|
|
return new Matrix([ |
|
|
|
|
|
scale.x, 0, 0, 0, |
|
|
|
|
|
0, scale.y, 0, 0, |
|
|
|
|
|
0, 0, scale.z, 0, |
|
|
|
|
|
0, 0, 0, 1 |
|
|
|
|
|
]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,7 +150,19 @@ export default class Matrix { |
|
|
*/ |
|
|
*/ |
|
|
mul(other: Matrix): Matrix { |
|
|
mul(other: Matrix): Matrix { |
|
|
// TODO: Return a new Matrix mat with mat = this * other
|
|
|
// TODO: Return a new Matrix mat with mat = this * other
|
|
|
return Matrix.identity(); |
|
|
|
|
|
|
|
|
var aNumRows = 4, aNumCols = 4, |
|
|
|
|
|
bNumRows = 4, bNumCols = 4, |
|
|
|
|
|
m = new Matrix([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); // initialize array of rows
|
|
|
|
|
|
for (var r = 0; r < aNumRows; ++r) { |
|
|
|
|
|
for (var c = 0; c < bNumCols; ++c) { |
|
|
|
|
|
let temp = 0; |
|
|
|
|
|
for (var i = 0; i < aNumCols; ++i) { |
|
|
|
|
|
temp += this.getVal(r, i) * other.getVal(i,c); |
|
|
|
|
|
} |
|
|
|
|
|
m.setVal(r, c, temp); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return m; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -126,7 +172,19 @@ export default class Matrix { |
|
|
*/ |
|
|
*/ |
|
|
mulVec(other: Vector): Vector { |
|
|
mulVec(other: Vector): Vector { |
|
|
// TODO: Return a new Vector vec with vec = this * other
|
|
|
// TODO: Return a new Vector vec with vec = this * other
|
|
|
return new Vector(0, 0, 0, 0); |
|
|
|
|
|
|
|
|
var aNumRows = 4, aNumCols = 4, |
|
|
|
|
|
bNumRows = 4, bNumCols = 4, |
|
|
|
|
|
m = new Array(0,0,0,0); // initialize result vector
|
|
|
|
|
|
for (var r = 0; r < aNumRows; ++r) { |
|
|
|
|
|
for (var c = 0; c < bNumCols; ++c) { |
|
|
|
|
|
let temp = 0; |
|
|
|
|
|
for (var i = 0; i < aNumCols; ++i) { |
|
|
|
|
|
temp += this.getVal(r, i) * other.valueOf()[i]; |
|
|
|
|
|
} |
|
|
|
|
|
m[r] = temp; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return new Vector(m[0], m[1], m[2], m[3]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|