]> git.jsancho.org Git - guile-irrlicht.git/blob - src/scene-node.cpp
684ad3fa4b57e9fd7a2ee2f74c175bcf1d3ff0b2
[guile-irrlicht.git] / src / scene-node.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
25 #include "animated-mesh-scene-node.h"
26 #include "matrix4.h"
27 #include "mesh-scene-node.h"
28 #include "scene-node.h"
29 #include "scene-node-animator.h"
30 #include "texture.h"
31 #include "vector3d.h"
32 #include "wrapped.h"
33
34 extern "C" {
35
36   void
37   init_scene_node (void)
38   {
39     init_scene_node_type ();
40     scm_c_define_gsubr ("add-animator!", 2, 0, 0, (scm_t_subr)irr_scene_addAnimator);
41     scm_c_define_gsubr ("get-absolute-transformation", 1, 0, 0,
42                         (scm_t_subr)irr_scene_getAbsoluteTransformation);
43     scm_c_define_gsubr ("set-material-texture!", 3, 0, 0, (scm_t_subr)irr_scene_setMaterialTexture);
44     scm_c_export ("add-animator!", "get-absolute-transformation",
45                   "set-material-texture!", NULL);
46   }
47
48   DEFINE_WRAPPED_TYPE (irr::scene::ISceneNode*, "scene-node",
49                        init_scene_node_type, scene_node_p,
50                        wrap_scene_node, unwrap_scene_node);
51
52   SCM
53   irr_scene_addAnimator (SCM wrapped_scene_node,
54                          SCM animator)
55   {
56     irr::scene::ISceneNode* node = unwrap_scene_node (wrapped_scene_node);
57     node->addAnimator (unwrap_scene_node_animator (animator));
58     return SCM_UNSPECIFIED;
59   }
60
61   SCM
62   irr_scene_getAbsoluteTransformation (SCM wrapped_scene_node)
63   {
64     irr::scene::ISceneNode* node = unwrap_scene_node (wrapped_scene_node);
65     return scm_from_matrix4 (node->getAbsoluteTransformation ());
66   }
67
68   SCM
69   irr_scene_setMaterialTexture (SCM wrapped_scene_node,
70                                 SCM texture_layer,
71                                 SCM texture)
72   {
73     if (animated_mesh_scene_node_p (wrapped_scene_node))
74       {
75         unwrap_animated_mesh_scene_node (wrapped_scene_node)->
76           setMaterialTexture (scm_to_uint32 (texture_layer),
77                               unwrap_texture (texture));
78       }
79     else if (scene_node_p (wrapped_scene_node))
80       {
81         unwrap_scene_node (wrapped_scene_node)->
82           setMaterialTexture (scm_to_uint32 (texture_layer),
83                               unwrap_texture (texture));
84       }
85     else
86       {
87         scm_error (scm_arg_type_key, NULL, "Cannot set material texture to object: ~S",
88                    scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
89       }
90     return SCM_UNSPECIFIED;
91   }
92
93   SCM
94   irr_scene_setPosition (SCM wrapped_scene_node,
95                          SCM position)
96   {
97     if (scene_node_p (wrapped_scene_node))
98       {
99         unwrap_scene_node (wrapped_scene_node)->
100           setPosition (scm_to_vector3df (position));
101       }
102     else if (mesh_scene_node_p (wrapped_scene_node))
103       {
104         unwrap_mesh_scene_node (wrapped_scene_node)->
105           setPosition (scm_to_vector3df (position));
106       }
107     else
108       {
109         scm_error (scm_arg_type_key, NULL, "Cannot set position to object: ~S",
110                    scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
111       }
112     return SCM_UNSPECIFIED;
113   }
114
115 }