From 21f12bf4ba8c031b36784e1e0a479535f477cc59 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sun, 8 Mar 2020 19:36:37 +0100 Subject: [PATCH] More bindings --- Makefile.am | 6 ++++- irrlicht.scm | 3 ++- irrlicht/device.scm | 1 + irrlicht/scene.scm | 43 ++++++++++++++++++++++++++++++++++ src/GuileIrrlicht.cpp | 6 +++++ src/IAnimatedMesh.cpp | 39 ++++++++++++++++++++++++++++++ src/IAnimatedMesh.h | 38 ++++++++++++++++++++++++++++++ src/IAnimatedMeshSceneNode.cpp | 39 ++++++++++++++++++++++++++++++ src/IAnimatedMeshSceneNode.h | 38 ++++++++++++++++++++++++++++++ src/ISceneManager.cpp | 38 ++++++++++++++++++++++++++++++ src/ISceneManager.h | 13 ++++++++++ src/ISceneNode.cpp | 39 ++++++++++++++++++++++++++++++ src/ISceneNode.h | 38 ++++++++++++++++++++++++++++++ src/IrrlichtDevice.cpp | 30 +++++++++++++++--------- src/IrrlichtDevice.h | 11 +++++---- src/vector3d.cpp | 37 +++++++++++++++++++++++++++++ src/vector3d.h | 35 +++++++++++++++++++++++++++ 17 files changed, 437 insertions(+), 17 deletions(-) create mode 100644 irrlicht/scene.scm create mode 100644 src/IAnimatedMesh.cpp create mode 100644 src/IAnimatedMesh.h create mode 100644 src/IAnimatedMeshSceneNode.cpp create mode 100644 src/IAnimatedMeshSceneNode.h create mode 100644 src/ISceneNode.cpp create mode 100644 src/ISceneNode.h create mode 100644 src/vector3d.cpp create mode 100644 src/vector3d.h diff --git a/Makefile.am b/Makefile.am index 485bc37..36003c1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,14 +4,18 @@ libguile_irrlicht_la_SOURCES = \ src/dimension2d.cpp \ src/EDriverTypes.cpp \ src/GuileIrrlicht.cpp \ + src/IAnimatedMesh.cpp \ + src/IAnimatedMeshSceneNode.cpp \ src/IGUIElement.cpp \ src/IGUIEnvironment.cpp \ src/IGUIStaticText.cpp \ src/IrrlichtDevice.cpp \ src/ISceneManager.cpp \ + src/ISceneNode.cpp \ src/IVideoDriver.cpp \ src/rect.cpp \ - src/util.cpp + src/util.cpp \ + src/vector3d.cpp libguile_irrlicht_la_CPPFLAGS = @GUILE_CFLAGS@ libguile_irrlicht_la_LDFLAGS = \ -version-info 0:1 \ diff --git a/irrlicht.scm b/irrlicht.scm index 6c4025f..327c45e 100644 --- a/irrlicht.scm +++ b/irrlicht.scm @@ -24,7 +24,8 @@ ;; load public symbols into current module (let ((public-modules '((irrlicht device) - (irrlicht gui))) + (irrlicht gui) + (irrlicht scene))) (current-interface (module-public-interface (current-module)))) (for-each diff --git a/irrlicht/device.scm b/irrlicht/device.scm index e07a812..2a61890 100644 --- a/irrlicht/device.scm +++ b/irrlicht/device.scm @@ -20,6 +20,7 @@ (define-module (irrlicht device) #:export (create-device + device-drop! get-gui-environment get-scene-manager get-video-driver diff --git a/irrlicht/scene.scm b/irrlicht/scene.scm new file mode 100644 index 0000000..b815700 --- /dev/null +++ b/irrlicht/scene.scm @@ -0,0 +1,43 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 Javier Sancho +;;; +;;; 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 +;;; . + + +(define-module (irrlicht gui) + #:export (add-animated-mesh-scene-node + get-mesh)) + +(load-extension "libguile-irrlicht" "init_guile_irrlicht") + +(define irr-add-animated-mesh-scene-node add-animated-mesh-scene-node) +(define* (add-animated-mesh-scene-node scene-manager mesh + #:key + (parent #f) + (id -1) + (position '(0 0 0)) + (rotation '(0 0 0)) + (scale '(1 1 1)) + (also-add-if-mesh-pointer-zero #f)) + (irr-add-animated-mesh-scene-node scene-manager + mesh + parent + id + position + rotation + scale + also-add-if-mesh-pointer-zero)) diff --git a/src/GuileIrrlicht.cpp b/src/GuileIrrlicht.cpp index 32fd4ac..2c20385 100644 --- a/src/GuileIrrlicht.cpp +++ b/src/GuileIrrlicht.cpp @@ -20,11 +20,14 @@ */ #include +#include "IAnimatedMesh.h" +#include "IAnimatedMeshSceneNode.h" #include "IGUIElement.h" #include "IGUIEnvironment.h" #include "IGUIStaticText.h" #include "IrrlichtDevice.h" #include "ISceneManager.h" +#include "ISceneNode.h" #include "IVideoDriver.h" extern "C" { @@ -32,11 +35,14 @@ extern "C" { void init_guile_irrlicht (void) { + init_animated_mesh (); + init_animated_mesh_scene_node (); init_device (); init_gui_element (); init_gui_environment (); init_gui_static_text (); init_scene_manager (); + init_scene_node (); init_video_driver (); } diff --git a/src/IAnimatedMesh.cpp b/src/IAnimatedMesh.cpp new file mode 100644 index 0000000..52394ef --- /dev/null +++ b/src/IAnimatedMesh.cpp @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#include +#include +#include "IAnimatedMesh.h" +#include "util.h" + +extern "C" { + + void + init_animated_mesh (void) + { + init_animated_mesh_type (); + } + + DEFINE_WRAPPED_TYPE (irr::scene::IAnimatedMesh*, "animated-mesh", + init_animated_mesh_type, + wrap_animated_mesh, unwrap_animated_mesh); + +} diff --git a/src/IAnimatedMesh.h b/src/IAnimatedMesh.h new file mode 100644 index 0000000..3926002 --- /dev/null +++ b/src/IAnimatedMesh.h @@ -0,0 +1,38 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#ifndef __GUILE_I_ANIMATED_MESH_INCLUDED__ +#define __GUILE_I_ANIMATED_MESH_INCLUDED__ + +#include +#include +#include "util.h" + +extern "C" { + + void + init_animated_mesh (void); + + DECLARE_WRAPPED_TYPE (irr::scene::IAnimatedMesh*, init_animated_mesh_type, + wrap_animated_mesh, unwrap_animated_mesh); +} + +#endif diff --git a/src/IAnimatedMeshSceneNode.cpp b/src/IAnimatedMeshSceneNode.cpp new file mode 100644 index 0000000..d10b9b4 --- /dev/null +++ b/src/IAnimatedMeshSceneNode.cpp @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#include +#include +#include "IAnimatedMeshSceneNode.h" +#include "util.h" + +extern "C" { + + void + init_animated_mesh_scene_node (void) + { + init_animated_mesh_scene_node_type (); + } + + DEFINE_WRAPPED_TYPE (irr::scene::IAnimatedMeshSceneNode*, "animated-mesh-scene-node", + init_animated_mesh_scene_node_type, + wrap_animated_mesh_scene_node, unwrap_animated_mesh_scene_node); + +} diff --git a/src/IAnimatedMeshSceneNode.h b/src/IAnimatedMeshSceneNode.h new file mode 100644 index 0000000..14752e9 --- /dev/null +++ b/src/IAnimatedMeshSceneNode.h @@ -0,0 +1,38 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#ifndef __GUILE_I_ANIMATED_MESH_SCENE_NODE_INCLUDED__ +#define __GUILE_I_ANIMATED_MESH_SCENE_NODE_INCLUDED__ + +#include +#include +#include "util.h" + +extern "C" { + + void + init_animated_mesh_scene_node (void); + + DECLARE_WRAPPED_TYPE (irr::scene::IAnimatedMeshSceneNode*, init_animated_mesh_scene_node_type, + wrap_animated_mesh_scene_node, unwrap_animated_mesh_scene_node); +} + +#endif diff --git a/src/ISceneManager.cpp b/src/ISceneManager.cpp index 6b24b3d..e6cebf4 100644 --- a/src/ISceneManager.cpp +++ b/src/ISceneManager.cpp @@ -21,8 +21,12 @@ #include #include +#include "IAnimatedMesh.h" +#include "IAnimatedMeshSceneNode.h" #include "ISceneManager.h" +#include "ISceneNode.h" #include "util.h" +#include "vector3d.h" extern "C" { @@ -30,10 +34,44 @@ extern "C" { init_scene_manager (void) { init_scene_manager_type (); + scm_c_define_gsubr ("add-animated-mesh-scene-node", 8, 0, 0, + (scm_t_subr)irr_scene_addAnimatedMeshSceneNode); + scm_c_define_gsubr ("get-mesh", 2, 0, 0, (scm_t_subr)irr_scene_getMesh); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager", init_scene_manager_type, wrap_scene_manager, unwrap_scene_manager); + SCM + irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager, + SCM mesh, + SCM parent, + SCM id, + SCM position, + SCM rotation, + SCM scale, + SCM alsoAddIfMeshPointerZero) + { + irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager); + irr::scene::IAnimatedMeshSceneNode* node = + smgr->addAnimatedMeshSceneNode (unwrap_animated_mesh (mesh), + scm_is_false (parent) ? 0 : unwrap_scene_node (parent), + scm_to_int32 (id), + scm_to_vector3df (position), + scm_to_vector3df (rotation), + scm_to_vector3df (scale), + scm_to_bool (alsoAddIfMeshPointerZero)); + return wrap_animated_mesh_scene_node (node); + } + + SCM + irr_scene_getMesh (SCM wrapped_scene_manager, + SCM filename) + { + irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager); + irr::scene::IAnimatedMesh* mesh = smgr->getMesh(scm_to_utf8_stringn (filename, NULL)); + return wrap_animated_mesh (mesh); + } + } diff --git a/src/ISceneManager.h b/src/ISceneManager.h index cdd85c9..02b27de 100644 --- a/src/ISceneManager.h +++ b/src/ISceneManager.h @@ -34,6 +34,19 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::scene::ISceneManager*, init_scene_manager_type, wrap_scene_manager, unwrap_scene_manager); + SCM + irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager, + SCM mesh, + SCM parent, + SCM id, + SCM position, + SCM rotation, + SCM scale, + SCM alsoAddIfMeshPointerZero); + SCM + irr_scene_getMesh (SCM wrapped_scene_manager, + SCM filename); + } #endif diff --git a/src/ISceneNode.cpp b/src/ISceneNode.cpp new file mode 100644 index 0000000..fd9b60c --- /dev/null +++ b/src/ISceneNode.cpp @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#include +#include +#include "ISceneNode.h" +#include "util.h" + +extern "C" { + + void + init_scene_node (void) + { + init_scene_node_type (); + } + + DEFINE_WRAPPED_TYPE (irr::scene::ISceneNode*, "scene-node", + init_scene_node_type, + wrap_scene_node, unwrap_scene_node); + +} diff --git a/src/ISceneNode.h b/src/ISceneNode.h new file mode 100644 index 0000000..79aa0a0 --- /dev/null +++ b/src/ISceneNode.h @@ -0,0 +1,38 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#ifndef __GUILE_I_SCENE_NODE_INCLUDED__ +#define __GUILE_I_SCENE_NODE_INCLUDED__ + +#include +#include +#include "util.h" + +extern "C" { + + void + init_scene_node (void); + + DECLARE_WRAPPED_TYPE (irr::scene::ISceneNode*, init_scene_node_type, + wrap_scene_node, unwrap_scene_node); +} + +#endif diff --git a/src/IrrlichtDevice.cpp b/src/IrrlichtDevice.cpp index 82b729d..a220cac 100644 --- a/src/IrrlichtDevice.cpp +++ b/src/IrrlichtDevice.cpp @@ -37,6 +37,7 @@ extern "C" { { init_device_type (); scm_c_define_gsubr ("create-device", 7, 0, 0, (scm_t_subr)irr_createDevice); + scm_c_define_gsubr ("device-drop!", 1, 0, 0, (scm_t_subr)irr_deviceDrop); scm_c_define_gsubr ("get-gui-environment", 1, 0, 0, (scm_t_subr)irr_getGUIEnvironment); scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager); scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver); @@ -66,34 +67,41 @@ extern "C" { } SCM - irr_getGUIEnvironment (SCM device_obj) + irr_deviceDrop (SCM wrapped_device) { - irr::IrrlichtDevice* device = unwrap_device (device_obj); - irr::gui::IGUIEnvironment* gui_environment = device->getGUIEnvironment(); + irr::IrrlichtDevice* device = unwrap_device (wrapped_device); + return scm_from_bool (device->drop ()); + } + + SCM + irr_getGUIEnvironment (SCM wrapped_device) + { + irr::IrrlichtDevice* device = unwrap_device (wrapped_device); + irr::gui::IGUIEnvironment* gui_environment = device->getGUIEnvironment (); return wrap_gui_environment (gui_environment); } SCM - irr_getSceneManager (SCM device_obj) + irr_getSceneManager (SCM wrapped_device) { - irr::IrrlichtDevice* device = unwrap_device (device_obj); - irr::scene::ISceneManager* scene_manager = device->getSceneManager(); + irr::IrrlichtDevice* device = unwrap_device (wrapped_device); + irr::scene::ISceneManager* scene_manager = device->getSceneManager (); return wrap_scene_manager (scene_manager); } SCM - irr_getVideoDriver (SCM device_obj) + irr_getVideoDriver (SCM wrapped_device) { - irr::IrrlichtDevice* device = unwrap_device (device_obj); - irr::video::IVideoDriver* driver = device->getVideoDriver(); + irr::IrrlichtDevice* device = unwrap_device (wrapped_device); + irr::video::IVideoDriver* driver = device->getVideoDriver (); return wrap_video_driver (driver); } SCM - irr_setWindowCaption (SCM device_obj, + irr_setWindowCaption (SCM wrapped_device, SCM text) { - irr::IrrlichtDevice* device = unwrap_device (device_obj); + irr::IrrlichtDevice* device = unwrap_device (wrapped_device); device->setWindowCaption (scm_to_wide_char_string (text)); return SCM_UNSPECIFIED; } diff --git a/src/IrrlichtDevice.h b/src/IrrlichtDevice.h index 09aa2cd..4b5b604 100644 --- a/src/IrrlichtDevice.h +++ b/src/IrrlichtDevice.h @@ -44,16 +44,19 @@ extern "C" { SCM receiver); SCM - irr_getGUIEnvironment (SCM device_obj); + irr_deviceDrop (SCM wrapped_device); SCM - irr_getSceneManager (SCM device_obj); + irr_getGUIEnvironment (SCM wrapped_device); SCM - irr_getVideoDriver (SCM device_obj); + irr_getSceneManager (SCM wrapped_device); SCM - irr_setWindowCaption (SCM device, + irr_getVideoDriver (SCM wrapped_device); + + SCM + irr_setWindowCaption (SCM wrapped_device, SCM text); } diff --git a/src/vector3d.cpp b/src/vector3d.cpp new file mode 100644 index 0000000..85f5bf8 --- /dev/null +++ b/src/vector3d.cpp @@ -0,0 +1,37 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#include +#include +#include "vector3d.h" + +extern "C" { + + irr::core::vector3df + scm_to_vector3df (SCM vector3d) + { + return irr::core::vector3df + (scm_to_double (scm_car (vector3d)), + scm_to_double (scm_cadr (vector3d)), + scm_to_double (scm_caddr (vector3d))); + } + +} diff --git a/src/vector3d.h b/src/vector3d.h new file mode 100644 index 0000000..8862cdf --- /dev/null +++ b/src/vector3d.h @@ -0,0 +1,35 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#ifndef __GUILE_IRRLICHT_VECTOR_3D_INCLUDED__ +#define __GUILE_IRRLICHT_VECTOR_3D_INCLUDED__ + +#include +#include + +extern "C" { + + irr::core::vector3df + scm_to_vector3df (SCM vector3d); + +} + +#endif -- 2.39.5