]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
scene-node
authorJavier Sancho <jsf@jsancho.org>
Sun, 10 May 2020 10:57:14 +0000 (12:57 +0200)
committerJavier Sancho <jsf@jsancho.org>
Sun, 10 May 2020 10:57:14 +0000 (12:57 +0200)
src/scene-node.cpp
src/scene-node.h

index 08c94a8f48be3464aac40f2fc87ac625964c8c9f..d8fcd0d3b9a05b3c503b600ee1d02840df245b59 100644 (file)
 
 #include <irrlicht/irrlicht.h>
 #include <libguile.h>
-
-#include "animated-mesh-scene-node.h"
-#include "camera-scene-node.h"
 #include "gsubr.h"
 #include "material-flags.h"
 #include "matrix4.h"
-#include "mesh-scene-node.h"
 #include "scene-node.h"
-#include "scene-node-animator.h"
-#include "texture.h"
 #include "vector3d.h"
-#include "wrapped.h"
 
-extern "C" {
 
-  void
-  init_scene_node (void)
-  {
-    init_scene_node_type ();
-    DEFINE_GSUBR ("add-animator!", 2, 0, 0, irr_scene_addAnimator);
-    DEFINE_GSUBR ("get-absolute-transformation", 1, 0, 0, irr_scene_getAbsoluteTransformation);
-    DEFINE_GSUBR ("set-material-texture!", 3, 0, 0, irr_scene_setMaterialTexture);
-    DEFINE_GSUBR ("set-rotation!", 2, 0, 0, irr_scene_setRotation);
-    DEFINE_GSUBR ("set-scale!", 2, 0, 0, irr_scene_setScale);
-  }
+using namespace irr;
 
-  DEFINE_WRAPPED_TYPE (irr::scene::ISceneNode*, "scene-node",
-                       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);
-  }
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_addAnimator (SCM scene_node,
+                              SCM animator)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  node->addAnimator (unwrap_scene_node_animator (animator));
+  return SCM_UNSPECIFIED;
+}
 
