1 ;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
2 ;;; Copyright (C) 2020 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 (oop goops)
23 #:use-module (ice-9 optargs)
24 #:use-module (irrlicht base)
25 #:use-module (irrlicht foreign)
26 #:use-module (irrlicht io)
27 #:use-module (irrlicht irr)
28 #:use-module (irrlicht video))
32 (define-class <mesh> (<reference-counted>)
33 (irr-class #:init-value "IMesh"))
39 (define-class <animated-mesh> (<mesh>)
40 (irr-class #:init-value "IAnimatedMesh"))
42 (export <animated-mesh>)
46 (define-class <scene-node-animator> (<attribute-exchanging-object> <event-receiver>)
47 (irr-class #:init-value "ISceneNodeAnimator"))
49 (export <scene-node-animator>)
53 (define-class <scene-manager> (<reference-counted>)
54 (irr-class #:init-value "ISceneManager"))
56 (define-method (add-animated-mesh-scene-node! (scene-manager <scene-manager>)
57 (mesh <animated-mesh>)
60 ((parent (make <scene-node>))
65 (also-add-if-mesh-pointer-zero #f))
66 (make <animated-mesh-scene-node>
68 ((get-irrlicht-proc "addAnimatedMeshSceneNode" scene-manager parent)
76 also-add-if-mesh-pointer-zero))))
78 (define-method (add-camera-scene-node! (scene-manager <scene-manager>) . rest)
80 ((parent (make <scene-node>))
85 (make <camera-scene-node>
87 ((get-irrlicht-proc "addCameraSceneNode" scene-manager parent)
95 (define-method (add-camera-scene-node-fps! (scene-manager <scene-manager>) . rest)
97 ((parent (make <scene-node>))
101 (key-map-array (make <key-map>))
103 (no-vertical-movement #f)
107 (let ((addCameraSceneNodeFPS (get-irrlicht-proc "addCameraSceneNodeFPS"
108 scene-manager parent)))
109 (make <camera-scene-node>
111 (addCameraSceneNodeFPS scene-manager #:parent parent #:rotate-speed rotate-speed
112 #:move-speed move-speed #:id id #:key-map-array key-map-array
113 #:key-map-size key-map-size
114 #:no-vertical-movement no-vertical-movement
115 #:jump-speed jump-speed #:invert-mouse invert-mouse
116 #:make-active make-active)))))
118 (define-method (add-custom-scene-node! (scene-manager <scene-manager>) proc-render
119 proc-get-bounding-box proc-get-material-count
120 proc-get-material . rest)
121 (let-keywords rest #f
122 ((parent (make <scene-node>))
127 (let ((addCustomSceneNode (get-irrlicht-proc "addCustomSceneNode" scene-manager parent)))
130 (addCustomSceneNode scene-manager proc-render proc-get-bounding-box proc-get-material-count
131 proc-get-material parent id position rotation scale)))))
133 (define-method (add-octree-scene-node! (scene-manager <scene-manager>)
134 (mesh <animated-mesh>)
136 (let-keywords rest #f
137 ((parent (make <scene-node>))
139 (minimal-polys-per-node 512)
140 (also-add-if-mesh-pointer-zero #f))
141 (let ((addOctreeSceneNode (get-irrlicht-proc "addOctreeSceneNode" scene-manager parent mesh)))
142 (make <mesh-scene-node>
144 (addOctreeSceneNode scene-manager mesh parent id minimal-polys-per-node
145 also-add-if-mesh-pointer-zero)))))
147 (define-method (add-octree-scene-node! (scene-manager <scene-manager>)
150 (let-keywords rest #f
151 ((parent (make <scene-node>))
153 (minimal-polys-per-node 256)
154 (also-add-if-mesh-pointer-zero #f))
155 (let ((addOctreeSceneNode (get-irrlicht-proc "addOctreeSceneNode" scene-manager parent mesh)))
156 (make <mesh-scene-node>
158 (addOctreeSceneNode scene-manager mesh parent id minimal-polys-per-node
159 also-add-if-mesh-pointer-zero)))))
161 (define-method (create-rotation-animator (scene-manager <scene-manager>) rotation-speed)
162 (let ((createRotationAnimator (get-irrlicht-proc "createRotationAnimator" scene-manager)))
163 (make <scene-node-animator>
165 (createRotationAnimator scene-manager rotation-speed))))
167 (define-method (draw-all (scene-manager <scene-manager>))
168 ((get-irrlicht-proc "drawAll" scene-manager)
171 (define-method (get-mesh (scene-manager <scene-manager>) filename)
172 (make <animated-mesh>
174 ((get-irrlicht-proc "getMesh" scene-manager)
178 (define-method (get-root-scene-node (scene-manager <scene-manager>))
179 (let ((getRootSceneNode (get-irrlicht-proc "getRootSceneNode" scene-manager)))
180 (make <scene-node> #:irr-pointer (getRootSceneNode scene-manager))))
182 (export <scene-manager> add-animated-mesh-scene-node! add-camera-scene-node!
183 add-camera-scene-node-fps! add-custom-scene-node! add-octree-scene-node!
184 create-rotation-animator draw-all get-root-scene-node get-mesh)
188 (define-class <scene-node> (<attribute-exchanging-object>)
189 (irr-class #:init-value "ISceneNode"))
191 (define-method (add-animator! (node <scene-node>) (animator <scene-node-animator>))
192 (let ((addAnimator (get-irrlicht-proc "addAnimator" node)))
193 (addAnimator node animator)))
195 (define-method (get-absolute-transformation (node <scene-node>))
196 (let ((getAbsoluteTransformation (get-irrlicht-proc "getAbsoluteTransformation" node)))
197 (getAbsoluteTransformation node)))
199 (define-method (set-material-flag! (node <scene-node>) flag new-value)
200 ((get-irrlicht-proc "setMaterialFlag" node)
205 (define-method (set-material-texture! (node <scene-node>) texture-layer (texture <texture>))
206 ((get-irrlicht-proc "setMaterialTexture" node)
211 (define-method (set-position! (node <scene-node>) new-pos)
212 (let ((setPosition (get-irrlicht-proc "setPosition" node)))
213 (setPosition node new-pos)))
215 (export <scene-node> add-animator! get-absolute-transformation set-material-flag!
216 set-material-texture! set-position!)
219 ;; IAnimatedMeshSceneNode
220 (define-class <animated-mesh-scene-node> (<scene-node>)
221 (irr-class #:init-value "IAnimatedMeshSceneNode"))
223 (define-method (set-md2-animation! (node <animated-mesh-scene-node>) anim)
224 ((get-irrlicht-proc "setMD2Animation" node)
228 (export <animated-mesh-scene-node> set-md2-animation!)
232 (define-class <camera-scene-node> (<scene-node>)
233 (irr-class #:init-value "ICameraSceneNode"))
235 (export <camera-scene-node>)
239 (define-class <mesh-scene-node> (<scene-node>)
240 (irr-class #:init-value "IMeshSceneNode"))
242 (export <mesh-scene-node>)