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 (let* ((addAnimatedMeshSceneNode (get-irrlicht-proc "addAnimatedMeshSceneNode"
69 (node-pointer (addAnimatedMeshSceneNode scene-manager mesh parent id position
70 rotation scale also-add-if-mesh-pointer-zero)))
71 (cond ((null-pointer? node-pointer)
72 (error "In procedure add-animated-mesh-scene-node!: Scene node cannot be created"))
74 (make <animated-mesh-scene-node> #:irr-pointer node-pointer))))))
76 (define-method (add-camera-scene-node! (scene-manager <scene-manager>) . rest)
78 ((parent (make <scene-node>))
83 (make <camera-scene-node>
85 ((get-irrlicht-proc "addCameraSceneNode" scene-manager parent)
93 (define-method (add-camera-scene-node-fps! (scene-manager <scene-manager>) . rest)
95 ((parent (make <scene-node>))
99 (key-map-array (make <key-map>))
101 (no-vertical-movement #f)
105 (let ((addCameraSceneNodeFPS (get-irrlicht-proc "addCameraSceneNodeFPS"
106 scene-manager parent)))
107 (make <camera-scene-node>
109 (addCameraSceneNodeFPS scene-manager #:parent parent #:rotate-speed rotate-speed
110 #:move-speed move-speed #:id id #:key-map-array key-map-array
111 #:key-map-size key-map-size
112 #:no-vertical-movement no-vertical-movement
113 #:jump-speed jump-speed #:invert-mouse invert-mouse
114 #:make-active make-active)))))
116 (define-method (add-custom-scene-node! (scene-manager <scene-manager>) proc-render
117 proc-get-bounding-box proc-get-material-count
118 proc-get-material . rest)
119 (let-keywords rest #f
120 ((parent (make <scene-node>))
125 (let ((addCustomSceneNode (get-irrlicht-proc "addCustomSceneNode" scene-manager parent)))
128 (addCustomSceneNode scene-manager proc-render proc-get-bounding-box proc-get-material-count
129 proc-get-material parent id position rotation scale)))))
131 (define-method (add-octree-scene-node! (scene-manager <scene-manager>)
132 (mesh <animated-mesh>)
134 (let-keywords rest #f
135 ((parent (make <scene-node>))
137 (minimal-polys-per-node 512)
138 (also-add-if-mesh-pointer-zero #f))
139 (let ((addOctreeSceneNode (get-irrlicht-proc "addOctreeSceneNode" scene-manager parent mesh)))
140 (make <mesh-scene-node>
142 (addOctreeSceneNode scene-manager mesh parent id minimal-polys-per-node
143 also-add-if-mesh-pointer-zero)))))
145 (define-method (add-octree-scene-node! (scene-manager <scene-manager>)
148 (let-keywords rest #f
149 ((parent (make <scene-node>))
151 (minimal-polys-per-node 256)
152 (also-add-if-mesh-pointer-zero #f))
153 (let ((addOctreeSceneNode (get-irrlicht-proc "addOctreeSceneNode" scene-manager parent mesh)))
154 (make <mesh-scene-node>
156 (addOctreeSceneNode scene-manager mesh parent id minimal-polys-per-node
157 also-add-if-mesh-pointer-zero)))))
159 (define-method (create-rotation-animator (scene-manager <scene-manager>) rotation-speed)
160 (let ((createRotationAnimator (get-irrlicht-proc "createRotationAnimator" scene-manager)))
161 (make <scene-node-animator>
163 (createRotationAnimator scene-manager rotation-speed))))
165 (define-method (draw-all (scene-manager <scene-manager>))
166 ((get-irrlicht-proc "drawAll" scene-manager)
169 (define-method (get-mesh (scene-manager <scene-manager>) filename)
170 (let* ((getMesh (get-irrlicht-proc "getMesh" scene-manager))
171 (mesh-pointer (getMesh scene-manager filename)))
172 (cond ((null-pointer? mesh-pointer)
173 (error "In procedure get-mesh: Mesh cannot be created"))
175 (make <animated-mesh> #:irr-pointer mesh-pointer)))))
177 (define-method (get-root-scene-node (scene-manager <scene-manager>))
178 (let ((getRootSceneNode (get-irrlicht-proc "getRootSceneNode" scene-manager)))
179 (make <scene-node> #:irr-pointer (getRootSceneNode scene-manager))))
181 (export <scene-manager> add-animated-mesh-scene-node! add-camera-scene-node!
182 add-camera-scene-node-fps! add-custom-scene-node! add-octree-scene-node!
183 create-rotation-animator draw-all get-root-scene-node get-mesh)
187 (define-class <scene-node> (<attribute-exchanging-object>)
188 (irr-class #:init-value "ISceneNode"))
190 (define-method (add-animator! (node <scene-node>) (animator <scene-node-animator>))
191 (let ((addAnimator (get-irrlicht-proc "addAnimator" node)))
192 (addAnimator node animator)))
194 (define-method (get-absolute-transformation (node <scene-node>))
195 (let ((getAbsoluteTransformation (get-irrlicht-proc "getAbsoluteTransformation" node)))
196 (getAbsoluteTransformation node)))
198 (define-method (set-material-flag! (node <scene-node>) flag new-value)
199 ((get-irrlicht-proc "setMaterialFlag" node)
204 (define-method (set-material-texture! (node <scene-node>) texture-layer (texture <texture>))
205 ((get-irrlicht-proc "setMaterialTexture" node)
210 (define-method (set-position! (node <scene-node>) new-pos)
211 (let ((setPosition (get-irrlicht-proc "setPosition" node)))
212 (setPosition node new-pos)))
214 (export <scene-node> add-animator! get-absolute-transformation set-material-flag!
215 set-material-texture! set-position!)
218 ;; IAnimatedMeshSceneNode
219 (define-class <animated-mesh-scene-node> (<scene-node>)
220 (irr-class #:init-value "IAnimatedMeshSceneNode"))
222 (define-method (set-md2-animation! (node <animated-mesh-scene-node>) anim)
223 ((get-irrlicht-proc "setMD2Animation" node)
227 (export <animated-mesh-scene-node> set-md2-animation!)
231 (define-class <camera-scene-node> (<scene-node>)
232 (irr-class #:init-value "ICameraSceneNode"))
234 (export <camera-scene-node>)
238 (define-class <mesh-scene-node> (<scene-node>)
239 (irr-class #:init-value "IMeshSceneNode"))
241 (export <mesh-scene-node>)