From 0cb94da9c4b0cc97e1a6e3452922b78f9f84124e Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 17 Apr 2020 19:29:51 +0200 Subject: [PATCH] Some fixes (beware with pointers casting) --- examples/04.Movement.scm | 14 +++++++------- src/scene-node.cpp | 20 ++++++++++++++++---- src/wrapped.h | 9 +++------ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/examples/04.Movement.scm b/examples/04.Movement.scm index 3850079..e0592c3 100644 --- a/examples/04.Movement.scm +++ b/examples/04.Movement.scm @@ -77,14 +77,14 @@ (define gui-env (get-gui-environment device)) ;; create the node which will be moved with the WSAD keys -(define wall (add-sphere-scene-node! scene-manager)) -(set-position! wall '(0 0 30)) -(set-material-texture! wall 0 (get-texture driver "media/wall.bmp")) -(set-material-flag! wall 'lighting #f) +(define ball (add-sphere-scene-node! scene-manager)) +(set-position! ball '(0 0 30)) +(set-material-texture! ball 0 (get-texture driver "media/wall.bmp")) +(set-material-flag! ball 'lighting #f) ;; create another node, movable using a scene node animator (let ((cube (add-cube-scene-node! scene-manager)) - (anim (create-fly-circle-animator scene-manager #:center '(0 0 30)))) + (anim (create-fly-circle-animator scene-manager #:center '(0 0 30) #:radius 20))) (set-material-texture! cube 0 (get-texture driver "media/t351sml.jpg")) (set-material-flag! cube 'lighting #f) (add-animator! cube anim) @@ -126,7 +126,7 @@ (set! then now) ;; check if W, S, A or D are pressed - (let* ((node-position (get-position wall)) + (let* ((node-position (get-position ball)) (pos-x (car node-position)) (pos-y (cadr node-position)) (pos-z (caddr node-position))) @@ -138,7 +138,7 @@ (set! pos-x (- pos-x (* movement-speed frame-delta-time)))) (if (is-key-down? 'key-d) (set! pos-x (+ pos-x (* movement-speed frame-delta-time)))) - (set-position! wall (list pos-x pos-y pos-z)))) + (set-position! ball (list pos-x pos-y pos-z)))) (begin-scene driver #:color '(255 113 113 133)) (draw-all scene-manager) diff --git a/src/scene-node.cpp b/src/scene-node.cpp index 8b3b561..08c94a8 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -81,10 +81,9 @@ extern "C" { } else { - scm_error (scm_arg_type_key, NULL, "Cannot add animator flag to object: ~S", + scm_error (scm_arg_type_key, NULL, "Cannot add animator to object: ~S", scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); } - return SCM_UNSPECIFIED; } @@ -98,8 +97,21 @@ extern "C" { 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 ()); +#define GET_POSITION(NODE) scm_from_vector3df (NODE->getPosition ()); + + if (scene_node_p (wrapped_scene_node)) + { + return GET_POSITION (unwrap_scene_node (wrapped_scene_node)); + } + else if (mesh_scene_node_p (wrapped_scene_node)) + { + return GET_POSITION (unwrap_mesh_scene_node (wrapped_scene_node)); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get position from object: ~S", + scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node)); + } } SCM diff --git a/src/wrapped.h b/src/wrapped.h index 5ffafb6..daaaa25 100644 --- a/src/wrapped.h +++ b/src/wrapped.h @@ -32,7 +32,7 @@ WRAP (TYPE foreign_obj); \ \ TYPE \ - UNWRAP (SCM wrapped_obj, bool assert_type = true); \ + UNWRAP (SCM wrapped_obj); \ \ bool \ PRED (SCM wrapped_obj); @@ -62,12 +62,9 @@ } \ \ TYPE \ - UNWRAP (SCM wrapped_obj, bool assert_type) \ + UNWRAP (SCM wrapped_obj) \ { \ - if (assert_type) \ - { \ - scm_assert_foreign_object_type (wrapped_##INIT, wrapped_obj); \ - } \ + scm_assert_foreign_object_type (wrapped_##INIT, wrapped_obj); \ return (TYPE)scm_foreign_object_ref (wrapped_obj, 0); \ } \ \ -- 2.39.5