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 "scene-manager.h"
31 template <typename TParent>
33 ISceneManager_addAnimatedMeshSceneNode (SCM scene_manager,
40 SCM also_add_if_mesh_pointer_zero)
42 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
43 scene::IAnimatedMeshSceneNode* node =
44 smgr->addAnimatedMeshSceneNode ((scene::IAnimatedMesh*) scm_to_irr_pointer (mesh),
45 (TParent) scm_to_irr_pointer (parent),
47 scm_to_vector3df (position),
48 scm_to_vector3df (rotation),
49 scm_to_vector3df (scale),
50 scm_to_bool (also_add_if_mesh_pointer_zero));
51 return scm_from_pointer ((void*) node, NULL);
54 template <typename TParent>
56 ISceneManager_addCameraSceneNode (SCM scene_manager,
63 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
64 scene::ICameraSceneNode* camera =
65 smgr->addCameraSceneNode ((TParent) scm_to_irr_pointer (parent),
66 scm_to_vector3df (position),
67 scm_to_vector3df (lookat),
69 scm_to_bool (make_active));
70 return scm_from_pointer ((void*) camera, NULL);
73 template <typename TParent>
75 ISceneManager_addCameraSceneNodeFPS (SCM scene_manager,
84 SCM no_vertical_movement;
89 scm_c_bind_keyword_arguments ("scene_ISceneManager_addCameraSceneNodeFPS",
90 rest, (scm_t_keyword_arguments_flags)0,
91 scm_from_utf8_keyword ("parent"), &parent,
92 scm_from_utf8_keyword ("rotate-speed"), &rotate_speed,
93 scm_from_utf8_keyword ("move-speed"), &move_speed,
94 scm_from_utf8_keyword ("id"), &id,
95 scm_from_utf8_keyword ("key-map-array"), &key_map_array,
96 scm_from_utf8_keyword ("key-map-size"), &key_map_size,
97 scm_from_utf8_keyword ("no-vertical-movement"), &no_vertical_movement,
98 scm_from_utf8_keyword ("jump-speed"), &jump_speed,
99 scm_from_utf8_keyword ("invert-mouse"), &invert_mouse,
100 scm_from_utf8_keyword ("make-active"), &make_active,
103 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
104 scene::ICameraSceneNode* camera =
105 smgr->addCameraSceneNodeFPS ((TParent) scm_to_irr_pointer (parent),
106 scm_to_double (rotate_speed),
107 scm_to_double (move_speed),
109 (SKeyMap*) scm_to_irr_pointer (key_map_array),
110 scm_to_int32 (key_map_size),
111 scm_to_bool (no_vertical_movement),
112 scm_to_double (jump_speed),
113 scm_to_bool (invert_mouse),
114 scm_to_bool (make_active));
115 return scm_from_pointer ((void*) camera, NULL);
118 template <typename TParent>
120 ISceneManager_addCubeSceneNode (SCM scene_manager,
128 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
129 scene::IMeshSceneNode* node =
130 smgr->addCubeSceneNode (scm_to_double (size),
131 (TParent) scm_to_irr_pointer (parent),
133 scm_to_vector3df (position),
134 scm_to_vector3df (rotation),
135 scm_to_vector3df (scale));
136 return scm_from_pointer ((void*) node, NULL);
139 template <typename TParent>
141 ISceneManager_addCustomSceneNode (SCM scene_manager,
143 SCM proc_get_bounding_box,
144 SCM proc_get_material_count,
145 SCM proc_get_material,
152 class CustomSceneNode : public scene::ISceneNode
155 SCM scm_get_bounding_box;
156 SCM scm_get_material_count;
157 SCM scm_get_material;
160 CustomSceneNode (scene::ISceneNode* parent,
161 scene::ISceneManager* smgr,
163 const core::vector3df& position,
164 const core::vector3df& rotation,
165 const core::vector3df& scale,
167 SCM get_bounding_box,
168 SCM get_material_count,
170 : scene::ISceneNode (parent, smgr, id, position, rotation, scale)
173 scm_get_bounding_box = get_bounding_box;
174 scm_get_material_count = get_material_count;
175 scm_get_material = get_material;
178 virtual void OnRegisterSceneNode ()
182 SceneManager->registerNodeForRendering (this);
184 ISceneNode::OnRegisterSceneNode ();
187 virtual void render ()
189 scm_call_0 (scm_render);
192 virtual const core::aabbox3d<f32>& getBoundingBox () const
194 SCM box = scm_call_0 (scm_get_bounding_box);
195 return *((core::aabbox3d<f32>*) scm_to_irr_pointer (box));
198 virtual u32 getMaterialCount () const
200 return scm_to_uint32 (scm_call_0 (scm_get_material_count));
203 virtual video::SMaterial& getMaterial (u32 i)
205 SCM material = scm_call_1 (scm_get_material, scm_from_uint32 (i));
206 return *((video::SMaterial*) scm_to_irr_pointer (material));
210 CustomSceneNode* node =
211 new CustomSceneNode ((TParent) scm_to_irr_pointer (parent),
212 (scene::ISceneManager*) scm_to_irr_pointer (scene_manager),
214 scm_to_vector3df (position),
215 scm_to_vector3df (rotation),
216 scm_to_vector3df (scale),
218 proc_get_bounding_box,
219 proc_get_material_count,
221 return scm_from_pointer ((void*) node, NULL);
224 template <typename TParent, typename TMesh>
226 ISceneManager_addOctreeSceneNode (SCM scene_manager,
230 SCM minimal_polys_per_node,
231 SCM also_add_if_mesh_pointer_zero)
233 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
234 scene::IMeshSceneNode* node =
235 smgr->addOctreeSceneNode ((TMesh) scm_to_irr_pointer (mesh),
236 (TParent) scm_to_irr_pointer (parent),
238 scm_to_int32 (minimal_polys_per_node),
239 scm_to_bool (also_add_if_mesh_pointer_zero));
240 return scm_from_pointer ((void*) node, NULL);
243 template <typename TParent>
245 ISceneManager_addSphereSceneNode (SCM scene_manager,
254 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
255 scene::IMeshSceneNode* node =
256 smgr->addSphereSceneNode (scm_to_double (radius),
257 scm_to_int32 (poly_count),
258 (TParent) scm_to_irr_pointer (parent),
260 scm_to_vector3df (position),
261 scm_to_vector3df (rotation),
262 scm_to_vector3df (scale));
263 return scm_from_pointer ((void*) node, NULL);
267 ISceneManager_createFlyCircleAnimator (SCM scene_manager,
273 SCM radius_ellipsoid)
275 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
276 scene::ISceneNodeAnimator* anim =
277 smgr->createFlyCircleAnimator (scm_to_vector3df (center),
278 scm_to_double (radius),
279 scm_to_double (speed),
280 scm_to_vector3df (direction),
281 scm_to_double (start_position),
282 scm_to_double (radius_ellipsoid));
283 return scm_from_pointer ((void*) anim, NULL);
287 ISceneManager_createFlyStraightAnimator (SCM scene_manager,
294 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
295 scene::ISceneNodeAnimator* anim =
296 smgr->createFlyStraightAnimator (scm_to_vector3df (start_point),
297 scm_to_vector3df (end_point),
298 scm_to_uint32 (time_for_way),
300 scm_to_bool (pingpong));
301 return scm_from_pointer ((void*) anim, NULL);
305 ISceneManager_createRotationAnimator (SCM scene_manager,
308 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
309 scene::ISceneNodeAnimator* anim =
310 smgr->createRotationAnimator (scm_to_vector3df (rotation_speed));
311 return scm_from_pointer ((void*) anim, NULL);
315 ISceneManager_drawAll (SCM scene_manager)
317 ((scene::ISceneManager*) scm_to_irr_pointer (scene_manager))->drawAll ();
318 return SCM_UNSPECIFIED;
322 ISceneManager_getMesh (SCM scene_manager,
325 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
326 scene::IAnimatedMesh* mesh = smgr->getMesh(scm_to_utf8_string (filename));
327 return scm_from_pointer ((void*) mesh, NULL);
331 ISceneManager_getRootSceneNode (SCM scene_manager)
333 scene::ISceneManager* smgr = (scene::ISceneManager*) scm_to_irr_pointer (scene_manager);
334 return scm_from_pointer ((void*) smgr->getRootSceneNode (), NULL);
338 init_scene_manager (void)
340 DEFINE_GSUBR ("ISceneManager_addAnimatedMeshSceneNode_ISceneNode", 8, 0, 0,
341 ISceneManager_addAnimatedMeshSceneNode<scene::ISceneNode*>);
342 DEFINE_GSUBR ("ISceneManager_addCameraSceneNode_ISceneNode", 6, 0, 0,
343 ISceneManager_addCameraSceneNode<scene::ISceneNode*>);
344 DEFINE_GSUBR ("ISceneManager_addCameraSceneNodeFPS_ISceneNode", 1, 0, 1,
345 ISceneManager_addCameraSceneNodeFPS<scene::ISceneNode*>);
346 DEFINE_GSUBR ("ISceneManager_addCubeSceneNode_ISceneNode", 7, 0, 0,
347 ISceneManager_addCubeSceneNode<scene::ISceneNode*>);
348 DEFINE_GSUBR ("ISceneManager_addCustomSceneNode_ISceneNode", 10, 0, 0,
349 ISceneManager_addCustomSceneNode<scene::ISceneNode*>);
350 DEFINE_GSUBR ("ISceneManager_addOctreeSceneNode_ISceneNode_IAnimatedMesh", 6, 0, 0,
351 (ISceneManager_addOctreeSceneNode<scene::ISceneNode*, scene::IAnimatedMesh*>));
352 DEFINE_GSUBR ("ISceneManager_addOctreeSceneNode_ISceneNode_IMesh", 6, 0, 0,
353 (ISceneManager_addOctreeSceneNode<scene::ISceneNode*, scene::IMesh*>));
354 DEFINE_GSUBR ("ISceneManager_addSphereSceneNode_ISceneNode", 8, 0, 0,
355 ISceneManager_addSphereSceneNode<scene::ISceneNode*>);
356 DEFINE_GSUBR ("ISceneManager_createFlyCircleAnimator", 7, 0, 0,
357 ISceneManager_createFlyCircleAnimator);
358 DEFINE_GSUBR ("ISceneManager_createFlyStraightAnimator", 6, 0, 0,
359 ISceneManager_createFlyStraightAnimator);
360 DEFINE_GSUBR ("ISceneManager_createRotationAnimator", 2, 0, 0,
361 ISceneManager_createRotationAnimator);
362 DEFINE_GSUBR ("ISceneManager_drawAll", 1, 0, 0, ISceneManager_drawAll);
363 DEFINE_GSUBR ("ISceneManager_getMesh", 2, 0, 0, ISceneManager_getMesh);
364 DEFINE_GSUBR ("ISceneManager_getRootSceneNode", 1, 0, 0, ISceneManager_getRootSceneNode);