| 1 | module main |
| 2 | |
| 3 | pub type Mat4 = [16]f32 |
| 4 | |
| 5 | pub 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 | |
| 18 | interface IGameObject { |
| 19 | parent ?&IGameObject |
| 20 | transform Mat4 |
| 21 | world_transform() Mat4 |
| 22 | } |
| 23 | |
| 24 | struct GameObject implements IGameObject { |
| 25 | mut: |
| 26 | transform Mat4 |
| 27 | parent ?&IGameObject |
| 28 | } |
| 29 | |
| 30 | fn (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 | |
| 37 | fn test_main() { |
| 38 | t := GameObject{} |
| 39 | a := dump(t.world_transform()) |
| 40 | assert a.len == 16 |
| 41 | } |
| 42 | |