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)))
57 ;; create engine and camera
58 (set-window-caption! device "Custom Scene Node - Irrlicht Engine Demo")
61 (define driver (get-video-driver device))
62 (define scene-manager (get-scene-manager device))
63 (add-camera-scene-node! scene-manager
67 ;; create our custom scene node
68 (define box (make-box3d))
70 (list (make-vertex3d '(0 0 10) '(1 1 0) '(255 0 255 255) '(0 1))
71 (make-vertex3d '(10 0 -10) '(1 0 0) '(255 255 0 255) '(1 1))
72 (make-vertex3d '(0 20 0) '(0 1 1) '(255 255 255 0) '(1 0))
73 (make-vertex3d '(-10 0 -10) '(0 0 1) '(255 0 255 0) '(0 0))))
74 (define material (make-material #:wireframe #f #:lighting #f))
76 (reset-box3d! box (get-position (car vertices)))
79 (add-internal-point! box (get-position vertex)))
82 (define (custom-render)
83 (let ((indices '((0 2 3) (2 1 3) (1 0 3) (2 0 1))))
84 (set-material! driver material)
85 (set-transform! driver 'world (get-absolute-transformation my-node))
86 (draw-vertex-primitive-list driver vertices indices)))
88 (define (custom-get-bounding-box)
91 (define (custom-get-material-count)
94 (define (custom-get-material i)
97 (set! my-node (add-custom-scene-node! scene-manager
99 custom-get-bounding-box
100 custom-get-material-count
102 #:parent (get-root-scene-node scene-manager)))
105 (let ((anim (create-rotation-animator scene-manager '(0.8 0 0.8))))
106 (add-animator! my-node anim))
111 (begin-scene driver #:color '(0 100 100 100))
112 (draw-all scene-manager)
115 (set! frames (+ frames 1))
117 (let ((fps (get-fps driver))
118 (driver-name (get-name driver)))
120 (format #f "Irrlicht Engine [~a] FPS:~a" driver-name fps)))
121 (set-window-caption! device caption)))