]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/matrix4.cpp
set-transform! get-absolute-transformation
[guile-irrlicht.git] / src / matrix4.cpp
diff --git a/src/matrix4.cpp b/src/matrix4.cpp
new file mode 100644 (file)
index 0000000..2861a0c
--- /dev/null
@@ -0,0 +1,77 @@
+/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
+
+   Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
+
+   This file is part of guile-irrlicht.
+
+   guile-irrlicht is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 3 of the
+   License, or (at your option) any later version.
+
+   guile-irrlicht is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with guile-irrlicht. If not, see
+   <http://www.gnu.org/licenses/>.
+*/
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+#include "matrix4.h"
+
+extern "C" {
+
+  SCM
+  scm_from_matrix4 (irr::core::matrix4 cmatrix)
+  {
+    return scm_list_4 (scm_list_4 (scm_from_double (cmatrix[0]),
+                                   scm_from_double (cmatrix[1]),
+                                   scm_from_double (cmatrix[2]),
+                                   scm_from_double (cmatrix[3])),
+                       scm_list_4 (scm_from_double (cmatrix[4]),
+                                   scm_from_double (cmatrix[5]),
+                                   scm_from_double (cmatrix[6]),
+                                   scm_from_double (cmatrix[7])),
+                       scm_list_4 (scm_from_double (cmatrix[8]),
+                                   scm_from_double (cmatrix[9]),
+                                   scm_from_double (cmatrix[10]),
+                                   scm_from_double (cmatrix[11])),
+                       scm_list_4 (scm_from_double (cmatrix[12]),
+                                   scm_from_double (cmatrix[13]),
+                                   scm_from_double (cmatrix[14]),
+                                   scm_from_double (cmatrix[15])));
+  }
+
+  irr::core::matrix4
+  scm_to_matrix4 (SCM matrix)
+  {
+    irr::core::matrix4 cmatrix;
+
+    cmatrix[0] = scm_to_double (scm_car (scm_car (matrix)));
+    cmatrix[1] = scm_to_double (scm_cadr (scm_car (matrix)));
+    cmatrix[2] = scm_to_double (scm_caddr (scm_car (matrix)));
+    cmatrix[3] = scm_to_double (scm_cadddr (scm_car (matrix)));
+
+    cmatrix[4] = scm_to_double (scm_car (scm_cadr (matrix)));
+    cmatrix[5] = scm_to_double (scm_cadr (scm_cadr (matrix)));
+    cmatrix[6] = scm_to_double (scm_caddr (scm_cadr (matrix)));
+    cmatrix[7] = scm_to_double (scm_cadddr (scm_cadr (matrix)));
+
+    cmatrix[8] = scm_to_double (scm_car (scm_caddr (matrix)));
+    cmatrix[9] = scm_to_double (scm_cadr (scm_caddr (matrix)));
+    cmatrix[10] = scm_to_double (scm_caddr (scm_caddr (matrix)));
+    cmatrix[11] = scm_to_double (scm_cadddr (scm_caddr (matrix)));
+
+    cmatrix[12] = scm_to_double (scm_car (scm_cadddr (matrix)));
+    cmatrix[13] = scm_to_double (scm_cadr (scm_cadddr (matrix)));
+    cmatrix[14] = scm_to_double (scm_caddr (scm_cadddr (matrix)));
+    cmatrix[15] = scm_to_double (scm_cadddr (scm_cadddr (matrix)));
+
+    return cmatrix;
+  }
+
+}