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
30 add-camera-scene-node-fps!
31 add-octree-scene-node-am
35 set-material-texture-am!
39 (define* (add-animated-mesh-scene-node scene-manager mesh
41 (parent %null-pointer)
46 (also-add-if-mesh-pointer-zero #f))
47 (let ((node (ffi-scene:add-animated-mesh-scene-node
52 (make-c-struct ffi-core:vector3df position)
53 (make-c-struct ffi-core:vector3df rotation)
54 (make-c-struct ffi-core:vector3df scale)
55 (bool->integer also-add-if-mesh-pointer-zero))))
56 (if (null-pointer? node) #f node)))
58 (define* (add-camera-scene-node scene-manager
60 (parent %null-pointer)
65 (let ((camera (ffi-scene:add-camera-scene-node
68 (make-c-struct ffi-core:vector3df position)
69 (make-c-struct ffi-core:vector3df lookat)
71 (bool->integer make-active))))
72 (if (null-pointer? camera) #f camera)))
74 (define* (add-camera-scene-node-fps! scene-manager
76 (parent %null-pointer)
80 (key-map-array %null-pointer)
82 (no-vertical-movement #f)
86 (ffi-scene:add-camera-scene-node-fps
94 (bool->integer no-vertical-movement)
96 (bool->integer invert-mouse)
97 (bool->integer make-active)))
99 (define* (add-octree-scene-node-am scene-manager mesh
101 (parent %null-pointer)
103 (minimal-polys-per-node 512)
104 (also-add-if-mesh-pointer-zero #f))
105 (ffi-scene:add-octree-scene-node-am
110 minimal-polys-per-node
111 (bool->integer also-add-if-mesh-pointer-zero)))
113 (define (get-mesh scene-manager filename)
114 (let ((mesh (ffi-scene:get-mesh scene-manager (string->pointer filename))))
115 (if (null-pointer? mesh) #f mesh)))
117 (define (scene-draw-all scene-manager)
118 (ffi-scene:draw-all scene-manager))
120 (define (set-material-flag-am! node flag newvalue)
123 ('wireframe ffi-video:EMF_WIREFRAME)
124 ('pointcloud ffi-video:EMF_POINTCLOUD)
125 ('gouraud-shading ffi-video:EMF_GOURAUD_SHADING)
126 ('lighting ffi-video:EMF_LIGHTING)
127 ('zbuffer ffi-video:EMF_ZBUFFER)
128 ('zwrite-enable ffi-video:EMF_ZWRITE_ENABLE)
129 ('back-face-culling ffi-video:EMF_BACK_FACE_CULLING)
130 ('front-face-culling ffi-video:EMF_FRONT_FACE_CULLING)
131 ('bilinear-filter ffi-video:EMF_BILINEAR_FILTER)
132 ('trilinear-filter ffi-video:EMF_TRILINEAR_FILTER)
133 ('anisotropic-filter ffi-video:EMF_ANISOTROPIC_FILTER)
134 ('fog-enable ffi-video:EMF_FOG_ENABLE)
135 ('normalize-normals ffi-video:EMF_NORMALIZE_NORMALS)
136 ('texture-wrap ffi-video:EMF_TEXTURE_WRAP)
137 ('anti-aliasing ffi-video:EMF_ANTI_ALIASING)
138 ('color-mask ffi-video:EMF_COLOR_MASK)
139 ('color-material ffi-video:EMF_COLOR_MATERIAL)
140 ('use-mip-maps ffi-video:EMF_USE_MIP_MAPS)
141 ('blend-operation ffi-video:EMF_BLEND_OPERATION)
142 ('polygon-offset ffi-video:EMF_POLYGON_OFFSET))))
143 (ffi-scene:set-material-flag-am
146 (bool->integer newvalue))))
148 (define (set-material-texture-am! node texture-layer texture)
149 (ffi-scene:set-material-texture-am node texture-layer texture))
151 (define (set-md2-animation! node anim)
152 (let ((animation-type
154 ('stand ffi-scene:EMAT_STAND)
155 ('run ffi-scene:EMAT_RUN)
156 ('attack ffi-scene:EMAT_ATTACK)
157 ('pain-a ffi-scene:EMAT_PAIN_A)
158 ('pain-b ffi-scene:EMAT_PAIN_B)
159 ('pain-c ffi-scene:EMAT_PAIN_C)
160 ('jump ffi-scene:EMAT_JUMP)
161 ('flip ffi-scene:EMAT_FLIP)
162 ('salute ffi-scene:EMAT_SALUTE)
163 ('fallback ffi-scene:EMAT_FALLBACK)
164 ('wave ffi-scene:EMAT_WAVE)
165 ('point ffi-scene:EMAT_POINT)
166 ('crouch-stand ffi-scene:EMAT_CROUCH_STAND)
167 ('crouch-walk ffi-scene:EMAT_CROUCH_WALK)
168 ('crouch-attack ffi-scene:EMAT_CROUCH_ATTACK)
169 ('crouch-pain ffi-scene:EMAT_CROUCH_PAIN)
170 ('crouch-death ffi-scene:EMAT_CROUCH_DEATH)
171 ('death-fallback ffi-scene:EMAT_DEATH_FALLBACK)
172 ('death-fallforward ffi-scene:EMAT_DEATH_FALLFORWARD)
173 ('death-fallbackslow ffi-scene:EMAT_DEATH_FALLBACKSLOW)
174 ('boom ffi-scene:EMAT_BOOM)
175 ('count ffi-scene:EMAT_COUNT))))
176 (ffi-scene:set-md2-animation
180 (define (set-position! node newpos)
181 (ffi-scene:set-position
183 (make-c-struct ffi-core:vector3df newpos)))