From 37217d692d4ead81cfed829395a9a7a5caf9325c Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 27 Mar 2020 08:50:24 +0100 Subject: [PATCH] box3d-reset! vertex3d-position --- Makefile.am | 2 +- examples/03.CustomSceneNode.scm | 18 ++++++++-------- src/{aabbox3d.cpp => box3d.cpp} | 38 ++++++++++++++++----------------- src/{aabbox3d.h => box3d.h} | 14 ++++++------ src/guile-irrlicht.cpp | 6 +++--- src/vector3d.cpp | 8 +++++++ src/vector3d.h | 3 +++ src/vertex3d.cpp | 9 +++++++- src/vertex3d.h | 3 +++ 9 files changed, 59 insertions(+), 42 deletions(-) rename src/{aabbox3d.cpp => box3d.cpp} (51%) rename src/{aabbox3d.h => box3d.h} (75%) diff --git a/Makefile.am b/Makefile.am index 1e1e331..b2fc266 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,10 +23,10 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libguile-irrlicht.la libguile_irrlicht_la_SOURCES = \ - src/aabbox3d.cpp \ src/animated-mesh.cpp \ src/animated-mesh-md2.cpp \ src/animated-mesh-scene-node.cpp \ + src/box3d.cpp \ src/camera-scene-node.cpp \ src/color.cpp \ src/cursor-control.cpp \ diff --git a/examples/03.CustomSceneNode.scm b/examples/03.CustomSceneNode.scm index 1c0d656..11869fb 100644 --- a/examples/03.CustomSceneNode.scm +++ b/examples/03.CustomSceneNode.scm @@ -67,7 +67,7 @@ #:lookat '(0 0 0)) ;; create our custom scene node -(define box (make-aabbox3df)) +(define box (make-box3d)) (define vertices (list (make-vertex3d '(0 0 10) '(1 1 0) '(255 0 255 255) '(0 1)) (make-vertex3d '(10 0 -10) '(1 0 0) '(255 255 0 255) '(1 1)) @@ -75,17 +75,17 @@ (make-vertex3d '(-10 0 -10) '(0 0 1) '(255 0 255 0) '(0 0)))) (define material (make-material #:wireframe #f #:lighting #f)) -(aabbox3d-reset! box (vertex-position (car vertices))) -(for-each (lambda (vertex) - (aabbox3d-add-internal-point! box (vertex-position vertex))) - (cdr vertices)) +(box3d-reset! box (vertex3d-position (car vertices))) +(for-each + (lambda (vertex) + (aabbox3d-add-internal-point! box (vertex3d-position vertex))) + (cdr vertices)) (define (custom-render) (let ((indices '((0 2 3) (2 1 3) (1 0 3) (2 0 1)))) - ;;(set-material! driver material) - ;;(set-transform! driver 'world (get-absolute-transformation my-node)) - ;;(draw-vertex-primitive-list driver vertices indices))) - #f)) + (set-material! driver material) + (set-transform! driver 'world (get-absolute-transformation my-node)) + (draw-vertex-primitive-list driver vertices indices))) (define (custom-get-bounding-box) box) diff --git a/src/aabbox3d.cpp b/src/box3d.cpp similarity index 51% rename from src/aabbox3d.cpp rename to src/box3d.cpp index 47a7eb2..ee5c65b 100644 --- a/src/aabbox3d.cpp +++ b/src/box3d.cpp @@ -21,41 +21,39 @@ #include #include -#include "aabbox3d.h" +#include "box3d.h" +#include "vector3d.h" #include "wrapped.h" extern "C" { void - init_aabbox3d (void) + init_box3d (void) { - init_aabbox3df_type (); - init_aabbox3di_type (); - scm_c_define_gsubr ("make-aabbox3df", 0, 0, 0, (scm_t_subr)make_aabbox3df); - scm_c_define_gsubr ("make-aabbox3di", 0, 0, 0, (scm_t_subr)make_aabbox3di); - scm_c_export ("make-aabbox3df", "make-aabbox3di", NULL); + init_box3d_type (); + scm_c_define_gsubr ("box3d-reset!", 2, 0, 0, (scm_t_subr)box3d_reset); + scm_c_define_gsubr ("make-box3d", 0, 0, 0, (scm_t_subr)make_box3d); + scm_c_export ("box3d-reset!", "make-box3d", NULL); } - DEFINE_WRAPPED_TYPE (irr::core::aabbox3df*, "aabbox3df", - init_aabbox3df_type, aabbox3df_p, - wrap_aabbox3df, unwrap_aabbox3df); - - DEFINE_WRAPPED_TYPE (irr::core::aabbox3di*, "aabbox3di", - init_aabbox3di_type, aabbox3di_p, - wrap_aabbox3di, unwrap_aabbox3di); + DEFINE_WRAPPED_TYPE (irr::core::aabbox3df*, "box3d", + init_box3d_type, box3d_p, + wrap_box3d, unwrap_box3d); SCM - make_aabbox3df () + box3d_reset (SCM box3d, + SCM init_value) { - irr::core::aabbox3df* box = new irr::core::aabbox3df (); - return wrap_aabbox3df (box); + irr::core::aabbox3df* aabbox = unwrap_box3d (box3d); + aabbox->reset (scm_to_vector3df (init_value)); + return SCM_UNSPECIFIED; } SCM - make_aabbox3di () + make_box3d () { - irr::core::aabbox3di* box = new irr::core::aabbox3di (); - return wrap_aabbox3di (box); + irr::core::aabbox3df* aabbox = new irr::core::aabbox3df (); + return wrap_box3d (aabbox); } } diff --git a/src/aabbox3d.h b/src/box3d.h similarity index 75% rename from src/aabbox3d.h rename to src/box3d.h index 8dda8d3..8ed47f5 100644 --- a/src/aabbox3d.h +++ b/src/box3d.h @@ -29,19 +29,17 @@ extern "C" { void - init_aabbox3d (void); + init_box3d (void); - DECLARE_WRAPPED_TYPE (irr::core::aabbox3df*, init_aabbox3df_type, - aabbox3df_p, wrap_aabbox3df, unwrap_aabbox3df); - - DECLARE_WRAPPED_TYPE (irr::core::aabbox3di*, init_aabbox3di_type, - aabbox3di_p, wrap_aabbox3di, unwrap_aabbox3di); + DECLARE_WRAPPED_TYPE (irr::core::aabbox3df*, init_box3d_type, + box3d_p, wrap_box3d, unwrap_box3d); SCM - make_aabbox3df (); + box3d_reset (SCM box3d, + SCM init_value); SCM - make_aabbox3di (); + make_box3d (); } diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index c825029..6e7a937 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -21,9 +21,9 @@ #include -#include "aabbox3d.h" #include "animated-mesh.h" #include "animated-mesh-scene-node.h" +#include "box3d.h" #include "camera-scene-node.h" #include "cursor-control.h" #include "device.h" @@ -50,10 +50,9 @@ extern "C" { void init_guile_irrlicht (void) { - init_vertex3d (); - init_aabbox3d (); init_animated_mesh (); init_animated_mesh_scene_node (); + init_box3d (); init_camera_scene_node (); init_cursor_control (); init_device (); @@ -72,6 +71,7 @@ extern "C" { init_scene_manager (); init_scene_node (); init_texture (); + init_vertex3d (); init_video_driver (); } diff --git a/src/vector3d.cpp b/src/vector3d.cpp index 85f5bf8..57f5a7d 100644 --- a/src/vector3d.cpp +++ b/src/vector3d.cpp @@ -25,6 +25,14 @@ extern "C" { + SCM + scm_from_vector3df (irr::core::vector3df vector3d) + { + return scm_list_3 (scm_from_double (vector3d.X), + scm_from_double (vector3d.Y), + scm_from_double (vector3d.Z)); + } + irr::core::vector3df scm_to_vector3df (SCM vector3d) { diff --git a/src/vector3d.h b/src/vector3d.h index bc7c9f0..c2834ca 100644 --- a/src/vector3d.h +++ b/src/vector3d.h @@ -27,6 +27,9 @@ extern "C" { + SCM + scm_from_vector3df (irr::core::vector3df vector3d); + irr::core::vector3df scm_to_vector3df (SCM vector3d); diff --git a/src/vertex3d.cpp b/src/vertex3d.cpp index 07a85b9..27bf941 100644 --- a/src/vertex3d.cpp +++ b/src/vertex3d.cpp @@ -34,7 +34,8 @@ extern "C" { { init_vertex3d_type (); scm_c_define_gsubr ("make-vertex3d", 4, 0, 0, (scm_t_subr)make_vertex3d); - scm_c_export ("make-vertex3d", NULL); + scm_c_define_gsubr ("vertex3d-position", 1, 0, 0, (scm_t_subr)vertex3d_position); + scm_c_export ("make-vertex3d", "vertex3d-position", NULL); } DEFINE_WRAPPED_TYPE (irr::video::S3DVertex*, "vertex3d", @@ -55,4 +56,10 @@ extern "C" { return wrap_vertex3d (vertex); } + SCM + vertex3d_position (SCM vertex) { + irr::video::S3DVertex* s3dvertex = unwrap_vertex3d (vertex); + return scm_from_vector3df (s3dvertex->Pos); + } + } diff --git a/src/vertex3d.h b/src/vertex3d.h index 4ce2c52..4c033d3 100644 --- a/src/vertex3d.h +++ b/src/vertex3d.h @@ -40,6 +40,9 @@ extern "C" { SCM color, SCM tcoords); + SCM + vertex3d_position (SCM vertex); + } #endif -- 2.39.5