1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
3 Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
5 This file is part of guile-irrlicht.
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.
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.
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/>.
22 #include <irrlicht/irrlicht.h>
25 #include "animated-mesh.h"
26 #include "animated-mesh-scene-node.h"
27 #include "camera-scene-node.h"
30 #include "mesh-scene-node.h"
31 #include "scene-manager.h"
32 #include "scene-node.h"
39 init_scene_manager (void)
41 init_scene_manager_type ();
42 scm_c_define_gsubr ("add-animated-mesh-scene-node!", 2, 0, 1,
43 (scm_t_subr)irr_scene_addAnimatedMeshSceneNode);
44 scm_c_define_gsubr ("add-camera-scene-node!", 1, 0, 1,
45 (scm_t_subr)irr_scene_addCameraSceneNode);
46 scm_c_define_gsubr ("add-octree-scene-node!", 2, 0, 1,
47 (scm_t_subr)irr_scene_addOctreeSceneNode);
48 scm_c_define_gsubr ("get-mesh", 2, 0, 0, (scm_t_subr)irr_scene_getMesh);
49 scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager);
50 scm_c_export ("add-animated-mesh-scene-node!", "add-camera-scene-node!",
51 "add-octree-scene-node!", "get-mesh", "get-scene-manager", NULL);
54 DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager",
55 init_scene_manager_type, scene_manager_p,
56 wrap_scene_manager, unwrap_scene_manager);
59 irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager,
63 SCM parent = scm_from_bool (0);
64 SCM id = scm_from_int32 (-1);
65 SCM position = scm_list_3 (scm_from_double (0),
68 SCM rotation = scm_list_3 (scm_from_double (0),
71 SCM scale = scm_list_3 (scm_from_double (1),
74 SCM also_add_if_mesh_pointer_zero = scm_from_bool (0);
76 scm_c_bind_keyword_arguments ("add-animated-mesh-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
77 scm_from_utf8_keyword ("parent"), &parent,
78 scm_from_utf8_keyword ("id"), &id,
79 scm_from_utf8_keyword ("position"), &position,
80 scm_from_utf8_keyword ("rotation"), &rotation,
81 scm_from_utf8_keyword ("scale"), &scale,
82 scm_from_utf8_keyword ("also-add-if-mesh-pointer-zero"), &also_add_if_mesh_pointer_zero,
85 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
86 irr::scene::IAnimatedMeshSceneNode* node =
87 smgr->addAnimatedMeshSceneNode (unwrap_animated_mesh (mesh),
88 scm_is_false (parent) ? 0 : unwrap_scene_node (parent),
90 scm_to_vector3df (position),
91 scm_to_vector3df (rotation),
92 scm_to_vector3df (scale),
93 scm_to_bool (also_add_if_mesh_pointer_zero));
94 return wrap_animated_mesh_scene_node (node);
98 irr_scene_addCameraSceneNode (SCM wrapped_scene_manager,
101 SCM parent = scm_from_bool (0);
102 SCM position = scm_list_3 (scm_from_double (0),
104 scm_from_double (0));
105 SCM lookat = scm_list_3 (scm_from_double (0),
107 scm_from_double (100));
108 SCM id = scm_from_int32 (-1);
109 SCM make_active = scm_from_bool (1);
111 scm_c_bind_keyword_arguments ("add-camera-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
112 scm_from_utf8_keyword ("parent"), &parent,
113 scm_from_utf8_keyword ("position"), &position,
114 scm_from_utf8_keyword ("lookat"), &lookat,
115 scm_from_utf8_keyword ("id"), &id,
116 scm_from_utf8_keyword ("make-active"), &make_active,
119 irr::scene::ISceneManager* scene_manager = unwrap_scene_manager (wrapped_scene_manager);
120 irr::scene::ICameraSceneNode* camera =
121 scene_manager->addCameraSceneNode (scm_is_false (parent) ? 0 : unwrap_scene_node (parent),
122 scm_to_vector3df (position),
123 scm_to_vector3df (lookat),
125 scm_to_bool (make_active));
126 return wrap_camera_scene_node (camera);
130 irr_scene_addOctreeSceneNode (SCM wrapped_scene_manager,
134 SCM parent = scm_from_bool (0);
135 SCM id = scm_from_int32 (-1);
136 SCM minimal_polys_per_node = scm_from_int32 (256);
137 SCM also_add_if_mesh_pointer_zero = scm_from_bool (0);
139 scm_c_bind_keyword_arguments ("add-octree-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
140 scm_from_utf8_keyword ("parent"), &parent,
141 scm_from_utf8_keyword ("id"), &id,
142 scm_from_utf8_keyword ("minimal-polys-per-node"), &minimal_polys_per_node,
143 scm_from_utf8_keyword ("also-add-if-mesh-pointer-zero"), &also_add_if_mesh_pointer_zero,
146 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
147 irr::scene::IMeshSceneNode* node;
148 if (animated_mesh_p (wrapped_mesh))
150 node = smgr->addOctreeSceneNode (unwrap_animated_mesh (wrapped_mesh),
151 scm_is_false (parent) ? 0 : unwrap_scene_node (parent),
153 scm_to_int32 (minimal_polys_per_node),
154 scm_to_bool (also_add_if_mesh_pointer_zero));
158 node = smgr->addOctreeSceneNode (unwrap_mesh (wrapped_mesh),
159 scm_is_false (parent) ? 0 : unwrap_scene_node (parent),
161 scm_to_int32 (minimal_polys_per_node),
162 scm_to_bool (also_add_if_mesh_pointer_zero));
164 return wrap_mesh_scene_node (node);
168 irr_scene_getMesh (SCM wrapped_scene_manager,
171 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
172 irr::scene::IAnimatedMesh* mesh = smgr->getMesh(scm_to_utf8_stringn (filename, NULL));
173 return wrap_animated_mesh (mesh);
177 irr_getSceneManager (SCM wrapped_obj)
179 irr::scene::ISceneManager* scene_manager;
180 if (device_p (wrapped_obj))
182 scene_manager = unwrap_device (wrapped_obj)->getSceneManager ();
186 scm_error (scm_arg_type_key, NULL, "Cannot get scene manager from object: ~S",
187 scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
189 return wrap_scene_manager (scene_manager);