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"
29 #include "scene-manager.h"
30 #include "scene-node.h"
37 init_scene_manager (void)
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);
50 DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager",
51 init_scene_manager_type, scene_manager_p,
52 wrap_scene_manager, unwrap_scene_manager);
55 irr_scene_addAnimatedMeshSceneNode (SCM wrapped_scene_manager,
59 SCM parent = scm_from_bool (0);
60 SCM id = scm_from_int32 (-1);
61 SCM position = scm_list_3 (scm_from_double (0),
64 SCM rotation = scm_list_3 (scm_from_double (0),
67 SCM scale = scm_list_3 (scm_from_double (1),
70 SCM also_add_if_mesh_pointer_zero = scm_from_bool (0);
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,
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),
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);
94 irr_scene_addCameraSceneNode (SCM wrapped_scene_manager,
97 SCM parent = scm_from_bool (0);
98 SCM position = scm_list_3 (scm_from_double (0),
100 scm_from_double (0));
101 SCM lookat = scm_list_3 (scm_from_double (0),
103 scm_from_double (100));
104 SCM id = scm_from_int32 (-1);
105 SCM make_active = scm_from_bool (1);
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,
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),
121 scm_to_bool (make_active));
122 return wrap_camera_scene_node (camera);
126 irr_scene_getMesh (SCM wrapped_scene_manager,
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);
135 irr_getSceneManager (SCM wrapped_obj)
137 irr::scene::ISceneManager* scene_manager;
138 if (device_p (wrapped_obj))
140 scene_manager = unwrap_device (wrapped_obj)->getSceneManager ();
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));
147 return wrap_scene_manager (scene_manager);