From 5e5b0caed972e0b225199551aff09c399edb8d3c Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Tue, 31 Mar 2020 09:15:45 +0200 Subject: [PATCH] set-transform! get-absolute-transformation --- Makefile.am | 2 +- src/color.cpp | 2 +- src/guile-irrlicht.cpp | 105 +++++++++++++++++++++++++- src/{misc.h => guile-irrlicht.h} | 10 ++- src/matrix4.cpp | 77 +++++++++++++++++++ src/matrix4.h | 38 ++++++++++ src/misc.cpp | 123 ------------------------------- src/scene-node.cpp | 13 +++- src/scene-node.h | 3 + src/video-driver.cpp | 64 +++++++++++++++- src/video-driver.h | 12 +++ 11 files changed, 317 insertions(+), 132 deletions(-) rename src/{misc.h => guile-irrlicht.h} (86%) create mode 100644 src/matrix4.cpp create mode 100644 src/matrix4.h delete mode 100644 src/misc.cpp diff --git a/Makefile.am b/Makefile.am index 43eb9c1..0eb3672 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,9 +42,9 @@ libguile_irrlicht_la_SOURCES = \ src/keymap.cpp \ src/material.cpp \ src/material-flags.cpp \ + src/matrix4.cpp \ src/mesh.cpp \ src/mesh-scene-node.cpp \ - src/misc.cpp \ src/position2d.cpp \ src/rect.cpp \ src/reference-counted.cpp \ diff --git a/src/color.cpp b/src/color.cpp index a6879c3..5ed16fe 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -21,7 +21,7 @@ #include #include -#include "rect.h" +#include "color.h" extern "C" { diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index 1bb87cf..35e27f1 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -32,12 +32,12 @@ #include "gui-element.h" #include "gui-environment.h" #include "gui-static-text.h" +#include "guile-irrlicht.h" #include "keymap.h" #include "material.h" #include "material-flags.h" #include "mesh.h" #include "mesh-scene-node.h" -#include "misc.h" #include "reference-counted.h" #include "scene-manager.h" #include "scene-node.h" @@ -45,12 +45,14 @@ #include "texture.h" #include "vertex3d.h" #include "video-driver.h" +#include "wchar.h" extern "C" { void init_guile_irrlicht (void) { + // Init modules init_animated_mesh (); init_animated_mesh_scene_node (); init_box3d (); @@ -67,7 +69,6 @@ extern "C" { init_material_flag (); init_mesh (); init_mesh_scene_node (); - init_misc (); init_reference_counted (); init_scene_manager (); init_scene_node (); @@ -75,6 +76,106 @@ extern "C" { init_texture (); init_vertex3d (); init_video_driver (); + + // Shared procedures (used by two or more objects) + scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_drawAll); + scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName); + scm_c_define_gsubr ("set-material!", 2, 0, 0, (scm_t_subr)irr_setMaterial); + scm_c_define_gsubr ("set-position!", 2, 0, 0, (scm_t_subr)irr_setPosition); + scm_c_define_gsubr ("set-visible!", 2, 0, 0, (scm_t_subr)irr_setVisible); + scm_c_export ("draw-all", "get-name", "set-material!", "set-position!", + "set-visible!", NULL); + } + + SCM + irr_drawAll (SCM wrapped_obj) + { + if (gui_environment_p (wrapped_obj)) + { + unwrap_gui_environment (wrapped_obj)->drawAll (); + } + else if (scene_manager_p (wrapped_obj)) + { + unwrap_scene_manager (wrapped_obj)->drawAll (); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot draw all elements from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + return SCM_UNSPECIFIED; + } + + SCM + irr_getName (SCM wrapped_obj) + { + if (video_driver_p (wrapped_obj)) + { + return scm_from_wide_char_string (unwrap_video_driver (wrapped_obj)->getName ()); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get name from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + + SCM + irr_setMaterial (SCM wrapped_obj, + SCM material) + { + if (video_driver_p (wrapped_obj)) + { + return irr_video_setMaterial (wrapped_obj, material); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set material to object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + + SCM + irr_setPosition (SCM wrapped_obj, + SCM position) + { + if (cursor_control_p (wrapped_obj)) + { + return irr_gui_setPosition (wrapped_obj, position); + } + else if (scene_node_p (wrapped_obj) || mesh_scene_node_p (wrapped_obj)) + { + return irr_scene_setPosition (wrapped_obj, position); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set position for object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + + SCM + irr_setVisible (SCM wrapped_obj, + SCM visible) + { + if (cursor_control_p (wrapped_obj)) + { + unwrap_cursor_control (wrapped_obj)->setVisible (scm_to_bool (visible)); + } + else if (gui_element_p (wrapped_obj)) + { + unwrap_gui_element (wrapped_obj)->setVisible (scm_to_bool (visible)); + } + else if (scene_node_p (wrapped_obj)) + { + unwrap_scene_node (wrapped_obj)->setVisible (scm_to_bool (visible)); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot set visibility for object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + return SCM_UNSPECIFIED; } } diff --git a/src/misc.h b/src/guile-irrlicht.h similarity index 86% rename from src/misc.h rename to src/guile-irrlicht.h index 047512d..52026d7 100644 --- a/src/misc.h +++ b/src/guile-irrlicht.h @@ -19,8 +19,8 @@ . */ -#ifndef __GUILE_IRRLICHT_MISC_H_INCLUDED__ -#define __GUILE_IRRLICHT_MISC_H_INCLUDED__ +#ifndef __GUILE_IRRLICHT_H_INCLUDED__ +#define __GUILE_IRRLICHT_H_INCLUDED__ #include #include @@ -28,7 +28,7 @@ extern "C" { void - init_misc (void); + init_guile_irrlicht (void); SCM irr_drawAll (SCM wrapped_obj); @@ -36,6 +36,10 @@ extern "C" { SCM irr_getName (SCM wrapped_obj); + SCM + irr_setMaterial (SCM wrapped_obj, + SCM material); + SCM irr_setPosition (SCM wrapped_obj, SCM position); diff --git a/src/matrix4.cpp b/src/matrix4.cpp new file mode 100644 index 0000000..2861a0c --- /dev/null +++ b/src/matrix4.cpp @@ -0,0 +1,77 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "matrix4.h" + +extern "C" { + + SCM + scm_from_matrix4 (irr::core::matrix4 cmatrix) + { + return scm_list_4 (scm_list_4 (scm_from_double (cmatrix[0]), + scm_from_double (cmatrix[1]), + scm_from_double (cmatrix[2]), + scm_from_double (cmatrix[3])), + scm_list_4 (scm_from_double (cmatrix[4]), + scm_from_double (cmatrix[5]), + scm_from_double (cmatrix[6]), + scm_from_double (cmatrix[7])), + scm_list_4 (scm_from_double (cmatrix[8]), + scm_from_double (cmatrix[9]), + scm_from_double (cmatrix[10]), + scm_from_double (cmatrix[11])), + scm_list_4 (scm_from_double (cmatrix[12]), + scm_from_double (cmatrix[13]), + scm_from_double (cmatrix[14]), + scm_from_double (cmatrix[15]))); + } + + irr::core::matrix4 + scm_to_matrix4 (SCM matrix) + { + irr::core::matrix4 cmatrix; + + cmatrix[0] = scm_to_double (scm_car (scm_car (matrix))); + cmatrix[1] = scm_to_double (scm_cadr (scm_car (matrix))); + cmatrix[2] = scm_to_double (scm_caddr (scm_car (matrix))); + cmatrix[3] = scm_to_double (scm_cadddr (scm_car (matrix))); + + cmatrix[4] = scm_to_double (scm_car (scm_cadr (matrix))); + cmatrix[5] = scm_to_double (scm_cadr (scm_cadr (matrix))); + cmatrix[6] = scm_to_double (scm_caddr (scm_cadr (matrix))); + cmatrix[7] = scm_to_double (scm_cadddr (scm_cadr (matrix))); + + cmatrix[8] = scm_to_double (scm_car (scm_caddr (matrix))); + cmatrix[9] = scm_to_double (scm_cadr (scm_caddr (matrix))); + cmatrix[10] = scm_to_double (scm_caddr (scm_caddr (matrix))); + cmatrix[11] = scm_to_double (scm_cadddr (scm_caddr (matrix))); + + cmatrix[12] = scm_to_double (scm_car (scm_cadddr (matrix))); + cmatrix[13] = scm_to_double (scm_cadr (scm_cadddr (matrix))); + cmatrix[14] = scm_to_double (scm_caddr (scm_cadddr (matrix))); + cmatrix[15] = scm_to_double (scm_cadddr (scm_cadddr (matrix))); + + return cmatrix; + } + +} diff --git a/src/matrix4.h b/src/matrix4.h new file mode 100644 index 0000000..2653051 --- /dev/null +++ b/src/matrix4.h @@ -0,0 +1,38 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_IRRLICHT_MATRIX4_H_INCLUDED__ +#define __GUILE_IRRLICHT_MATRIX4_H_INCLUDED__ + +#include +#include + +extern "C" { + + SCM + scm_from_matrix4 (irr::core::matrix4 cmatrix); + + irr::core::matrix4 + scm_to_matrix4 (SCM matrix); + +} + +#endif diff --git a/src/misc.cpp b/src/misc.cpp deleted file mode 100644 index 1c01d2c..0000000 --- a/src/misc.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine - - Copyright (C) 2020 Javier Sancho - - This file is part of guile-irrlicht. - - guile-irrlicht is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version. - - guile-irrlicht is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with guile-irrlicht. If not, see - . -*/ - -#include -#include - -#include "cursor-control.h" -#include "gui-element.h" -#include "gui-environment.h" -#include "mesh-scene-node.h" -#include "misc.h" -#include "scene-manager.h" -#include "scene-node.h" -#include "video-driver.h" -#include "wchar.h" - -extern "C" { - - void - init_misc (void) - { - scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_drawAll); - scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName); - scm_c_define_gsubr ("set-position!", 2, 0, 0, (scm_t_subr)irr_setPosition); - scm_c_define_gsubr ("set-visible!", 2, 0, 0, (scm_t_subr)irr_setVisible); - scm_c_export ("draw-all", "get-name", "set-position!", "set-visible!", NULL); - } - - SCM - irr_drawAll (SCM wrapped_obj) - { - if (gui_environment_p (wrapped_obj)) - { - unwrap_gui_environment (wrapped_obj)->drawAll (); - } - else if (scene_manager_p (wrapped_obj)) - { - unwrap_scene_manager (wrapped_obj)->drawAll (); - } - else - { - scm_error (scm_arg_type_key, NULL, "Cannot draw all elements from object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); - } - return SCM_UNSPECIFIED; - } - - SCM - irr_getName (SCM wrapped_obj) - { - if (video_driver_p (wrapped_obj)) - { - return scm_from_wide_char_string (unwrap_video_driver (wrapped_obj)->getName ()); - } - else - { - scm_error (scm_arg_type_key, NULL, "Cannot get name from object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); - } - } - - SCM - irr_setPosition (SCM wrapped_obj, - SCM position) - { - if (cursor_control_p (wrapped_obj)) - { - return irr_gui_setPosition (wrapped_obj, position); - } - else if (scene_node_p (wrapped_obj) || mesh_scene_node_p (wrapped_obj)) - { - return irr_scene_setPosition (wrapped_obj, position); - } - else - { - scm_error (scm_arg_type_key, NULL, "Cannot set position for object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); - } - } - - SCM - irr_setVisible (SCM wrapped_obj, - SCM visible) - { - if (cursor_control_p (wrapped_obj)) - { - unwrap_cursor_control (wrapped_obj)->setVisible (scm_to_bool (visible)); - } - else if (gui_element_p (wrapped_obj)) - { - unwrap_gui_element (wrapped_obj)->setVisible (scm_to_bool (visible)); - } - else if (scene_node_p (wrapped_obj)) - { - unwrap_scene_node (wrapped_obj)->setVisible (scm_to_bool (visible)); - } - else - { - scm_error (scm_arg_type_key, NULL, "Cannot set visibility for object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); - } - return SCM_UNSPECIFIED; - } - -} diff --git a/src/scene-node.cpp b/src/scene-node.cpp index c92c2d5..684ad3f 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -23,6 +23,7 @@ #include #include "animated-mesh-scene-node.h" +#include "matrix4.h" #include "mesh-scene-node.h" #include "scene-node.h" #include "scene-node-animator.h" @@ -37,8 +38,11 @@ extern "C" { { init_scene_node_type (); scm_c_define_gsubr ("add-animator!", 2, 0, 0, (scm_t_subr)irr_scene_addAnimator); + scm_c_define_gsubr ("get-absolute-transformation", 1, 0, 0, + (scm_t_subr)irr_scene_getAbsoluteTransformation); scm_c_define_gsubr ("set-material-texture!", 3, 0, 0, (scm_t_subr)irr_scene_setMaterialTexture); - scm_c_export ("add-animator!", "set-material-texture!", NULL); + scm_c_export ("add-animator!", "get-absolute-transformation", + "set-material-texture!", NULL); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneNode*, "scene-node", @@ -54,6 +58,13 @@ extern "C" { 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 ()); + } + SCM irr_scene_setMaterialTexture (SCM wrapped_scene_node, SCM texture_layer, diff --git a/src/scene-node.h b/src/scene-node.h index 4aab1e1..660cc86 100644 --- a/src/scene-node.h +++ b/src/scene-node.h @@ -38,6 +38,9 @@ extern "C" { irr_scene_addAnimator (SCM wrapped_scene_node, SCM animator); + SCM + irr_scene_getAbsoluteTransformation (SCM wrapped_scene_node); + SCM irr_scene_setMaterialTexture (SCM wrapped_scene_node, SCM texture_layer, diff --git a/src/video-driver.cpp b/src/video-driver.cpp index ee80c36..aa63e52 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -25,6 +25,8 @@ #include "color.h" #include "device.h" #include "gui-environment.h" +#include "material.h" +#include "matrix4.h" #include "rect.h" #include "scene-manager.h" #include "texture.h" @@ -42,8 +44,9 @@ extern "C" { scm_c_define_gsubr ("get-fps", 1, 0, 0, (scm_t_subr)irr_video_getFPS); scm_c_define_gsubr ("get-texture", 2, 0, 0, (scm_t_subr)irr_video_getTexture); scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver); + scm_c_define_gsubr ("set-transform!", 3, 0, 0, (scm_t_subr)irr_video_setTransform); scm_c_export ("begin-scene", "end-scene", "get-fps", "get-texture", - "get-video-driver", NULL); + "get-video-driver", "set-transform!", NULL); } DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver", @@ -108,6 +111,26 @@ extern "C" { return wrap_texture (texture); } + SCM + irr_video_setMaterial (SCM wrapped_video_driver, + SCM material) + { + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + driver->setMaterial (*(unwrap_material (material))); + return SCM_UNSPECIFIED; + } + + SCM + irr_video_setTransform (SCM wrapped_video_driver, + SCM state, + SCM mat) + { + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + driver->setTransform (scm_to_transformation_state (state), + scm_to_matrix4 (mat)); + return SCM_UNSPECIFIED; + } + SCM irr_getVideoDriver (SCM wrapped_obj) { @@ -124,4 +147,43 @@ extern "C" { return wrap_video_driver (driver); } + irr::video::E_TRANSFORMATION_STATE + scm_to_transformation_state (SCM transformation_state) + { + char* state = scm_to_utf8_stringn (scm_symbol_to_string (transformation_state), NULL); + if (!strcmp (state, "view")) + { + return irr::video::ETS_VIEW; + } + else if (!strcmp (state, "world")) + { + return irr::video::ETS_WORLD; + } + else if (!strcmp (state, "projection")) + { + return irr::video::ETS_PROJECTION; + } + else if (!strcmp (state, "texture0")) + { + return irr::video::ETS_TEXTURE_0; + } + else if (!strcmp (state, "texture1")) + { + return irr::video::ETS_TEXTURE_1; + } + else if (!strcmp (state, "texture2")) + { + return irr::video::ETS_TEXTURE_2; + } + else if (!strcmp (state, "texture3")) + { + return irr::video::ETS_TEXTURE_3; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong transformation state: ~S", + scm_list_1 (transformation_state), scm_list_1 (transformation_state)); + } + } + } diff --git a/src/video-driver.h b/src/video-driver.h index 2560135..d697e5b 100644 --- a/src/video-driver.h +++ b/src/video-driver.h @@ -48,9 +48,21 @@ extern "C" { irr_video_getTexture (SCM wrapped_video_driver, SCM filename); + SCM + irr_video_setMaterial (SCM wrapped_video_driver, + SCM material); + + SCM + irr_video_setTransform (SCM wrapped_video_driver, + SCM state, + SCM mat); + SCM irr_getVideoDriver (SCM wrapped_obj); + irr::video::E_TRANSFORMATION_STATE + scm_to_transformation_state (SCM transformation_state); + } #endif -- 2.39.5