circles, triangles and rotations for primitive shapes

This commit is contained in:
2023-12-11 23:00:31 +02:00
committed by Illusion
parent a3fcd5b93f
commit 212c7b9d5a
6 changed files with 129 additions and 22 deletions
+34
View File
@@ -1,3 +1,5 @@
#include <math.h>
#include "helper.h"
Matrix4x4 identity() {
@@ -11,6 +13,34 @@ Matrix4x4 identity() {
return result;
}
void mult_4x4(Matrix4x4 *multiplicant, Matrix4x4 *multiplier) {
Matrix4x4 result = identity();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
result.m[i][j] = 0;
for (int k = 0; k < 4; k++) {
result.m[i][j] += multiplicant->m[i][k] * multiplier->m[k][j];
}
}
}
*multiplicant = result;
}
// TODO: rotate around the center of the element
// currently we rotate around the 0, 0 point of the element
void apply_rotation(Matrix4x4 *model, float angle) {
Matrix4x4 ident = identity();
ident.m[0][0] = cos(angle);
ident.m[0][1] = sin(angle);
ident.m[1][0] = -sin(angle);
ident.m[1][1] = cos(angle);
mult_4x4(model, &ident);
}
Matrix4x4 orthographic_projection_2d(float left, float right, float bottom, float top) {
Matrix4x4 result = identity();
@@ -41,3 +71,7 @@ float clampf(float value, float min, float max) {
return value;
}
float to_radians(float degrees) {
return degrees * (M_PI / 180.f);
}