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 #:export (add-animated-mesh-scene-node
29 add-camera-scene-node-fps!
30 add-octree-scene-node-am
34 set-material-texture-am!
38 (define* (add-animated-mesh-scene-node scene-manager mesh
40 (parent %null-pointer)
45 (also-add-if-mesh-pointer-zero #f))
46 (let ((node (ffi-scene:add-animated-mesh-scene-node
51 (make-c-struct ffi-core:vector3df position)
52 (make-c-struct ffi-core:vector3df rotation)
53 (make-c-struct ffi-core:vector3df scale)
54 (if also-add-if-mesh-pointer-zero 1 0))))
55 (if (null-pointer? node) #f node)))
57 (define* (add-camera-scene-node scene-manager
59 (parent %null-pointer)
64 (let ((camera (ffi-scene:add-camera-scene-node
67 (make-c-struct ffi-core:vector3df position)
68 (make-c-struct ffi-core:vector3df lookat)
70 (if make-active 1 0))))
71 (if (null-pointer? camera) #f camera)))
73 (define* (add-camera-scene-node-fps! scene-manager
75 (parent %null-pointer)
79 (key-map-array %null-pointer)
81 (no-vertical-movement #f)
85 (ffi-scene:add-camera-scene-node-fps
93 (if no-vertical-movement 1 0)
96 (if make-active 1 0)))
98 (define* (add-octree-scene-node-am scene-manager mesh
100 (parent %null-pointer)
102 (minimal-polys-per-node 512)
103 (also-add-if-mesh-pointer-zero #f))
104 (ffi-scene:add-octree-scene-node-am
109 minimal-polys-per-node
110 (if also-add-if-mesh-pointer-zero 1 0)))
112 (define (get-mesh scene-manager filename)
113 (let ((mesh (ffi-scene:get-mesh scene-manager (string->pointer filename))))
114 (if (null-pointer? mesh) #f mesh)))
116 (define (scene-draw-all scene-manager)
117 (ffi-scene:draw-all scene-manager))
119 (define (set-material-flag-am! node flag newvalue)
122 ('wireframe ffi-video:EMF_WIREFRAME)
123 ('pointcloud ffi-video:EMF_POINTCLOUD)
124 ('gouraud-shading ffi-video:EMF_GOURAUD_SHADING)
125 ('lighting ffi-video:EMF_LIGHTING)
126 ('zbuffer ffi-video:EMF_ZBUFFER)
127 ('zwrite-enable ffi-video:EMF_ZWRITE_ENABLE)
128 ('back-face-culling ffi-video:EMF_BACK_FACE_CULLING)
129 ('front-face-culling ffi-video:EMF_FRONT_FACE_CULLING)
130 ('bilinear-filter ffi-video:EMF_BILINEAR_FILTER)
131 ('trilinear-filter ffi-video:EMF_TRILINEAR_FILTER)
132 ('anisotropic-filter ffi-video:EMF_ANISOTROPIC_FILTER)
133 ('fog-enable ffi-video:EMF_FOG_ENABLE)
134 ('normalize-normals ffi-video:EMF_NORMALIZE_NORMALS)
135 ('texture-wrap ffi-video:EMF_TEXTURE_WRAP)
136 ('anti-aliasing ffi-video:EMF_ANTI_ALIASING)
137 ('color-mask ffi-video:EMF_COLOR_MASK)
138 ('color-material ffi-video:EMF_COLOR_MATERIAL)
139 ('use-mip-maps ffi-video:EMF_USE_MIP_MAPS)
140 ('blend-operation ffi-video:EMF_BLEND_OPERATION)
141 ('polygon-offset ffi-video:EMF_POLYGON_OFFSET))))
142 (ffi-scene:set-material-flag-am
147 (define (set-material-texture-am! node texture-layer texture)
148 (ffi-scene:set-material-texture-am node texture-layer texture))
150 (define (set-md2-animation! node anim)
151 (let ((animation-type
153 ('stand ffi-scene:EMAT_STAND)
154 ('run ffi-scene:EMAT_RUN)
155 ('attack ffi-scene:EMAT_ATTACK)
156 ('pain-a ffi-scene:EMAT_PAIN_A)
157 ('pain-b ffi-scene:EMAT_PAIN_B)
158 ('pain-c ffi-scene:EMAT_PAIN_C)
159 ('jump ffi-scene:EMAT_JUMP)
160 ('flip ffi-scene:EMAT_FLIP)
161 ('salute ffi-scene:EMAT_SALUTE)
162 ('fallback ffi-scene:EMAT_FALLBACK)
163 ('wave ffi-scene:EMAT_WAVE)
164 ('point ffi-scene:EMAT_POINT)
165 ('crouch-stand ffi-scene:EMAT_CROUCH_STAND)
166 ('crouch-walk ffi-scene:EMAT_CROUCH_WALK)
167 ('crouch-attack ffi-scene:EMAT_CROUCH_ATTACK)
168 ('crouch-pain ffi-scene:EMAT_CROUCH_PAIN)
169 ('crouch-death ffi-scene:EMAT_CROUCH_DEATH)
170 ('death-fallback ffi-scene:EMAT_DEATH_FALLBACK)
171 ('death-fallforward ffi-scene:EMAT_DEATH_FALLFORWARD)
172 ('death-fallbackslow ffi-scene:EMAT_DEATH_FALLBACKSLOW)
173 ('boom ffi-scene:EMAT_BOOM)
174 ('count ffi-scene:EMAT_COUNT))))
175 (ffi-scene:set-md2-animation
179 (define (set-position! node newpos)
180 (ffi-scene:set-position
182 (make-c-struct ffi-core:vector3df newpos)))