]> git.jsancho.org Git - guile-irrlicht.git/blob - src/matrix4.cpp
67d58ed81aff315ce9960e87ad75a22ad34b7200
[guile-irrlicht.git] / src / matrix4.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    guile-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht. If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include <libguile.h>
24 #include "matrix4.h"
25
26
27 using namespace irr;
28
29
30 SCM
31 scm_from_matrix4 (core::matrix4 cmatrix)
32 {
33   return scm_list_4 (scm_list_4 (scm_from_double (cmatrix[0]),
34                                  scm_from_double (cmatrix[1]),
35                                  scm_from_double (cmatrix[2]),
36                                  scm_from_double (cmatrix[3])),
37                      scm_list_4 (scm_from_double (cmatrix[4]),
38                                  scm_from_double (cmatrix[5]),
39                                  scm_from_double (cmatrix[6]),
40                                  scm_from_double (cmatrix[7])),
41                      scm_list_4 (scm_from_double (cmatrix[8]),
42                                  scm_from_double (cmatrix[9]),
43                                  scm_from_double (cmatrix[10]),
44                                  scm_from_double (cmatrix[11])),
45                      scm_list_4 (scm_from_double (cmatrix[12]),
46                                  scm_from_double (cmatrix[13]),
47                                  scm_from_double (cmatrix[14]),
48                                  scm_from_double (cmatrix[15])));
49 }
50
51
52 core::matrix4
53 scm_to_matrix4 (SCM matrix)
54 {
55   core::matrix4 cmatrix;
56
57   cmatrix[0] = scm_to_double (scm_car (scm_car (matrix)));
58   cmatrix[1] = scm_to_double (scm_cadr (scm_car (matrix)));
59   cmatrix[2] = scm_to_double (scm_caddr (scm_car (matrix)));
60   cmatrix[3] = scm_to_double (scm_cadddr (scm_car (matrix)));
61
62   cmatrix[4] = scm_to_double (scm_car (scm_cadr (matrix)));
63   cmatrix[5] = scm_to_double (scm_cadr (scm_cadr (matrix)));
64   cmatrix[6] = scm_to_double (scm_caddr (scm_cadr (matrix)));
65   cmatrix[7] = scm_to_double (scm_cadddr (scm_cadr (matrix)));
66
67   cmatrix[8] = scm_to_double (scm_car (scm_caddr (matrix)));
68   cmatrix[9] = scm_to_double (scm_cadr (scm_caddr (matrix)));
69   cmatrix[10] = scm_to_double (scm_caddr (scm_caddr (matrix)));
70   cmatrix[11] = scm_to_double (scm_cadddr (scm_caddr (matrix)));
71
72   cmatrix[12] = scm_to_double (scm_car (scm_cadddr (matrix)));
73   cmatrix[13] = scm_to_double (scm_cadr (scm_cadddr (matrix)));
74   cmatrix[14] = scm_to_double (scm_caddr (scm_cadddr (matrix)));
75   cmatrix[15] = scm_to_double (scm_cadddr (scm_cadddr (matrix)));
76
77   return cmatrix;
78 }