From: Javier Sancho Date: Wed, 15 Apr 2020 10:50:39 +0000 (+0200) Subject: get-position X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=8876c6e31fddf00f9764d9fe73930d8dc8fc6c4a;p=guile-irrlicht.git get-position --- diff --git a/src/cursor-control.cpp b/src/cursor-control.cpp index 5ff6540..1147eab 100644 --- a/src/cursor-control.cpp +++ b/src/cursor-control.cpp @@ -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) diff --git a/src/cursor-control.h b/src/cursor-control.h index d7a4bc5..1d4677c 100644 --- a/src/cursor-control.h +++ b/src/cursor-control.h @@ -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); diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index 29fb2fb..4531715 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -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)); } diff --git a/src/guile-irrlicht.h b/src/guile-irrlicht.h index 5f42bac..c60fddd 100644 --- a/src/guile-irrlicht.h +++ b/src/guile-irrlicht.h @@ -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); diff --git a/src/position2d.cpp b/src/position2d.cpp index 16c44bc..20fb743 100644 --- a/src/position2d.cpp +++ b/src/position2d.cpp @@ -25,6 +25,13 @@ extern "C" { + SCM + scm_from_position2d_s32 (irr::core::position2d position2d) + { + return scm_list_2 (scm_from_int32 (position2d.X), + scm_from_int32 (position2d.Y)); + } + irr::core::position2d scm_to_position2d_f32 (SCM position2d) { diff --git a/src/position2d.h b/src/position2d.h index 2874998..e13555b 100644 --- a/src/position2d.h +++ b/src/position2d.h @@ -27,6 +27,9 @@ extern "C" { + SCM + scm_from_position2d_s32 (irr::core::position2d position2d); + irr::core::position2d scm_to_position2d_f32 (SCM position2d); diff --git a/src/scene-node.cpp b/src/scene-node.cpp index 50d402b..8b3b561 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -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, diff --git a/src/scene-node.h b/src/scene-node.h index 038601f..ca7acc9 100644 --- a/src/scene-node.h +++ b/src/scene-node.h @@ -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, diff --git a/src/wrapped.h b/src/wrapped.h index daaaa25..5ffafb6 100644 --- a/src/wrapped.h +++ b/src/wrapped.h @@ -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); @@ -62,9 +62,12 @@ } \ \ 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); \ } \ \