1 ;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
2 ;;; Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
4 ;;; This file is part of guile-irrlicht.
6 ;;; Guile-irrlicht is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation; either version 3 of the
9 ;;; License, or (at your option) any later version.
11 ;;; Guile-irrlicht is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with guile-irrlicht. If not, see
18 ;;; <http://www.gnu.org/licenses/>.
21 (define-module (irrlicht scene)
22 #:use-module (ice-9 match)
23 #:use-module (system foreign)
24 #:use-module ((irrlicht bindings core) #:prefix ffi-core:)
25 #:use-module ((irrlicht bindings scene) #:prefix ffi-scene:)
26 #:use-module ((irrlicht bindings video) #:prefix ffi-video:)
27 #:use-module (irrlicht util)
28 #:export (add-animated-mesh-scene-node
29 add-camera-scene-node!
30 add-camera-scene-node-fps!
31 add-custom-scene-node!
41 (define* (add-animated-mesh-scene-node scene-manager mesh
43 (parent %null-pointer)
48 (also-add-if-mesh-pointer-zero #f))
49 (let ((node (ffi-scene:add-animated-mesh-scene-node
54 (ffi-core:vector3df->pointer position)
55 (ffi-core:vector3df->pointer rotation)
56 (ffi-core:vector3df->pointer scale)
57 (bool->integer also-add-if-mesh-pointer-zero))))
58 (if (null-pointer? node) #f node)))
60 (define* (add-camera-scene-node! scene-manager
62 (parent %null-pointer)
67 (let ((camera (ffi-scene:add-camera-scene-node
70 (ffi-core:vector3df->pointer position)
71 (ffi-core:vector3df->pointer lookat)
73 (bool->integer make-active))))
74 (if (null-pointer? camera) #f camera)))
76 (define* (add-camera-scene-node-fps! scene-manager
78 (parent %null-pointer)
82 (key-map-array %null-pointer)
84 (no-vertical-movement #f)
88 (ffi-scene:add-camera-scene-node-fps
96 (bool->integer no-vertical-movement)
98 (bool->integer invert-mouse)
99 (bool->integer make-active)))
101 (define* (add-custom-scene-node! scene-manager
107 (parent %null-pointer)
112 (let ((c-get-bounding-box
114 (ffi-core:aabbox3df->pointer (get-bounding-box))))
117 (ffi-core:material->pointer (get-material i)))))
118 (ffi-scene:add-custom-scene-node
122 (ffi-core:vector3df->pointer position)
123 (ffi-core:vector3df->pointer rotation)
124 (ffi-core:vector3df->pointer scale)
125 (procedure->pointer void render '())
126 (procedure->pointer '* c-get-bounding-box '())
127 (procedure->pointer uint32 get-material-count '())
128 (procedure->pointer '* c-get-material (list uint32)))))
130 (define* (add-octree-scene-node scene-manager mesh
132 (parent %null-pointer)
134 (minimal-polys-per-node 512)
135 (also-add-if-mesh-pointer-zero #f))
136 (ffi-scene:add-octree-scene-node
141 minimal-polys-per-node
142 (bool->integer also-add-if-mesh-pointer-zero)))
144 (define (get-mesh scene-manager filename)
145 (let ((mesh (ffi-scene:get-mesh scene-manager (string->pointer filename))))
146 (if (null-pointer? mesh) #f mesh)))
148 (define (get-root-scene-node scene-manager)
149 (ffi-scene:get-root-scene-node scene-manager))
151 (define (scene-draw-all scene-manager)
152 (ffi-scene:draw-all scene-manager))
154 (define (set-material-flag! node flag newvalue)
157 ('wireframe ffi-video:EMF_WIREFRAME)
158 ('pointcloud ffi-video:EMF_POINTCLOUD)
159 ('gouraud-shading ffi-video:EMF_GOURAUD_SHADING)
160 ('lighting ffi-video:EMF_LIGHTING)
161 ('zbuffer ffi-video:EMF_ZBUFFER)
162 ('zwrite-enable ffi-video:EMF_ZWRITE_ENABLE)
163 ('back-face-culling ffi-video:EMF_BACK_FACE_CULLING)
164 ('front-face-culling ffi-video:EMF_FRONT_FACE_CULLING)
165 ('bilinear-filter ffi-video:EMF_BILINEAR_FILTER)
166 ('trilinear-filter ffi-video:EMF_TRILINEAR_FILTER)
167 ('anisotropic-filter ffi-video:EMF_ANISOTROPIC_FILTER)
168 ('fog-enable ffi-video:EMF_FOG_ENABLE)
169 ('normalize-normals ffi-video:EMF_NORMALIZE_NORMALS)
170 ('texture-wrap ffi-video:EMF_TEXTURE_WRAP)
171 ('anti-aliasing ffi-video:EMF_ANTI_ALIASING)
172 ('color-mask ffi-video:EMF_COLOR_MASK)
173 ('color-material ffi-video:EMF_COLOR_MATERIAL)
174 ('use-mip-maps ffi-video:EMF_USE_MIP_MAPS)
175 ('blend-operation ffi-video:EMF_BLEND_OPERATION)
176 ('polygon-offset ffi-video:EMF_POLYGON_OFFSET))))
177 (ffi-scene:set-material-flag
180 (bool->integer newvalue))))
182 (define (set-material-texture! node texture-layer texture)
183 (ffi-scene:set-material-texture node texture-layer texture))
185 (define (set-md2-animation! node anim)
186 (let ((animation-type
188 ('stand ffi-scene:EMAT_STAND)
189 ('run ffi-scene:EMAT_RUN)
190 ('attack ffi-scene:EMAT_ATTACK)
191 ('pain-a ffi-scene:EMAT_PAIN_A)
192 ('pain-b ffi-scene:EMAT_PAIN_B)
193 ('pain-c ffi-scene:EMAT_PAIN_C)
194 ('jump ffi-scene:EMAT_JUMP)
195 ('flip ffi-scene:EMAT_FLIP)
196 ('salute ffi-scene:EMAT_SALUTE)
197 ('fallback ffi-scene:EMAT_FALLBACK)
198 ('wave ffi-scene:EMAT_WAVE)
199 ('point ffi-scene:EMAT_POINT)
200 ('crouch-stand ffi-scene:EMAT_CROUCH_STAND)
201 ('crouch-walk ffi-scene:EMAT_CROUCH_WALK)
202 ('crouch-attack ffi-scene:EMAT_CROUCH_ATTACK)
203 ('crouch-pain ffi-scene:EMAT_CROUCH_PAIN)
204 ('crouch-death ffi-scene:EMAT_CROUCH_DEATH)
205 ('death-fallback ffi-scene:EMAT_DEATH_FALLBACK)
206 ('death-fallforward ffi-scene:EMAT_DEATH_FALLFORWARD)
207 ('death-fallbackslow ffi-scene:EMAT_DEATH_FALLBACKSLOW)
208 ('boom ffi-scene:EMAT_BOOM)
209 ('count ffi-scene:EMAT_COUNT))))
210 (ffi-scene:set-md2-animation
214 (define (set-position! node newpos)
215 (ffi-scene:set-position
217 (ffi-core:vector3df->pointer newpos)))