-
Notifications
You must be signed in to change notification settings - Fork 0
/
math3.c
80 lines (71 loc) · 2.26 KB
/
math3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amajid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/20 19:45:25 by amajid #+# #+# */
/* Updated: 2023/12/22 23:25:00 by amajid ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
#include <math.h>
// [a b c d][A B C D] [aA+bE+cI+dM
// [e f g h][E F G H] = [eA+fE+gI+hM ...
// [i j k l][I J K L]
// [m n o p][M N O P]
t_matrix4f matrix4x4_mul(t_matrix4f left, t_matrix4f right)
{
t_matrix4f result;
int i;
int j;
i = 0;
result = get_identity_matrix();
while (i < 4)
{
j = 0;
while (j < 4)
{
result.m[i][j] = left.m[0][j] * right.m[i][0] + left.m[1][j]
* right.m[i][1] + left.m[2][j] * right.m[i][2]
+ left.m[3][j] * right.m[i][3];
j++;
}
i++;
}
return (result);
}
t_matrix4f matrix4x4_set_rotation_x(float flAngle)
{
t_matrix4f result;
result = get_identity_matrix();
flAngle = (flAngle * M_PI / 180);
result.m[1][1] = cos(flAngle);
result.m[2][1] = -sin(flAngle);
result.m[1][2] = sin(flAngle);
result.m[2][2] = cos(flAngle);
return (result);
}
t_matrix4f matrix4x4_set_rotation_y(float flAngle)
{
t_matrix4f result;
result = get_identity_matrix();
flAngle = (flAngle * M_PI / 180);
result.m[0][0] = cos(flAngle);
result.m[2][0] = sin(flAngle);
result.m[0][2] = -sin(flAngle);
result.m[2][2] = cos(flAngle);
return (result);
}
t_matrix4f matrix4x4_set_rotation_z(float flAngle)
{
t_matrix4f result;
result = get_identity_matrix();
flAngle = (flAngle * M_PI / 180);
result.m[0][0] = cos(flAngle);
result.m[1][0] = -sin(flAngle);
result.m[0][1] = sin(flAngle);
result.m[1][1] = cos(flAngle);
return (result);
}