]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
get-position
authorJavier Sancho <jsf@jsancho.org>
Wed, 15 Apr 2020 10:50:39 +0000 (12:50 +0200)
committerJavier Sancho <jsf@jsancho.org>
Wed, 15 Apr 2020 10:50:39 +0000 (12:50 +0200)
src/cursor-control.cpp
src/cursor-control.h
src/guile-irrlicht.cpp
src/guile-irrlicht.h
src/position2d.cpp
src/position2d.h
src/scene-node.cpp
src/scene-node.h
src/wrapped.h

index 5ff6540d7960e82df57fea5fa40b9049627fed7a..1147eab54191ab35ad655b9ef0c6ce103c5ac8c9 100644 (file)
@@ -49,6 +49,13 @@ extern "C" {
     return wrap_cursor_control (cursor_control);
   }
 
+  SCM
+  irr_gui_getPosition (SCM wrapped_cursor_control)
+  {
+    irr::gui::ICursorControl* control = unwrap_cursor_control (wrapped_cursor_control);
+    return scm_from_position2d_s32 (control->getPosition ());
+  }
+
   SCM
   irr_gui_setPosition (SCM wrapped_cursor_control,
                        SCM position)
index d7a4bc5fff7dbb526f8a093dde6c716a06ddf887..1d4677c24384ef3d12230a20dd23779e7f52aa1b 100644 (file)
@@ -37,6 +37,9 @@ extern "C" {
   SCM
   irr_getCursorControl (SCM wrapped_device);
 
+  SCM
+  irr_gui_getPosition (SCM wrapped_cursor_control);
+
   SCM
   irr_gui_setPosition (SCM wrapped_cursor_control,
                        SCM position);
index 29fb2fbdb2961200ebe08f70e7d71698e99917e8..4531715adcd5a385d4ce75ea85d9a59dfe3bc2ae 100644 (file)
@@ -88,6 +88,7 @@ extern "C" {
 
     // Shared procedures (used by two or more objects)
     DEFINE_GSUBR ("draw-all", 1, 0, 0, irr_drawAll);
+    DEFINE_GSUBR ("get-position", 1, 1, 0, irr_getPosition);
     DEFINE_GSUBR ("get-name", 1, 0, 0, irr_getName);
     DEFINE_GSUBR ("set-material!", 2, 0, 0, irr_setMaterial);
     DEFINE_GSUBR ("set-material-flag!", 3, 0, 0, irr_setMaterialFlag);
@@ -128,6 +129,25 @@ extern "C" {
       }
   }
 
+  SCM
+  irr_getPosition (SCM wrapped_obj,
+                   SCM i)
+  {
+    if (cursor_control_p (wrapped_obj))
+      {
+        return irr_gui_getPosition (wrapped_obj);
+      }
+    else if (is_scene_node_object (wrapped_obj))
+      {
+        return irr_scene_getPosition (wrapped_obj);
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Cannot get position from object: ~S",
+                   scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
+      }
+  }
+
   SCM
   irr_setMaterial (SCM wrapped_obj,
                    SCM material)
@@ -148,9 +168,7 @@ extern "C" {
                        SCM flag,
                        SCM newvalue)
   {
-    if (animated_mesh_scene_node_p (wrapped_obj) ||
-        mesh_scene_node_p (wrapped_obj) ||
-        scene_node_p (wrapped_obj))
+    if (is_scene_node_object (wrapped_obj))
       {
         return irr_scene_ISceneNode_setMaterialFlag (wrapped_obj, flag, newvalue);
       }
@@ -169,7 +187,7 @@ extern "C" {
       {
         return irr_gui_setPosition (wrapped_obj, position);
       }
-    else if (scene_node_p (wrapped_obj) || mesh_scene_node_p (wrapped_obj))
+    else if (is_scene_node_object (wrapped_obj))
       {
         return irr_scene_setPosition (wrapped_obj, position);
       }
@@ -194,7 +212,7 @@ extern "C" {
       {
         SET_VISIBLE (unwrap_gui_element (wrapped_obj));
       }
-    else if (scene_node_p (wrapped_obj))
+    else if (is_scene_node_object (wrapped_obj))
       {
         SET_VISIBLE (unwrap_scene_node (wrapped_obj));
       }
index 5f42bac5c671832b770f98b01617b76ce886e828..c60fdddb9c592ebb99dc32cdf4599c1b6708c4ba 100644 (file)
@@ -33,6 +33,10 @@ extern "C" {
   SCM
   irr_drawAll (SCM wrapped_obj);
 
+  SCM
+  irr_getPosition (SCM wrapped_obj,
+                   SCM i);
+
   SCM
   irr_getName (SCM wrapped_obj);
 
index 16c44bc50672b742c096835829fc1268018039a2..20fb74316f87b04a5e1779a69079fd7e04c4d6a3 100644 (file)
 
 extern "C" {
 
+  SCM
+  scm_from_position2d_s32 (irr::core::position2d<irr::s32> position2d)
+  {
+    return scm_list_2 (scm_from_int32 (position2d.X),
+                       scm_from_int32 (position2d.Y));
+  }
+
   irr::core::position2d<irr::f32>
   scm_to_position2d_f32 (SCM position2d)
   {
index 287499877240008fbcc5ca59629b8f30efe36ac8..e13555bacd025a11ac9ddf9653f6263c71f38cdf 100644 (file)
@@ -27,6 +27,9 @@
 
 extern "C" {
 
+  SCM
+  scm_from_position2d_s32 (irr::core::position2d<irr::s32> position2d);
+
   irr::core::position2d<irr::f32>
   scm_to_position2d_f32 (SCM position2d);
 
index 50d402b3866031277d9fab2edf9ca143dde2b3a1..8b3b561902674b8114157969c30fe1d94bfcaa44 100644 (file)
@@ -51,6 +51,16 @@ extern "C" {
                        init_scene_node_type, scene_node_p,
                        wrap_scene_node, unwrap_scene_node);
 
+  bool
+  is_scene_node_object (SCM wrapped_scene_node)
+  {
+    return
+      animated_mesh_scene_node_p (wrapped_scene_node) ||
+      camera_scene_node_p (wrapped_scene_node) ||
+      mesh_scene_node_p (wrapped_scene_node) ||
+      scene_node_p (wrapped_scene_node);
+  }
+
   SCM
   irr_scene_addAnimator (SCM wrapped_scene_node,
                          SCM animator)
@@ -85,6 +95,13 @@ extern "C" {
     return scm_from_matrix4 (node->getAbsoluteTransformation ());
   }
 
+  SCM
+  irr_scene_getPosition (SCM wrapped_scene_node)
+  {
+    irr::scene::ISceneNode* node = unwrap_scene_node (wrapped_scene_node, false);
+    return scm_from_vector3df (node->getPosition ());
+  }
+
   SCM
   irr_scene_ISceneNode_setMaterialFlag (SCM wrapped_scene_node,
                                         SCM flag,
index 038601f4f7ca71ad8b27e4b0cee255a5f0deef5d..ca7acc9f7c03ffadd7e35e80253bcad91d91814b 100644 (file)
@@ -34,6 +34,9 @@ extern "C" {
   DECLARE_WRAPPED_TYPE (irr::scene::ISceneNode*, init_scene_node_type,
                         scene_node_p, wrap_scene_node, unwrap_scene_node);
 
+  bool
+  is_scene_node_object (SCM wrapped_scene_node);
+
   SCM
   irr_scene_addAnimator (SCM wrapped_scene_node,
                          SCM animator);
@@ -41,6 +44,9 @@ extern "C" {
   SCM
   irr_scene_getAbsoluteTransformation (SCM wrapped_scene_node);
 
+  SCM
+  irr_scene_getPosition (SCM wrapped_scene_node);
+
   SCM
   irr_scene_ISceneNode_setMaterialFlag (SCM wrapped_scene_node,
                                         SCM flag,
index daaaa25404d07c95e32fd71f7e6d7a927e100353..5ffafb6745c10f3ece617a9d4dd7fe3c527774c4 100644 (file)
@@ -32,7 +32,7 @@
   WRAP (TYPE foreign_obj);                                              \
                                                                         \
   TYPE                                                                  \
-  UNWRAP (SCM wrapped_obj);                                             \
+  UNWRAP (SCM wrapped_obj, bool assert_type = true);                    \
                                                                         \
   bool                                                                  \
   PRED (SCM wrapped_obj);
   }                                                                     \
                                                                         \
   TYPE                                                                  \
-  UNWRAP (SCM wrapped_obj)                                              \
+  UNWRAP (SCM wrapped_obj, bool assert_type)                            \
   {                                                                     \
-    scm_assert_foreign_object_type (wrapped_##INIT, wrapped_obj);       \
+    if (assert_type)                                                    \
+      {                                                                 \
+        scm_assert_foreign_object_type (wrapped_##INIT, wrapped_obj);   \
+      }                                                                 \
     return (TYPE)scm_foreign_object_ref (wrapped_obj, 0);               \
   }                                                                     \
                                                                         \