-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.wl
53 lines (46 loc) · 908 Bytes
/
matrix.wl
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
use "importc"
import(C) "/usr/include/stdlib.h"
import(C) "/usr/include/math.h"
struct Matrix
{
float^ v
}
Matrix new_matrix()
{
Matrix m
m.v = malloc(4 * 4)
matrix_identity(&m)
return m
}
void matrix_identity(Matrix^ m)
{
m.v[0] = 1.0
m.v[1] = 0.0
m.v[2] = 1.0
m.v[3] = 1.0
}
void matrix_rotation(Matrix^ m, float rad)
{
float s
float c
s = sin(rad);
c = cos(rad);
//sincosf(rad, &s, &c)
m.v[0] = c
m.v[1] = 0.0-s
m.v[2] = s
m.v[3] = c
}
void matrix_mult(Matrix^ dst, Matrix^ a, Matrix^ b)
{
dst.v[0] = a.v[0] * b.v[0] + a.v[1] * b.v[2]
dst.v[1] = a.v[0] * b.v[1] + a.v[1] * b.v[3]
dst.v[2] = a.v[2] * b.v[0] + a.v[3] * b.v[2]
dst.v[3] = a.v[2] * b.v[1] + a.v[3] * b.v[3]
}
void matrix_rotate(Matrix^ m, float rad)
{
Matrix rmat
matrix_rotation(&rmat, rad)
matrix_mult(m, m, &rmat)
}