From: Javier Sancho Date: Sun, 15 Mar 2020 18:59:53 +0000 (+0100) Subject: set-md2-animation! X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=8ff6816b98af584ca7670ad964d5f13f84e18044;p=guile-irrlicht.git set-md2-animation! --- diff --git a/Makefile.am b/Makefile.am index d666607..a641056 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,7 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libguile-irrlicht.la libguile_irrlicht_la_SOURCES = \ src/animated-mesh.cpp \ + src/animated-mesh-md2.cpp \ src/animated-mesh-scene-node.cpp \ src/device.cpp \ src/dimension2d.cpp \ diff --git a/irrlicht/scene.scm b/irrlicht/scene.scm index 1326783..0053b93 100644 --- a/irrlicht/scene.scm +++ b/irrlicht/scene.scm @@ -21,7 +21,8 @@ (define-module (irrlicht scene) #:export (add-animated-mesh-scene-node get-mesh - set-material-flag!)) + set-material-flag! + set-md2-animation!)) (load-extension "libguile-irrlicht" "init_guile_irrlicht") diff --git a/src/animated-mesh-md2.cpp b/src/animated-mesh-md2.cpp new file mode 100644 index 0000000..70e7473 --- /dev/null +++ b/src/animated-mesh-md2.cpp @@ -0,0 +1,123 @@ +/* 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 "animated-mesh-md2.h" + +extern "C" { + + irr::scene::EMD2_ANIMATION_TYPE + scm_to_md2_animation_type (SCM md2_animation_type) + { + char* flag = scm_to_utf8_stringn (scm_symbol_to_string (md2_animation_type), NULL); + if (!strcmp (flag, "stand")) + { + return irr::scene::EMAT_STAND; + } + else if (!strcmp (flag, "run")) + { + return irr::scene::EMAT_RUN; + } + else if (!strcmp (flag, "attack")) + { + return irr::scene::EMAT_ATTACK; + } + else if (!strcmp (flag, "pain-a")) + { + return irr::scene::EMAT_PAIN_A; + } + else if (!strcmp (flag, "pain-b")) + { + return irr::scene::EMAT_PAIN_B; + } + else if (!strcmp (flag, "pain-c")) + { + return irr::scene::EMAT_PAIN_C; + } + else if (!strcmp (flag, "jump")) + { + return irr::scene::EMAT_JUMP; + } + else if (!strcmp (flag, "flip")) + { + return irr::scene::EMAT_FLIP; + } + else if (!strcmp (flag, "salute")) + { + return irr::scene::EMAT_SALUTE; + } + else if (!strcmp (flag, "fallback")) + { + return irr::scene::EMAT_FALLBACK; + } + else if (!strcmp (flag, "wave")) + { + return irr::scene::EMAT_WAVE; + } + else if (!strcmp (flag, "point")) + { + return irr::scene::EMAT_POINT; + } + else if (!strcmp (flag, "crouch-stand")) + { + return irr::scene::EMAT_CROUCH_STAND; + } + else if (!strcmp (flag, "crouch-walk")) + { + return irr::scene::EMAT_CROUCH_WALK; + } + else if (!strcmp (flag, "crouch-attack")) + { + return irr::scene::EMAT_CROUCH_ATTACK; + } + else if (!strcmp (flag, "crouch-pain")) + { + return irr::scene::EMAT_CROUCH_PAIN; + } + else if (!strcmp (flag, "crouch-death")) + { + return irr::scene::EMAT_CROUCH_DEATH; + } + else if (!strcmp (flag, "death-fallback")) + { + return irr::scene::EMAT_DEATH_FALLBACK; + } + else if (!strcmp (flag, "death-fallforward")) + { + return irr::scene::EMAT_DEATH_FALLFORWARD; + } + else if (!strcmp (flag, "death-fallbackslow")) + { + return irr::scene::EMAT_DEATH_FALLBACKSLOW; + } + else if (!strcmp (flag, "boom")) + { + return irr::scene::EMAT_BOOM; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong MD2 animation type: ~S", + scm_list_1 (md2_animation_type), scm_list_1 (md2_animation_type)); + } + } + +} diff --git a/src/animated-mesh-md2.h b/src/animated-mesh-md2.h new file mode 100644 index 0000000..c37a61b --- /dev/null +++ b/src/animated-mesh-md2.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_ANIMATED_MESH_MD2_H_INCLUDED__ +#define __GUILE_IRRLICHT_ANIMATED_MESH_MD2_H_INCLUDED__ + +#include +#include + +extern "C" { + + irr::scene::EMD2_ANIMATION_TYPE + scm_to_md2_animation_type (SCM md2_animation_type); + +} + +#endif diff --git a/src/animated-mesh-scene-node.cpp b/src/animated-mesh-scene-node.cpp index be46b3a..87fac47 100644 --- a/src/animated-mesh-scene-node.cpp +++ b/src/animated-mesh-scene-node.cpp @@ -21,6 +21,7 @@ #include #include +#include "animated-mesh-md2.h" #include "animated-mesh-scene-node.h" #include "wrapped.h" @@ -30,10 +31,21 @@ extern "C" { init_animated_mesh_scene_node (void) { init_animated_mesh_scene_node_type (); + scm_c_define_gsubr ("set-md2-animation!", 2, 0, 0, (scm_t_subr)irr_scene_setMD2Animation); } DEFINE_WRAPPED_TYPE (irr::scene::IAnimatedMeshSceneNode*, "animated-mesh-scene-node", init_animated_mesh_scene_node_type, animated_mesh_scene_node_p, wrap_animated_mesh_scene_node, unwrap_animated_mesh_scene_node); + SCM + irr_scene_setMD2Animation (SCM wrappedAnimatedMeshSceneNode, + SCM anim) + { + irr::scene::IAnimatedMeshSceneNode* node = + unwrap_animated_mesh_scene_node (wrappedAnimatedMeshSceneNode); + bool result = node->setMD2Animation (scm_to_md2_animation_type (anim)); + return scm_from_bool (result); + } + } diff --git a/src/animated-mesh-scene-node.h b/src/animated-mesh-scene-node.h index 9858cf2..c84aab9 100644 --- a/src/animated-mesh-scene-node.h +++ b/src/animated-mesh-scene-node.h @@ -34,6 +34,11 @@ extern "C" { DECLARE_WRAPPED_TYPE (irr::scene::IAnimatedMeshSceneNode*, init_animated_mesh_scene_node_type, animated_mesh_scene_node_p, wrap_animated_mesh_scene_node, unwrap_animated_mesh_scene_node); + + SCM + irr_scene_setMD2Animation (SCM wrappedAnimatedMeshSceneNode, + SCM anim); + } #endif