]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - irrlicht/scene.scm
begin-scene
[guile-irrlicht.git] / irrlicht / scene.scm
index 7e9b8d23dddcc1cc7d22c2503600e5cb009d7e59..115d2e856a5d6477ef57435715b5516cacc0b8bd 100644 (file)
 
 
 (define-module (irrlicht scene)
-  #:use-module (ice-9 match)
-  #:use-module (system foreign)
-  #:use-module ((irrlicht bindings core) #:prefix ffi-core:)
-  #:use-module ((irrlicht bindings scene) #:prefix ffi-scene:)
-  #:use-module ((irrlicht bindings video) #:prefix ffi-video:)
-  #:use-module (irrlicht util)
-  #:export (add-animated-mesh-scene-node
+  #:export (add-animated-mesh-scene-node!
             add-camera-scene-node!
-            add-camera-scene-node-fps!
-            add-custom-scene-node!
-            add-octree-scene-node
             get-mesh
-            get-root-scene-node
-            scene-draw-all
             set-material-flag!
             set-material-texture!
-            set-md2-animation!
-            set-position!))
-
-(define* (add-animated-mesh-scene-node scene-manager mesh
-                                       #:key
-                                       (parent %null-pointer)
-                                       (id -1)
-                                       (position '(0 0 0))
-                                       (rotation '(0 0 0))
-                                       (scale '(1 1 1))
-                                       (also-add-if-mesh-pointer-zero #f))
-  (let ((node (ffi-scene:add-animated-mesh-scene-node
-               scene-manager
-               mesh
-               parent
-               id
-               (ffi-core:vector3df->pointer position)
-               (ffi-core:vector3df->pointer rotation)
-               (ffi-core:vector3df->pointer scale)
-               (bool->integer also-add-if-mesh-pointer-zero))))
-    (if (null-pointer? node) #f node)))
-
+            set-md2-animation!))
+
+(load-extension "libguile-irrlicht" "init_guile_irrlicht")
+
+(define irr-add-animated-mesh-scene-node! add-animated-mesh-scene-node!)
+(define* (add-animated-mesh-scene-node! scene-manager mesh
+                                        #:key
+                                        (parent #f)
+                                        (id -1)
+                                        (position '(0 0 0))
+                                        (rotation '(0 0 0))
+                                        (scale '(1 1 1))
+                                        (also-add-if-mesh-pointer-zero #f))
+  (irr-add-animated-mesh-scene-node! scene-manager
+                                     mesh
+                                     parent
+                                     id
+                                     position
+                                     rotation
+                                     scale
+                                     also-add-if-mesh-pointer-zero))
+
+(define irr-add-camera-scene-node! add-camera-scene-node!)
 (define* (add-camera-scene-node! scene-manager
                                  #:key
-                                 (parent %null-pointer)
+                                 (parent #f)
                                  (position '(0 0 0))
                                  (lookat '(0 0 100))
                                  (id -1)
                                  (make-active #t))
-  (let ((camera (ffi-scene:add-camera-scene-node
-                 scene-manager
-                 parent
-                 (ffi-core:vector3df->pointer position)
-                 (ffi-core:vector3df->pointer lookat)
-                 id
-                 (bool->integer make-active))))
-    (if (null-pointer? camera) #f camera)))
-
-(define* (add-camera-scene-node-fps! scene-manager
-                                     #:key
-                                     (parent %null-pointer)
-                                     (rotate-speed 100.0)
-                                     (move-speed 0.5)
-                                     (id -1)
-                                     (key-map-array %null-pointer)
-                                     (key-map-size 0)
-                                     (no-vertical-movement #f)
-                                     (jump-speed 0.0)
-                                     (invert-mouse #f)
-                                     (make-active #t))
-  (ffi-scene:add-camera-scene-node-fps
-   scene-manager
-   parent
-   rotate-speed
-   move-speed
-   id
-   key-map-array
-   key-map-size
-   (bool->integer no-vertical-movement)
-   jump-speed
-   (bool->integer invert-mouse)
-   (bool->integer make-active)))
-
-(define* (add-custom-scene-node! scene-manager
-                                 render
-                                 get-bounding-box
-                                 get-material-count
-                                 get-material
-                                 #:key
-                                 (parent %null-pointer)
-                                 (id -1)
-                                 (position '(0 0 0))
-                                 (rotation '(0 0 0))
-                                 (scale '(1 1 1)))
-  (let ((c-get-bounding-box
-         (lambda ()
-           (ffi-core:aabbox3df->pointer (get-bounding-box))))
-        (c-get-material
-         (lambda (i)
-           (ffi-core:material->pointer (get-material i)))))
-    (ffi-scene:add-custom-scene-node
-     scene-manager
-     parent
-     id
-     (ffi-core:vector3df->pointer position)
-     (ffi-core:vector3df->pointer rotation)
-     (ffi-core:vector3df->pointer scale)
-     (procedure->pointer void render '())
-     (procedure->pointer '* c-get-bounding-box '())
-     (procedure->pointer uint32 get-material-count '())
-     (procedure->pointer '* c-get-material (list uint32)))))
-
-(define* (add-octree-scene-node scene-manager mesh
-                                #:key
-                                (parent %null-pointer)
-                                (id -1)
-                                (minimal-polys-per-node 512)
-                                (also-add-if-mesh-pointer-zero #f))
-  (ffi-scene:add-octree-scene-node
-   scene-manager
-   mesh
-   parent
-   id
-   minimal-polys-per-node
-   (bool->integer also-add-if-mesh-pointer-zero)))
-
-(define (get-mesh scene-manager filename)
-  (let ((mesh (ffi-scene:get-mesh scene-manager (string->pointer filename))))
-    (if (null-pointer? mesh) #f mesh)))
-
-(define (get-root-scene-node scene-manager)
-  (ffi-scene:get-root-scene-node scene-manager))
-
-(define (scene-draw-all scene-manager)
-  (ffi-scene:draw-all scene-manager))
-
-(define (set-material-flag! node flag newvalue)
-  (let ((material-flag
-         (match flag
-                ('wireframe ffi-video:EMF_WIREFRAME)
-                ('pointcloud ffi-video:EMF_POINTCLOUD)
-                ('gouraud-shading ffi-video:EMF_GOURAUD_SHADING)
-                ('lighting ffi-video:EMF_LIGHTING)
-                ('zbuffer ffi-video:EMF_ZBUFFER)
-                ('zwrite-enable ffi-video:EMF_ZWRITE_ENABLE)
-                ('back-face-culling ffi-video:EMF_BACK_FACE_CULLING)
-                ('front-face-culling ffi-video:EMF_FRONT_FACE_CULLING)
-                ('bilinear-filter ffi-video:EMF_BILINEAR_FILTER)
-                ('trilinear-filter ffi-video:EMF_TRILINEAR_FILTER)
-                ('anisotropic-filter ffi-video:EMF_ANISOTROPIC_FILTER)
-                ('fog-enable ffi-video:EMF_FOG_ENABLE)
-                ('normalize-normals ffi-video:EMF_NORMALIZE_NORMALS)
-                ('texture-wrap ffi-video:EMF_TEXTURE_WRAP)
-                ('anti-aliasing ffi-video:EMF_ANTI_ALIASING)
-                ('color-mask ffi-video:EMF_COLOR_MASK)
-                ('color-material ffi-video:EMF_COLOR_MATERIAL)
-                ('use-mip-maps ffi-video:EMF_USE_MIP_MAPS)
-                ('blend-operation ffi-video:EMF_BLEND_OPERATION)
-                ('polygon-offset ffi-video:EMF_POLYGON_OFFSET))))
-    (ffi-scene:set-material-flag
-     node
-     material-flag
-     (bool->integer newvalue))))
-
-(define (set-material-texture! node texture-layer texture)
-  (ffi-scene:set-material-texture node texture-layer texture))
-
-(define (set-md2-animation! node anim)
-  (let ((animation-type
-         (match anim
-                ('stand ffi-scene:EMAT_STAND)
-                ('run ffi-scene:EMAT_RUN)
-                ('attack ffi-scene:EMAT_ATTACK)
-                ('pain-a ffi-scene:EMAT_PAIN_A)
-                ('pain-b ffi-scene:EMAT_PAIN_B)
-                ('pain-c ffi-scene:EMAT_PAIN_C)
-                ('jump ffi-scene:EMAT_JUMP)
-                ('flip ffi-scene:EMAT_FLIP)
-                ('salute ffi-scene:EMAT_SALUTE)
-                ('fallback ffi-scene:EMAT_FALLBACK)
-                ('wave ffi-scene:EMAT_WAVE)
-                ('point ffi-scene:EMAT_POINT)
-                ('crouch-stand ffi-scene:EMAT_CROUCH_STAND)
-                ('crouch-walk ffi-scene:EMAT_CROUCH_WALK)
-                ('crouch-attack ffi-scene:EMAT_CROUCH_ATTACK)
-                ('crouch-pain ffi-scene:EMAT_CROUCH_PAIN)
-                ('crouch-death ffi-scene:EMAT_CROUCH_DEATH)
-                ('death-fallback ffi-scene:EMAT_DEATH_FALLBACK)
-                ('death-fallforward ffi-scene:EMAT_DEATH_FALLFORWARD)
-                ('death-fallbackslow ffi-scene:EMAT_DEATH_FALLBACKSLOW)
-                ('boom ffi-scene:EMAT_BOOM)
-                ('count ffi-scene:EMAT_COUNT))))
-    (ffi-scene:set-md2-animation
-     node
-     animation-type)))
-
-(define (set-position! node newpos)
-  (ffi-scene:set-position
-   node
-   (ffi-core:vector3df->pointer newpos)))
+  (irr-add-camera-scene-node! scene-manager
+                              parent
+                              position
+                              lookat
+                              id
+                              make-active))