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"
28 #include "camera-scene-node.h"
34 #include "mesh-scene-node.h"
35 #include "scene-manager.h"
36 #include "scene-node.h"
37 #include "scene-node-animator.h"
44 init_scene_manager (void)
46 init_scene_manager_type ();
47 DEFINE_GSUBR ("add-animated-mesh-scene-node!", 2, 0, 1, irr_scene_addAnimatedMeshSceneNode);
48 DEFINE_GSUBR ("add-camera-scene-node!", 1, 0, 1, irr_scene_addCameraSceneNode);
49 DEFINE_GSUBR ("add-camera-scene-node-fps!", 1, 0, 1, irr_scene_addCameraSceneNodeFPS);
50 DEFINE_GSUBR ("add-cube-scene-node!", 1, 0, 1, irr_scene_addCubeSceneNode);
51 DEFINE_GSUBR ("add-custom-scene-node!", 5, 0, 1, irr_scene_addCustomSceneNode);
52 DEFINE_GSUBR ("add-octree-scene-node!", 2, 0, 1, irr_scene_addOctreeSceneNode);
53 DEFINE_GSUBR ("add-sphere-scene-node!", 1, 0, 1, irr_scene_addSphereSceneNode);
54 DEFINE_GSUBR ("create-fly-circle-animator", 1, 0, 1, irr_scene_createFlyCircleAnimator);
55 DEFINE_GSUBR ("create-fly-straight-animator", 4, 0, 1, irr_scene_createFlyStraightAnimator);
56 DEFINE_GSUBR ("create-rotation-animator", 2, 0, 0, irr_scene_createRotationAnimator);
57 DEFINE_GSUBR ("get-mesh", 2, 0, 0, irr_scene_getMesh);
58 DEFINE_GSUBR ("get-root-scene-node", 1, 0, 0, irr_scene_getRootSceneNode);
61 DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager",
62 init_scene_manager_type, scene_manager_p,
63 wrap_scene_manager, unwrap_scene_manager);
66 irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager,
70 SCM parent = SCM_UNDEFINED;
71 SCM id = scm_from_int32 (-1);
72 SCM position = scm_list_3 (scm_from_double (0),
75 SCM rotation = scm_list_3 (scm_from_double (0),
78 SCM scale = scm_list_3 (scm_from_double (1),
81 SCM also_add_if_mesh_pointer_zero = SCM_BOOL_F;
83 scm_c_bind_keyword_arguments ("add-animated-mesh-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
84 scm_from_utf8_keyword ("parent"), &parent,
85 scm_from_utf8_keyword ("id"), &id,
86 scm_from_utf8_keyword ("position"), &position,
87 scm_from_utf8_keyword ("rotation"), &rotation,
88 scm_from_utf8_keyword ("scale"), &scale,
89 scm_from_utf8_keyword ("also-add-if-mesh-pointer-zero"), &also_add_if_mesh_pointer_zero,
92 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
93 irr::scene::IAnimatedMeshSceneNode* node =
94 smgr->addAnimatedMeshSceneNode (unwrap_animated_mesh (mesh),
95 parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
97 scm_to_vector3df (position),
98 scm_to_vector3df (rotation),
99 scm_to_vector3df (scale),
100 scm_to_bool (also_add_if_mesh_pointer_zero));
101 return wrap_animated_mesh_scene_node (node);
105 irr_scene_addCameraSceneNode (SCM wrapped_scene_manager,
108 SCM parent = SCM_UNDEFINED;
109 SCM position = scm_list_3 (scm_from_double (0),
111 scm_from_double (0));
112 SCM lookat = scm_list_3 (scm_from_double (0),
114 scm_from_double (100));
115 SCM id = scm_from_int32 (-1);
116 SCM make_active = SCM_BOOL_T;
118 scm_c_bind_keyword_arguments ("add-camera-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
119 scm_from_utf8_keyword ("parent"), &parent,
120 scm_from_utf8_keyword ("position"), &position,
121 scm_from_utf8_keyword ("lookat"), &lookat,
122 scm_from_utf8_keyword ("id"), &id,
123 scm_from_utf8_keyword ("make-active"), &make_active,
126 irr::scene::ISceneManager* scene_manager = unwrap_scene_manager (wrapped_scene_manager);
127 irr::scene::ICameraSceneNode* camera =
128 scene_manager->addCameraSceneNode (parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
129 scm_to_vector3df (position),
130 scm_to_vector3df (lookat),
132 scm_to_bool (make_active));
133 return wrap_camera_scene_node (camera);
137 irr_scene_addCameraSceneNodeFPS (SCM wrapped_scene_manager,
140 SCM parent = SCM_UNDEFINED;
141 SCM rotate_speed = scm_from_double (100);
142 SCM move_speed = scm_from_double (0.5);
143 SCM id = scm_from_int32 (-1);
144 SCM key_map_array = SCM_UNDEFINED;
145 SCM key_map_size = scm_from_int32 (0);
146 SCM no_vertical_movement = SCM_BOOL_F;
147 SCM jump_speed = scm_from_double (0);
148 SCM invert_mouse = SCM_BOOL_F;
149 SCM make_active = SCM_BOOL_T;
151 scm_c_bind_keyword_arguments ("add-camera-scene-node-fps!", rest, (scm_t_keyword_arguments_flags)0,
152 scm_from_utf8_keyword ("parent"), &parent,
153 scm_from_utf8_keyword ("rotate-speed"), &rotate_speed,
154 scm_from_utf8_keyword ("move-speed"), &move_speed,
155 scm_from_utf8_keyword ("id"), &id,
156 scm_from_utf8_keyword ("key-map-array"), &key_map_array,
157 scm_from_utf8_keyword ("key-map-size"), &key_map_size,
158 scm_from_utf8_keyword ("no-vertical-movement"), &no_vertical_movement,
159 scm_from_utf8_keyword ("jump-speed"), &jump_speed,
160 scm_from_utf8_keyword ("invert-mouse"), &invert_mouse,
161 scm_from_utf8_keyword ("make-active"), &make_active,
164 irr::scene::ISceneManager* scene_manager = unwrap_scene_manager (wrapped_scene_manager);
165 irr::scene::ICameraSceneNode* camera =
166 scene_manager->addCameraSceneNodeFPS (parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
167 scm_to_double (rotate_speed),
168 scm_to_double (move_speed),
170 key_map_array == SCM_UNDEFINED ? 0 : unwrap_keymap (key_map_array),
171 scm_to_int32 (key_map_size),
172 scm_to_bool (no_vertical_movement),
173 scm_to_double (jump_speed),
174 scm_to_bool (invert_mouse),
175 scm_to_bool (make_active));
176 return wrap_camera_scene_node (camera);
180 irr_scene_addCubeSceneNode (SCM wrapped_scene_manager,
183 SCM size = scm_from_double (10);
184 SCM parent = SCM_UNDEFINED;
185 SCM id = scm_from_int32 (-1);
186 SCM position = scm_list_3 (scm_from_double (0),
188 scm_from_double (0));
189 SCM rotation = scm_list_3 (scm_from_double (0),
191 scm_from_double (0));
192 SCM scale = scm_list_3 (scm_from_double (1),
194 scm_from_double (1));
196 scm_c_bind_keyword_arguments ("add-cube-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
197 scm_from_utf8_keyword ("size"), &size,
198 scm_from_utf8_keyword ("parent"), &parent,
199 scm_from_utf8_keyword ("id"), &id,
200 scm_from_utf8_keyword ("position"), &position,
201 scm_from_utf8_keyword ("rotation"), &rotation,
202 scm_from_utf8_keyword ("scale"), &scale,
205 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
206 irr::scene::IMeshSceneNode* node =
207 smgr->addCubeSceneNode (scm_to_double (size),
208 parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
210 scm_to_vector3df (position),
211 scm_to_vector3df (rotation),
212 scm_to_vector3df (scale));
213 return wrap_mesh_scene_node (node);
217 irr_scene_addCustomSceneNode (SCM wrapped_scene_manager,
219 SCM proc_get_bounding_box,
220 SCM proc_get_material_count,
221 SCM proc_get_material,
224 irr::scene::ISceneManager* scene_manager = unwrap_scene_manager (wrapped_scene_manager);
226 SCM parent = wrap_scene_node (scene_manager->getRootSceneNode ());
227 SCM id = scm_from_int32 (-1);
228 SCM position = scm_list_3 (scm_from_double (0),
230 scm_from_double (0));
231 SCM rotation = scm_list_3 (scm_from_double (0),
233 scm_from_double (0));
234 SCM scale = scm_list_3 (scm_from_double (1),
236 scm_from_double (1));
238 scm_c_bind_keyword_arguments ("add-custom-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
239 scm_from_utf8_keyword ("parent"), &parent,
240 scm_from_utf8_keyword ("id"), &id,
241 scm_from_utf8_keyword ("position"), &position,
242 scm_from_utf8_keyword ("rotation"), &rotation,
243 scm_from_utf8_keyword ("scale"), &scale,
246 class CustomSceneNode : public irr::scene::ISceneNode
249 SCM scm_get_bounding_box;
250 SCM scm_get_material_count;
251 SCM scm_get_material;
254 CustomSceneNode (irr::scene::ISceneNode* parent,
255 irr::scene::ISceneManager* smgr,
257 const irr::core::vector3df& position,
258 const irr::core::vector3df& rotation,
259 const irr::core::vector3df& scale,
261 SCM get_bounding_box,
262 SCM get_material_count,
264 : irr::scene::ISceneNode (parent, smgr, id, position, rotation, scale)
267 scm_get_bounding_box = get_bounding_box;
268 scm_get_material_count = get_material_count;
269 scm_get_material = get_material;
272 virtual void OnRegisterSceneNode ()
276 SceneManager->registerNodeForRendering (this);
278 ISceneNode::OnRegisterSceneNode ();
281 virtual void render ()
283 scm_call_0 (scm_render);
286 virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox () const
288 SCM box = scm_call_0 (scm_get_bounding_box);
289 return *(unwrap_box3d (box));
292 virtual irr::u32 getMaterialCount () const
294 return scm_to_uint32 (scm_call_0 (scm_get_material_count));
297 virtual irr::video::SMaterial& getMaterial (irr::u32 i)
299 SCM material = scm_call_1 (scm_get_material, scm_from_uint32 (i));
300 return *(unwrap_material (material));
304 CustomSceneNode* node =
305 new CustomSceneNode (unwrap_scene_node (parent),
308 scm_to_vector3df (position),
309 scm_to_vector3df (rotation),
310 scm_to_vector3df (scale),
312 proc_get_bounding_box,
313 proc_get_material_count,
315 return wrap_scene_node (node);
319 irr_scene_addOctreeSceneNode (SCM wrapped_scene_manager,
323 SCM parent = SCM_UNDEFINED;
324 SCM id = scm_from_int32 (-1);
325 SCM minimal_polys_per_node = scm_from_int32 (256);
326 SCM also_add_if_mesh_pointer_zero = SCM_BOOL_F;
328 scm_c_bind_keyword_arguments ("add-octree-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
329 scm_from_utf8_keyword ("parent"), &parent,
330 scm_from_utf8_keyword ("id"), &id,
331 scm_from_utf8_keyword ("minimal-polys-per-node"), &minimal_polys_per_node,
332 scm_from_utf8_keyword ("also-add-if-mesh-pointer-zero"), &also_add_if_mesh_pointer_zero,
335 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
336 irr::scene::IMeshSceneNode* node;
337 if (animated_mesh_p (wrapped_mesh))
339 node = smgr->addOctreeSceneNode (unwrap_animated_mesh (wrapped_mesh),
340 parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
342 scm_to_int32 (minimal_polys_per_node),
343 scm_to_bool (also_add_if_mesh_pointer_zero));
347 node = smgr->addOctreeSceneNode (unwrap_mesh (wrapped_mesh),
348 parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
350 scm_to_int32 (minimal_polys_per_node),
351 scm_to_bool (also_add_if_mesh_pointer_zero));
353 return wrap_mesh_scene_node (node);
357 irr_scene_addSphereSceneNode (SCM wrapped_scene_manager,
360 SCM radius = scm_from_double (5.0);
361 SCM poly_count = scm_from_int32 (16);
362 SCM parent = SCM_UNDEFINED;
363 SCM id = scm_from_int32 (-1);
364 SCM position = scm_list_3 (scm_from_double (0),
366 scm_from_double (0));
367 SCM rotation = scm_list_3 (scm_from_double (0),
369 scm_from_double (0));
370 SCM scale = scm_list_3 (scm_from_double (1),
372 scm_from_double (1));
374 scm_c_bind_keyword_arguments ("add-sphere-scene-node!", rest, (scm_t_keyword_arguments_flags)0,
375 scm_from_utf8_keyword ("radius"), &radius,
376 scm_from_utf8_keyword ("poly-count"), &poly_count,
377 scm_from_utf8_keyword ("parent"), &parent,
378 scm_from_utf8_keyword ("id"), &id,
379 scm_from_utf8_keyword ("position"), &position,
380 scm_from_utf8_keyword ("rotation"), &rotation,
381 scm_from_utf8_keyword ("scale"), &scale,
384 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
385 irr::scene::IMeshSceneNode* node =
386 smgr->addSphereSceneNode (scm_to_double (radius),
387 scm_to_int32 (poly_count),
388 parent == SCM_UNDEFINED ? 0 : unwrap_scene_node (parent),
390 scm_to_vector3df (position),
391 scm_to_vector3df (rotation),
392 scm_to_vector3df (scale));
393 return wrap_mesh_scene_node (node);
397 irr_scene_createFlyCircleAnimator (SCM wrapped_scene_manager,
400 SCM center = scm_list_3 (scm_from_double (0),
402 scm_from_double (0));
403 SCM radius = scm_from_double (100);
404 SCM speed = scm_from_double (0.001);
405 SCM direction = scm_list_3 (scm_from_double (0),
407 scm_from_double (0));
408 SCM start_position = scm_from_double (0);
409 SCM radius_ellipsoid = scm_from_double (0);
411 scm_c_bind_keyword_arguments ("create-fly-circle-animator", rest, (scm_t_keyword_arguments_flags)0,
412 scm_from_utf8_keyword ("center"), ¢er,
413 scm_from_utf8_keyword ("radius"), &radius,
414 scm_from_utf8_keyword ("speed"), &speed,
415 scm_from_utf8_keyword ("direction"), &direction,
416 scm_from_utf8_keyword ("start-position"), &start_position,
417 scm_from_utf8_keyword ("radius-ellipsoid"), &radius_ellipsoid,
420 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
421 irr::scene::ISceneNodeAnimator* anim =
422 smgr->createFlyCircleAnimator (scm_to_vector3df (center),
423 scm_to_double (radius),
424 scm_to_double (speed),
425 scm_to_vector3df (direction),
426 scm_to_double (start_position),
427 scm_to_double (radius_ellipsoid));
428 return wrap_scene_node_animator (anim);
432 irr_scene_createFlyStraightAnimator (SCM wrapped_scene_manager,
438 SCM loop = SCM_BOOL_F;
439 SCM pingpong = SCM_BOOL_F;
441 scm_c_bind_keyword_arguments ("create-fly-straight-animator", rest, (scm_t_keyword_arguments_flags)0,
442 scm_from_utf8_keyword ("loop"), &loop,
443 scm_from_utf8_keyword ("pingpong"), &pingpong,
446 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
447 irr::scene::ISceneNodeAnimator* anim =
448 smgr->createFlyStraightAnimator (scm_to_vector3df (start_point),
449 scm_to_vector3df (end_point),
450 scm_to_uint32 (time_for_way),
452 scm_to_bool (pingpong));
453 return wrap_scene_node_animator (anim);
457 irr_scene_createRotationAnimator (SCM wrapped_scene_manager,
460 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
461 irr::scene::ISceneNodeAnimator* anim =
462 smgr->createRotationAnimator (scm_to_vector3df (rotation_speed));
463 return wrap_scene_node_animator (anim);
467 irr_scene_getMesh (SCM wrapped_scene_manager,
470 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
471 irr::scene::IAnimatedMesh* mesh = smgr->getMesh(scm_to_utf8_stringn (filename, NULL));
472 return wrap_animated_mesh (mesh);
476 irr_scene_getRootSceneNode (SCM wrapped_scene_manager)
478 irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager);
479 return wrap_scene_node (smgr->getRootSceneNode ());