From 2cca3297e02be62c3a5c7aacb5e90d35fe1b1588 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sun, 10 May 2020 12:57:14 +0200 Subject: [PATCH] scene-node --- src/scene-node.cpp | 333 ++++++++++++++++++--------------------------- src/scene-node.h | 44 ------ 2 files changed, 129 insertions(+), 248 deletions(-) diff --git a/src/scene-node.cpp b/src/scene-node.cpp index 08c94a8..d8fcd0d 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -21,228 +21,153 @@ #include #include - -#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 +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 +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 +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 +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 +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 +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 +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 +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); + DEFINE_GSUBR ("scene_IMeshSceneNode_addAnimator", 2, 0, 0, + scene_ISceneNode_addAnimator); + DEFINE_GSUBR ("scene_ISceneNode_addAnimator", 2, 0, 0, + scene_ISceneNode_addAnimator); + + DEFINE_GSUBR ("scene_ISceneNode_getAbsoluteTransformation", 1, 0, 0, + scene_ISceneNode_getAbsoluteTransformation); + + DEFINE_GSUBR ("scene_IMeshSceneNode_getPosition", 1, 0, 0, + scene_ISceneNode_getPosition); + DEFINE_GSUBR ("scene_ISceneNode_getPosition", 1, 0, 0, + scene_ISceneNode_getPosition); + + DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setMaterialFlag", 3, 0, 0, + scene_ISceneNode_setMaterialFlag); + DEFINE_GSUBR ("scene_IMeshSceneNode_setMaterialFlag", 3, 0, 0, + scene_ISceneNode_setMaterialFlag); + DEFINE_GSUBR ("scene_ISceneNode_setMaterialFlag", 3, 0, 0, + scene_ISceneNode_setMaterialFlag); + + DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setMaterialTexture", 3, 0, 0, + scene_ISceneNode_setMaterialTexture); + DEFINE_GSUBR ("scene_IMeshSceneNode_setMaterialTexture", 3, 0, 0, + scene_ISceneNode_setMaterialTexture); + DEFINE_GSUBR ("scene_ISceneNode_setMaterialTexture", 3, 0, 0, + scene_ISceneNode_setMaterialTexture); + + DEFINE_GSUBR ("scene_IMeshSceneNode_setPosition", 2, 0, 0, + scene_ISceneNode_setPosition); + DEFINE_GSUBR ("scene_ISceneNode_setPosition", 2, 0, 0, + scene_ISceneNode_setPosition); + + DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setRotation", 2, 0, 0, + scene_ISceneNode_setRotation); + DEFINE_GSUBR ("scene_ICameraSceneNode_setRotation", 2, 0, 0, + scene_ISceneNode_setRotation); + DEFINE_GSUBR ("scene_ISceneNode_setRotation", 2, 0, 0, + scene_ISceneNode_setRotation); + + DEFINE_GSUBR ("scene_IAnimatedMeshSceneNode_setScale", 2, 0, 0, + scene_ISceneNode_setScale); + DEFINE_GSUBR ("scene_ISceneNode_setScale", 2, 0, 0, + scene_ISceneNode_setScale); } } diff --git a/src/scene-node.h b/src/scene-node.h index ca7acc9..0ff17be 100644 --- a/src/scene-node.h +++ b/src/scene-node.h @@ -22,53 +22,9 @@ #ifndef __GUILE_IRRLICHT_SCENE_NODE_H_INCLUDED__ #define __GUILE_IRRLICHT_SCENE_NODE_H_INCLUDED__ -#include -#include -#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 -- 2.39.5