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 ;;; Irrlicht 03.CustomSceneNode example
22 ;;; http://irrlicht.sourceforge.net/docu/example003.html
25 (use-modules (irrlicht)
28 ;; ask user for driver
30 "Please select the driver you want for this example:
34 (d) Burning's Software Renderer
39 (define device-type (match (read-char)
48 (when (not device-type)
51 ;; start up the engine
54 #:device-type device-type
55 #:window-size '(640 480)))
59 ;; create engine and camera
60 (set-window-caption! device "Custom Scene Node - Irrlicht Engine Demo")
63 (define driver (get-video-driver device))
64 (define scene-manager (get-scene-manager device))
65 (add-camera-scene-node! scene-manager
69 ;; create our custom scene node
70 (define box (make-aabbox3df))
72 (list (make-s3dvertex '(0 0 10) '(1 1 0) '(255 0 255 255) '(0 1))
73 (make-s3dvertex '(10 0 -10) '(1 0 0) '(255 255 0 255) '(1 1))
74 (make-s3dvertex '(0 20 0) '(0 1 1) '(255 255 255 0) '(1 0))
75 (make-s3dvertex '(-10 0 -10) '(0 0 1) '(255 0 255 0) '(0 0))))
76 (define material (make-material #:wireframe #f #:lighting #f))
78 (aabbox3d-reset! box (vertex-position (car vertices)))
79 (for-each (lambda (vertex)
80 (aabbox3d-add-internal-point! box (vertex-position vertex)))
83 (define (custom-render)
84 (let ((indices '((0 2 3) (2 1 3) (1 0 3) (2 0 1))))
85 ;;(set-material! driver material)
86 ;;(set-transform! driver 'world (get-absolute-transformation my-node))
87 ;;(draw-vertex-primitive-list driver vertices indices)))
90 (define (custom-get-bounding-box)
93 (define (custom-get-material-count)
96 (define (custom-get-material i)
99 (set! my-node (add-custom-scene-node! scene-manager
101 custom-get-bounding-box
102 custom-get-material-count
104 #:parent (get-root-scene-node scene-manager)))
107 (let ((anim (create-rotation-animator scene-manager '(0.8 0 0.8))))
108 (add-animator! my-node anim))
112 (while (device-run? device)
113 (begin-scene driver #:color '(0 100 100 100))
114 (scene-draw-all scene-manager)
117 (set! frames (+ frames 1))
119 (let ((fps (get-fps driver))
120 (driver-name (get-video-driver-name driver)))
122 (format #f "Irrlicht Engine [~a] FPS:~a" driver-name fps)))
123 (set-window-caption! device caption)))
127 (device-drop! device)