X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fvideo-driver.cpp;h=9c81120fb97825ad23f422146a0795569705a9bf;hb=d6fd925d118daf71de62200a6c5505fa06917f62;hp=ee80c369e767641caccb23b41e44b48c23e4e1d6;hpb=af6316437363cf85ac844091071bee9b04f58a31;p=guile-irrlicht.git diff --git a/src/video-driver.cpp b/src/video-driver.cpp index ee80c36..9c81120 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -25,9 +25,13 @@ #include "color.h" #include "device.h" #include "gui-environment.h" +#include "material.h" +#include "matrix4.h" +#include "primitive-types.h" #include "rect.h" #include "scene-manager.h" #include "texture.h" +#include "vertex3d.h" #include "video-driver.h" #include "wrapped.h" @@ -38,12 +42,15 @@ extern "C" { { init_video_driver_type (); scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene); + scm_c_define_gsubr ("draw-vertex-primitive-list", 3, 0, 1, + (scm_t_subr)irr_video_drawVertexPrimitiveList); scm_c_define_gsubr ("end-scene", 1, 0, 0, (scm_t_subr)irr_video_endScene); 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_export ("begin-scene", "end-scene", "get-fps", "get-texture", - "get-video-driver", NULL); + scm_c_define_gsubr ("set-transform!", 3, 0, 0, (scm_t_subr)irr_video_setTransform); + scm_c_export ("begin-scene", "draw-vertex-primitive-list", "end-scene", "get-fps", + "get-texture", "get-video-driver", "set-transform!", NULL); } DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver", @@ -85,6 +92,55 @@ extern "C" { sourceRectAddress)); } + SCM + irr_video_drawVertexPrimitiveList (SCM wrapped_video_driver, + SCM vertices, + SCM indices, + SCM rest) + { + SCM v_type = scm_from_utf8_symbol ("standard"); + SCM p_type = scm_from_utf8_symbol ("triangles"); + + scm_c_bind_keyword_arguments ("draw-vertex-primitive-list", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("vertex-type"), &v_type, + scm_from_utf8_keyword ("primitive-type"), &p_type, + SCM_UNDEFINED); + + // Build vertex array + irr::u32 vertex_count = scm_to_uint32 (scm_length (vertices)); + irr::video::S3DVertex s3d_vertices [vertex_count]; + for (int i = 0; i < vertex_count; i++) + { + irr::video::S3DVertex* vertex = unwrap_vertex3d (scm_list_ref (vertices, scm_from_int (i))); + s3d_vertices[i] = irr::video::S3DVertex (vertex->Pos, + vertex->Normal, + vertex->Color, + vertex->TCoords); + } + + // Build index array + irr::u32 index_count = scm_to_uint32 (scm_length (indices)); + SCM flat_indices = scm_apply_0 (scm_eval_string (scm_from_utf8_string ("append")), + indices); + int flat_length = scm_to_int (scm_length (flat_indices)); + irr::u32 c_indices [flat_length]; + for (int i = 0; i < flat_length; i++) + { + c_indices[i] = scm_to_uint32 (scm_list_ref (flat_indices, scm_from_int (i))); + } + + // Draw vertices + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + driver->drawVertexPrimitiveList (&s3d_vertices[0], + vertex_count, + &c_indices[0], + index_count, + scm_to_vertex_type (v_type), + scm_to_primitive_type (p_type), + irr::video::EIT_32BIT); + return SCM_UNSPECIFIED; + } + SCM irr_video_endScene (SCM wrapped_video_driver) { @@ -108,6 +164,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 +200,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)); + } + } + }