;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
-;;; Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+;;; Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
;;;
;;; This file is part of guile-irrlicht.
;;;
(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
- add-animator!
- add-camera-scene-node!
- add-camera-scene-node-fps!
- add-custom-scene-node!
- add-octree-scene-node
- create-rotation-animator
- get-mesh
- get-root-scene-node
- scene-draw-all
- set-material-flag!
- set-material-texture!
- set-md2-animation!
- set-position!))
+ #:use-module (oop goops)
+ #:use-module (irrlicht foreign)
+ #:use-module (irrlicht irr))
-(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)))
-(define (add-animator! node animator)
- (ffi-scene:add-animator node animator))
+;; ISceneManager
+(define-class <scene-manager> (<reference-counted>))
-(define* (add-camera-scene-node! scene-manager
- #:key
- (parent %null-pointer)
- (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 (create-rotation-animator scene-manager rotation-speed)
- (let ((animator (ffi-scene:create-rotation-animator
- scene-manager
- (ffi-core:vector3df->pointer rotation-speed))))
- (if (null-pointer? animator) #f animator)))
-
-(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)))
+(export <scene-manager>)