]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/guile-irrlicht.cpp
set-transform! get-absolute-transformation
[guile-irrlicht.git] / src / guile-irrlicht.cpp
index 1bb87cf909beaeb18ac62fb9e9d58e08081757d4..35e27f108879944c2120031b8c3721d2d55a0c67 100644 (file)
 #include "gui-element.h"
 #include "gui-environment.h"
 #include "gui-static-text.h"
+#include "guile-irrlicht.h"
 #include "keymap.h"
 #include "material.h"
 #include "material-flags.h"
 #include "mesh.h"
 #include "mesh-scene-node.h"
-#include "misc.h"
 #include "reference-counted.h"
 #include "scene-manager.h"
 #include "scene-node.h"
 #include "texture.h"
 #include "vertex3d.h"
 #include "video-driver.h"
+#include "wchar.h"
 
 extern "C" {
 
   void
   init_guile_irrlicht (void)
   {
+    // Init modules
     init_animated_mesh ();
     init_animated_mesh_scene_node ();
     init_box3d ();
@@ -67,7 +69,6 @@ extern "C" {
     init_material_flag ();
     init_mesh ();
     init_mesh_scene_node ();
-    init_misc ();
     init_reference_counted ();
     init_scene_manager ();
     init_scene_node ();
@@ -75,6 +76,106 @@ extern "C" {
     init_texture ();
     init_vertex3d ();
     init_video_driver ();
+
+    // Shared procedures (used by two or more objects)
+    scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_drawAll);
+    scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName);
+    scm_c_define_gsubr ("set-material!", 2, 0, 0, (scm_t_subr)irr_setMaterial);
+    scm_c_define_gsubr ("set-position!", 2, 0, 0, (scm_t_subr)irr_setPosition);
+    scm_c_define_gsubr ("set-visible!", 2, 0, 0, (scm_t_subr)irr_setVisible);
+    scm_c_export ("draw-all", "get-name", "set-material!", "set-position!",
+                  "set-visible!", NULL);
+  }
+
+  SCM
+  irr_drawAll (SCM wrapped_obj)
+  {
+    if (gui_environment_p (wrapped_obj))
+      {
+        unwrap_gui_environment (wrapped_obj)->drawAll ();
+      }
+    else if (scene_manager_p (wrapped_obj))
+      {
+        unwrap_scene_manager (wrapped_obj)->drawAll ();
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot draw all elements from object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+    return SCM_UNSPECIFIED;
+  }
+
+  SCM
+  irr_getName (SCM wrapped_obj)
+  {
+    if (video_driver_p (wrapped_obj))
+      {
+        return scm_from_wide_char_string (unwrap_video_driver (wrapped_obj)->getName ());
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot get name from object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+  }
+
+  SCM
+  irr_setMaterial (SCM wrapped_obj,
+                   SCM material)
+  {
+    if (video_driver_p (wrapped_obj))
+      {
+        return irr_video_setMaterial (wrapped_obj, material);
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot set material to object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+  }
+
+  SCM
+  irr_setPosition (SCM wrapped_obj,
+                   SCM position)
+  {
+    if (cursor_control_p (wrapped_obj))
+      {
+        return irr_gui_setPosition (wrapped_obj, position);
+      }
+    else if (scene_node_p (wrapped_obj) || mesh_scene_node_p (wrapped_obj))
+      {
+        return irr_scene_setPosition (wrapped_obj, position);
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot set position for object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+  }
+
+  SCM
+  irr_setVisible (SCM wrapped_obj,
+                  SCM visible)
+  {
+    if (cursor_control_p (wrapped_obj))
+      {
+        unwrap_cursor_control (wrapped_obj)->setVisible (scm_to_bool (visible));
+      }
+    else if (gui_element_p (wrapped_obj))
+      {
+        unwrap_gui_element (wrapped_obj)->setVisible (scm_to_bool (visible));
+      }
+    else if (scene_node_p (wrapped_obj))
+      {
+        unwrap_scene_node (wrapped_obj)->setVisible (scm_to_bool (visible));
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot set visibility for object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+    return SCM_UNSPECIFIED;
   }
 
 }