]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
Some fixes (beware with pointers casting)
authorJavier Sancho <jsf@jsancho.org>
Fri, 17 Apr 2020 17:29:51 +0000 (19:29 +0200)
committerJavier Sancho <jsf@jsancho.org>
Fri, 17 Apr 2020 17:29:51 +0000 (19:29 +0200)
examples/04.Movement.scm
src/scene-node.cpp
src/wrapped.h

index 385007924e09e2185d7e0500e2aaa21f7d66b45f..e0592c3645f93c65b4d64113249b4af6748a535a 100644 (file)
 (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)
         (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)))
               (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)
index 8b3b561902674b8114157969c30fe1d94bfcaa44..08c94a8f48be3464aac40f2fc87ac625964c8c9f 100644 (file)
@@ -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
index 5ffafb6745c10f3ece617a9d4dd7fe3c527774c4..daaaa25404d07c95e32fd71f7e6d7a927e100353 100644 (file)
@@ -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);
   }                                                                     \
                                                                         \
   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);               \
   }                                                                     \
                                                                         \