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 (make-c-struct ffi-core:vector3df position)
55 (make-c-struct ffi-core:vector3df rotation)
56 (make-c-struct ffi-core:vector3df 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 (make-c-struct ffi-core:vector3df position)
71 (make-c-struct ffi-core:vector3df 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! parent
105 (ffi-scene:add-custom-scene-node
109 (procedure->pointer void custom-render '())))
111 (define* (add-octree-scene-node scene-manager mesh
113 (parent %null-pointer)
115 (minimal-polys-per-node 512)
116 (also-add-if-mesh-pointer-zero #f))
117 (ffi-scene:add-octree-scene-node
122 minimal-polys-per-node
123 (bool->integer also-add-if-mesh-pointer-zero)))
125 (define (get-mesh scene-manager filename)
126 (let ((mesh (ffi-scene:get-mesh scene-manager (string->pointer filename))))
127 (if (null-pointer? mesh) #f mesh)))
129 (define (get-root-scene-node scene-manager)
130 (ffi-scene:get-root-scene-node scene-manager))
132 (define (scene-draw-all scene-manager)
133 (ffi-scene:draw-all scene-manager))
135 (define (set-material-flag! node flag newvalue)
138 ('wireframe ffi-video:EMF_WIREFRAME)
139 ('pointcloud ffi-video:EMF_POINTCLOUD)
140 ('gouraud-shading ffi-video:EMF_GOURAUD_SHADING)
141 ('lighting ffi-video:EMF_LIGHTING)
142 ('zbuffer ffi-video:EMF_ZBUFFER)
143 ('zwrite-enable ffi-video:EMF_ZWRITE_ENABLE)
144 ('back-face-culling ffi-video:EMF_BACK_FACE_CULLING)
145 ('front-face-culling ffi-video:EMF_FRONT_FACE_CULLING)
146 ('bilinear-filter ffi-video:EMF_BILINEAR_FILTER)
147 ('trilinear-filter ffi-video:EMF_TRILINEAR_FILTER)
148 ('anisotropic-filter ffi-video:EMF_ANISOTROPIC_FILTER)
149 ('fog-enable ffi-video:EMF_FOG_ENABLE)
150 ('normalize-normals ffi-video:EMF_NORMALIZE_NORMALS)
151 ('texture-wrap ffi-video:EMF_TEXTURE_WRAP)
152 ('anti-aliasing ffi-video:EMF_ANTI_ALIASING)
153 ('color-mask ffi-video:EMF_COLOR_MASK)
154 ('color-material ffi-video:EMF_COLOR_MATERIAL)
155 ('use-mip-maps ffi-video:EMF_USE_MIP_MAPS)
156 ('blend-operation ffi-video:EMF_BLEND_OPERATION)
157 ('polygon-offset ffi-video:EMF_POLYGON_OFFSET))))
158 (ffi-scene:set-material-flag
161 (bool->integer newvalue))))
163 (define (set-material-texture! node texture-layer texture)
164 (ffi-scene:set-material-texture node texture-layer texture))
166 (define (set-md2-animation! node anim)
167 (let ((animation-type
169 ('stand ffi-scene:EMAT_STAND)
170 ('run ffi-scene:EMAT_RUN)
171 ('attack ffi-scene:EMAT_ATTACK)
172 ('pain-a ffi-scene:EMAT_PAIN_A)
173 ('pain-b ffi-scene:EMAT_PAIN_B)
174 ('pain-c ffi-scene:EMAT_PAIN_C)
175 ('jump ffi-scene:EMAT_JUMP)
176 ('flip ffi-scene:EMAT_FLIP)
177 ('salute ffi-scene:EMAT_SALUTE)
178 ('fallback ffi-scene:EMAT_FALLBACK)
179 ('wave ffi-scene:EMAT_WAVE)
180 ('point ffi-scene:EMAT_POINT)
181 ('crouch-stand ffi-scene:EMAT_CROUCH_STAND)
182 ('crouch-walk ffi-scene:EMAT_CROUCH_WALK)
183 ('crouch-attack ffi-scene:EMAT_CROUCH_ATTACK)
184 ('crouch-pain ffi-scene:EMAT_CROUCH_PAIN)
185 ('crouch-death ffi-scene:EMAT_CROUCH_DEATH)
186 ('death-fallback ffi-scene:EMAT_DEATH_FALLBACK)
187 ('death-fallforward ffi-scene:EMAT_DEATH_FALLFORWARD)
188 ('death-fallbackslow ffi-scene:EMAT_DEATH_FALLBACKSLOW)
189 ('boom ffi-scene:EMAT_BOOM)
190 ('count ffi-scene:EMAT_COUNT))))
191 (ffi-scene:set-md2-animation
195 (define (set-position! node newpos)
196 (ffi-scene:set-position
198 (make-c-struct ffi-core:vector3df newpos)))