]> git.jsancho.org Git - guile-irrlicht.git/blob - src/scene-manager.cpp
Define procedures with keywords from C code
[guile-irrlicht.git] / src / scene-manager.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.h"
26 #include "animated-mesh-scene-node.h"
27 #include "camera-scene-node.h"
28 #include "device.h"
29 #include "scene-manager.h"
30 #include "scene-node.h"
31 #include "vector3d.h"
32 #include "wrapped.h"
33
34 extern "C" {
35
36   void
37   init_scene_manager (void)
38   {
39     init_scene_manager_type ();
40     scm_c_define_gsubr ("add-animated-mesh-scene-node!", 2, 0, 1,
41                         (scm_t_subr)irr_scene_addAnimatedMeshSceneNode);
42     scm_c_define_gsubr ("add-camera-scene-node!", 1, 0, 1,
43                         (scm_t_subr)irr_scene_addCameraSceneNode);
44     scm_c_define_gsubr ("get-mesh", 2, 0, 0, (scm_t_subr)irr_scene_getMesh);
45     scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager);
46     scm_c_export ("add-animated-mesh-scene-node!", "add-camera-scene-node!",
47                   "get-mesh", "get-scene-manager", NULL);
48   }
49
50   DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager",
51                        init_scene_manager_type, scene_manager_p,
52                        wrap_scene_manager, unwrap_scene_manager);
53
54   SCM
55   irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager,
56                                       SCM mesh,
57                                       SCM rest)
58   {
59     SCM parent = scm_from_bool (0);
60     SCM id = scm_from_int32 (-1);
61     SCM position = scm_list_3 (scm_from_double (0),
62                                scm_from_double (0),
63                                scm_from_double (0));
64     SCM rotation = scm_list_3 (scm_from_double (0),
65                                scm_from_double (0),
66                                scm_from_double (0));
67     SCM scale = scm_list_3 (scm_from_double (1),
68                             scm_from_double (1),
69                             scm_from_double (1));
70     SCM also_add_if_mesh_pointer_zero = scm_from_bool (0);
71
72     scm_c_bind_keyword_arguments ("add-animated-mesh-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
73                                   scm_from_utf8_keyword ("parent"), &parent,
74                                   scm_from_utf8_keyword ("id"), &id,
75                                   scm_from_utf8_keyword ("position"), &position,
76                                   scm_from_utf8_keyword ("rotation"), &rotation,
77                                   scm_from_utf8_keyword ("scale"), &scale,
78                                   scm_from_utf8_keyword ("also-add-if-mesh-pointer-zero"), &also_add_if_mesh_pointer_zero,
79                                   SCM_UNDEFINED);
80
81     irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
82     irr::scene::IAnimatedMeshSceneNode* node =
83       smgr->addAnimatedMeshSceneNode (unwrap_animated_mesh (mesh),
84                                       scm_is_false (parent) ? 0 : unwrap_scene_node (parent),
85                                       scm_to_int32 (id),
86                                       scm_to_vector3df (position),
87                                       scm_to_vector3df (rotation),
88                                       scm_to_vector3df (scale),
89                                       scm_to_bool (also_add_if_mesh_pointer_zero));
90     return wrap_animated_mesh_scene_node (node);
91   }
92
93   SCM
94   irr_scene_addCameraSceneNode (SCM wrapped_scene_manager,
95                                 SCM rest)
96   {
97     SCM parent = scm_from_bool (0);
98     SCM position = scm_list_3 (scm_from_double (0),
99                                scm_from_double (0),
100                                scm_from_double (0));
101     SCM lookat = scm_list_3 (scm_from_double (0),
102                              scm_from_double (0),
103                              scm_from_double (100));
104     SCM id = scm_from_int32 (-1);
105     SCM make_active = scm_from_bool (1);
106
107     scm_c_bind_keyword_arguments ("add-camera-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
108                                   scm_from_utf8_keyword ("parent"), &parent,
109                                   scm_from_utf8_keyword ("position"), &position,
110                                   scm_from_utf8_keyword ("lookat"), &lookat,
111                                   scm_from_utf8_keyword ("id"), &id,
112                                   scm_from_utf8_keyword ("make-active"), &make_active,
113                                   SCM_UNDEFINED);
114
115     irr::scene::ISceneManager* scene_manager = unwrap_scene_manager (wrapped_scene_manager);
116     irr::scene::ICameraSceneNode* camera =
117       scene_manager->addCameraSceneNode (scm_is_false (parent) ? 0 : unwrap_scene_node (parent),
118                                          scm_to_vector3df (position),
119                                          scm_to_vector3df (lookat),
120                                          scm_to_int32 (id),
121                                          scm_to_bool (make_active));
122     return wrap_camera_scene_node (camera);
123   }
124
125   SCM
126   irr_scene_getMesh (SCM wrapped_scene_manager,
127                      SCM filename)
128   {
129     irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
130     irr::scene::IAnimatedMesh* mesh = smgr->getMesh(scm_to_utf8_stringn (filename, NULL));
131     return wrap_animated_mesh (mesh);
132   }
133
134   SCM
135   irr_getSceneManager (SCM wrapped_obj)
136   {
137     irr::scene::ISceneManager* scene_manager;
138     if (device_p (wrapped_obj))
139       {
140         scene_manager = unwrap_device (wrapped_obj)->getSceneManager ();
141       }
142     else
143       {
144         scm_error (scm_arg_type_key, NULL, "Cannot get scene manager from object: ~S",
145                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
146       }
147     return wrap_scene_manager (scene_manager);
148   }
149
150 }