Skip to content

Commit 632c2f8

Browse files
author
Victor Widell
committed
Added supporting matrix functions.
1 parent 23f6dae commit 632c2f8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Matrix.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ Matrix makeMatrixTranslation(const Vector v) {
3131
};
3232
}
3333

34+
Matrix makeMatrixScale(const float s) {
35+
36+
return (Matrix) {
37+
s, 0, 0, 0,
38+
0, s, 0, 0,
39+
0, 0, s, 0,
40+
0, 0, 0, 1
41+
};
42+
}
43+
3444
Matrix makeMatrixAxisAngle(const Vector axis, const float angle) {
3545

3646
float length = vLength(axis);
@@ -290,5 +300,12 @@ Matrix mInversed(const Matrix matrix) {
290300
return returnValue;
291301
}
292302

303+
float mScale(const Matrix matrix) {
293304

294-
305+
return powf(
306+
matrix.values[0][0] * (matrix.values[1][1] * matrix.values[2][2] - matrix.values[1][2] * matrix.values[2][1])
307+
- matrix.values[0][1] * (matrix.values[1][0] * matrix.values[2][2] - matrix.values[1][2] * matrix.values[2][0])
308+
+ matrix.values[0][2] * (matrix.values[1][0] * matrix.values[2][1] - matrix.values[1][1] * matrix.values[2][0]),
309+
1/3.0
310+
);
311+
}

Matrix.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct {
1111
Matrix makeMatrixZero();
1212
Matrix makeMatrixIdentity();
1313
Matrix makeMatrixTranslation(const Vector v);
14+
Matrix makeMatrixScale(const float s);
1415
Matrix makeMatrixAxisAngle(const Vector axis, const float angle);
1516

1617
bool mEqual(const Matrix a, const Matrix b);
@@ -24,4 +25,6 @@ Ray mrMul(const Matrix matrix, const Ray ray);
2425

2526
Matrix mInversed();
2627

28+
float mScale(const Matrix matrix);
29+
2730
#endif // MATRIX_H

0 commit comments

Comments
 (0)