-  SCM
-  irr_scene_addAnimator (SCM wrapped_scene_node,
-                         SCM animator)
-  {
-#define ADD_ANIMATOR(NODE) NODE->addAnimator (unwrap_scene_node_animator (animator));
-
-    if (animated_mesh_scene_node_p (wrapped_scene_node))
-      {
-        ADD_ANIMATOR (unwrap_animated_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (mesh_scene_node_p (wrapped_scene_node))
-      {
-        ADD_ANIMATOR (unwrap_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (scene_node_p (wrapped_scene_node))
-      {
-        ADD_ANIMATOR (unwrap_scene_node (wrapped_scene_node));
-      }
-    else
-      {
-        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;
-  }
 
-  SCM
-  irr_scene_getAbsoluteTransformation (SCM wrapped_scene_node)
-  {
-    irr::scene::ISceneNode* node = unwrap_scene_node (wrapped_scene_node);
-    return scm_from_matrix4 (node->getAbsoluteTransformation ());
-  }
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_getAbsoluteTransformation (SCM scene_node)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  return scm_from_matrix4 (node->getAbsoluteTransformation ());
+}
 
-  SCM
-  irr_scene_getPosition (SCM wrapped_scene_node)
-  {
-#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
-  irr_scene_ISceneNode_setMaterialFlag (SCM wrapped_scene_node,
-                                        SCM flag,
-                                        SCM newvalue)
-  {
-#define SET_MATERIAL_FLAG(NODE) NODE->setMaterialFlag (scm_to_material_flag (flag), \
-                                                       scm_to_bool (newvalue));
-
-    if (animated_mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_MATERIAL_FLAG (unwrap_animated_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_MATERIAL_FLAG (unwrap_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (scene_node_p (wrapped_scene_node))
-      {
-        SET_MATERIAL_FLAG (unwrap_scene_node (wrapped_scene_node));
-      }
-    else
-      {
-        scm_error (scm_arg_type_key, NULL, "Cannot set material flag to object: ~S",
-                   scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
-      }
-
-    return SCM_UNSPECIFIED;
-  }
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_getPosition (SCM scene_node)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  return scm_from_vector3df (node->getPosition ());
+}
 
-  SCM
-  irr_scene_setMaterialTexture (SCM wrapped_scene_node,
-                                SCM texture_layer,
-                                SCM texture)
-  {
-#define SET_MATERIAL_TEXTURE(NODE) NODE->setMaterialTexture (scm_to_uint32 (texture_layer), \
-                                                             unwrap_texture (texture));
-
-    if (animated_mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_MATERIAL_TEXTURE (unwrap_animated_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_MATERIAL_TEXTURE (unwrap_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (scene_node_p (wrapped_scene_node))
-      {
-        SET_MATERIAL_TEXTURE (unwrap_scene_node (wrapped_scene_node));
-      }
-    else
-      {
-        scm_error (scm_arg_type_key, NULL, "Cannot set material texture to object: ~S",
-                   scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
-      }
-
-    return SCM_UNSPECIFIED;
-  }
 
-  SCM
-  irr_scene_setPosition (SCM wrapped_scene_node,
-                         SCM position)
-  {
-#define SET_POSITION(NODE) NODE->setPosition (scm_to_vector3df (position));
-
-    if (scene_node_p (wrapped_scene_node))
-      {
-        SET_POSITION (unwrap_scene_node (wrapped_scene_node));
-      }
-    else if (mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_POSITION (unwrap_mesh_scene_node (wrapped_scene_node));
-      }
-    else
-      {
-        scm_error (scm_arg_type_key, NULL, "Cannot set position to object: ~S",
-                   scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
-      }
-
-    return SCM_UNSPECIFIED;
-  }
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_setMaterialFlag (SCM scene_node,
+                                  SCM flag,
+                                  SCM newvalue)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  node->setMaterialFlag (scm_to_material_flag (flag), scm_to_bool (newvalue));
+  return SCM_UNSPECIFIED;
+}
+
+
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_setMaterialTexture (SCM scene_node,
+                                     SCM texture_layer,
+                                     SCM texture)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  node->setMaterialTexture (scm_to_uint32 (texture_layer),
+                            (video::ITexture*) scm_to_pointer (texture));
+  return SCM_UNSPECIFIED;
+}
+
+
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_setPosition (SCM scene_node,
+                              SCM position)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  node->setPosition (scm_to_vector3df (position));
+  return SCM_UNSPECIFIED;
+}
 
-  SCM
-  irr_scene_setRotation (SCM wrapped_scene_node,
-                         SCM rotation)
-  {
-#define SET_ROTATION(NODE) NODE->setRotation (scm_to_vector3df (rotation));
-
-    if (animated_mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_ROTATION (unwrap_animated_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (camera_scene_node_p (wrapped_scene_node))
-      {
-        SET_ROTATION (unwrap_camera_scene_node (wrapped_scene_node));
-      }
-    else if (scene_node_p (wrapped_scene_node))
-      {
-        SET_ROTATION (unwrap_scene_node (wrapped_scene_node));
-      }
-    else
-      {
-        scm_error (scm_arg_type_key, NULL, "Cannot set rotation to object: ~S",
-                   scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
-      }
-
-    return SCM_UNSPECIFIED;
-  }
 
-  SCM
-  irr_scene_setScale (SCM wrapped_scene_node,
-                      SCM scale)
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_setRotation (SCM scene_node,
+                              SCM rotation)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  node->setRotation (scm_to_vector3df (rotation));
+  return SCM_UNSPECIFIED;
+}
+
+
+template <typename TSceneNode>
+SCM
+scene_ISceneNode_setScale (SCM scene_node,
+                           SCM scale)
+{
+  TSceneNode node = (TSceneNode) scm_to_pointer (scene_node);
+  node->setScale (scm_to_vector3df (scale));
+  return SCM_UNSPECIFIED;
+}
+
+
+extern "C" {
+
+  void
+  init_scene_node (void)
   {
-#define SET_SCALE(NODE) NODE->setScale (scm_to_vector3df (scale));
-
-    if (animated_mesh_scene_node_p (wrapped_scene_node))
-      {
-        SET_SCALE (unwrap_animated_mesh_scene_node (wrapped_scene_node));
-      }
-    else if (scene_node_p (wrapped_scene_node))
-      {
-        SET_SCALE (unwrap_scene_node (wrapped_scene_node));
-      }
-    else
-      {
-        scm_error (scm_arg_type_key, NULL, "Cannot set scale to object: ~S",
-                   scm_list_1 (wrapped_scene_node), scm_list_1 (wrapped_scene_node));
-      }
-
-    return SCM_UNSPECIFIED;
+    DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_addAnimator", 2, 0, 0,
+                  scene_ISceneNode_addAnimator<scene::IAnimatedMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_IMeshSceneNode_addAnimator", 2, 0, 0,
+                  scene_ISceneNode_addAnimator<scene::IMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_addAnimator", 2, 0, 0,
+                  scene_ISceneNode_addAnimator<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_ISceneNode_getAbsoluteTransformation", 1, 0, 0,
+                  scene_ISceneNode_getAbsoluteTransformation<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_IMeshSceneNode_getPosition", 1, 0, 0,
+                  scene_ISceneNode_getPosition<scene::IMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_getPosition", 1, 0, 0,
+                  scene_ISceneNode_getPosition<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setMaterialFlag", 3, 0, 0,
+                  scene_ISceneNode_setMaterialFlag<scene::IAnimatedMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_IMeshSceneNode_setMaterialFlag", 3, 0, 0,
+                  scene_ISceneNode_setMaterialFlag<scene::IMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_setMaterialFlag", 3, 0, 0,
+                  scene_ISceneNode_setMaterialFlag<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setMaterialTexture", 3, 0, 0,
+                  scene_ISceneNode_setMaterialTexture<scene::IAnimatedMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_IMeshSceneNode_setMaterialTexture", 3, 0, 0,
+                  scene_ISceneNode_setMaterialTexture<scene::IMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_setMaterialTexture", 3, 0, 0,
+                  scene_ISceneNode_setMaterialTexture<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_IMeshSceneNode_setPosition", 2, 0, 0,
+                  scene_ISceneNode_setPosition<scene::IMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_setPosition", 2, 0, 0,
+                  scene_ISceneNode_setPosition<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setRotation", 2, 0, 0,
+                  scene_ISceneNode_setRotation<scene::IAnimatedMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ICameraSceneNode_setRotation", 2, 0, 0,
+                  scene_ISceneNode_setRotation<scene::ICameraSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_setRotation", 2, 0, 0,
+                  scene_ISceneNode_setRotation<scene::ISceneNode*>);
+
+    DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setScale", 2, 0, 0,
+                  scene_ISceneNode_setScale<scene::IAnimatedMeshSceneNode*>);
+    DEFINE_GSUBR ("scene_ISceneNode_setScale", 2, 0, 0,
+                  scene_ISceneNode_setScale<scene::ISceneNode*>);
   }
 
 }
index ca7acc9f7c03ffadd7e35e80253bcad91d91814b..0ff17be556c435cab2c59aff5af9990200fb6549 100644 (file)
 #ifndef __GUILE_IRRLICHT_SCENE_NODE_H_INCLUDED__
 #define __GUILE_IRRLICHT_SCENE_NODE_H_INCLUDED__
 
-#include <irrlicht/irrlicht.h>
-#include <libguile.h>
-#include "wrapped.h"
-
 extern "C" {
-
   void
   init_scene_node (void);
-
-  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);
-
-  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,
-                                        SCM newvalue);
-
-  SCM
-  irr_scene_setMaterialTexture (SCM wrapped_scene_node,
-                                SCM texture_layer,
-                                SCM texture);
-
-  SCM
-  irr_scene_setPosition (SCM wrapped_scene_node,
-                         SCM position);
-
-  SCM
-  irr_scene_setRotation (SCM wrapped_scene_node,
-                         SCM rotation);
-
-  SCM
-  irr_scene_setScale (SCM wrapped_scene_node,
-                      SCM scale);
-
 }
 
 #endif