v2 / vlib / v / tests / fns / iface_method_fixed_arr_test.v
41 lines · 35 sloc · 717 bytes · 2afce42fc7b4b161df1d352335c3c46c036f72e3
Raw
1module main
2
3pub type Mat4 = [16]f32
4
5pub fn (a Mat4) * (b Mat4) Mat4 {
6 mut res := Mat4{}
7 for i := 0; i < 4; i++ {
8 for j := 0; j < 4; j++ {
9 res[j * 4 + i] = 0
10 for k := 0; k < 4; k++ {
11 res[j * 4 + i] += a[k * 4 + i] * b[j * 4 + k]
12 }
13 }
14 }
15 return res
16}
17
18interface IGameObject {
19 parent ?&IGameObject
20 transform Mat4
21 world_transform() Mat4
22}
23
24struct GameObject implements IGameObject {
25mut:
26 transform Mat4
27 parent ?&IGameObject
28}
29
30fn (gameobject GameObject) world_transform() Mat4 {
31 if mut p := gameobject.parent {
32 return p.world_transform() * gameobject.transform
33 }
34 return gameobject.transform
35}
36
37fn test_main() {
38 t := GameObject{}
39 a := dump(t.world_transform())
40 assert a.len == 16
41}
42