From: Javier Sancho Date: Sat, 18 Apr 2020 18:31:58 +0000 (+0200) Subject: Rename examples X-Git-Url: https://git.jsancho.org/?p=guile-irrlicht.git;a=commitdiff_plain;h=9137f8fdb1e89ffdec1fb498084f71e92e7f02a9 Rename examples --- diff --git a/examples/01-hello-world.scm b/examples/01-hello-world.scm new file mode 100644 index 0000000..b480c89 --- /dev/null +++ b/examples/01-hello-world.scm @@ -0,0 +1,72 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +;;; Irrlicht 01.HelloWorld example +;;; http://irrlicht.sourceforge.net/docu/example001.html + + +(use-modules (irrlicht)) + +;; start up the engine +(define device + (create-device + #:device-type 'software + #:window-size '(640 480))) +(when (not device) + (exit #f)) + +(set-window-caption! device "Hello World! - Irrlicht Engine Demo") + +(define driver (get-video-driver device)) +(define scene-manager (get-scene-manager device)) +(define gui-env (get-gui-environment device)) + +;; static text +(add-static-text! + gui-env + "Hello World! This is the Irrlicht Software renderer!" + '(10 10 260 22) + #:border #t) + +;; load a Quake2 model +(define mesh (get-mesh scene-manager "media/sydney.md2")) +(when (not mesh) + (drop! device) + (exit #f)) + +(define node (add-animated-mesh-scene-node! scene-manager mesh)) +(when node + (set-material-flag! node 'lighting #f) + (set-md2-animation! node 'stand) + (set-material-texture! node 0 (get-texture driver "media/sydney.bmp"))) + +;; place camera +(add-camera-scene-node! scene-manager #:position '(0 30 -40) #:lookat '(0 5 0)) + +;; draw everything +(while (run device) + (begin-scene driver #:color '(255 100 101 140)) + (draw-all scene-manager) + (draw-all gui-env) + (end-scene driver)) + +;; delete device +(drop! device) +(exit #t) diff --git a/examples/01.HelloWorld.scm b/examples/01.HelloWorld.scm deleted file mode 100644 index b480c89..0000000 --- a/examples/01.HelloWorld.scm +++ /dev/null @@ -1,72 +0,0 @@ -;;; guile-irrlicht --- FFI bindings for Irrlicht Engine -;;; Copyright (C) 2019 Javier Sancho -;;; -;;; This file is part of guile-irrlicht. -;;; -;;; Guile-irrlicht is free software; you can redistribute it and/or modify -;;; it under the terms of the GNU Lesser General Public License as -;;; published by the Free Software Foundation; either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; Guile-irrlicht is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU Lesser General Public -;;; License along with guile-irrlicht. If not, see -;;; . - - -;;; Irrlicht 01.HelloWorld example -;;; http://irrlicht.sourceforge.net/docu/example001.html - - -(use-modules (irrlicht)) - -;; start up the engine -(define device - (create-device - #:device-type 'software - #:window-size '(640 480))) -(when (not device) - (exit #f)) - -(set-window-caption! device "Hello World! - Irrlicht Engine Demo") - -(define driver (get-video-driver device)) -(define scene-manager (get-scene-manager device)) -(define gui-env (get-gui-environment device)) - -;; static text -(add-static-text! - gui-env - "Hello World! This is the Irrlicht Software renderer!" - '(10 10 260 22) - #:border #t) - -;; load a Quake2 model -(define mesh (get-mesh scene-manager "media/sydney.md2")) -(when (not mesh) - (drop! device) - (exit #f)) - -(define node (add-animated-mesh-scene-node! scene-manager mesh)) -(when node - (set-material-flag! node 'lighting #f) - (set-md2-animation! node 'stand) - (set-material-texture! node 0 (get-texture driver "media/sydney.bmp"))) - -;; place camera -(add-camera-scene-node! scene-manager #:position '(0 30 -40) #:lookat '(0 5 0)) - -;; draw everything -(while (run device) - (begin-scene driver #:color '(255 100 101 140)) - (draw-all scene-manager) - (draw-all gui-env) - (end-scene driver)) - -;; delete device -(drop! device) -(exit #t) diff --git a/examples/02-quake3map.scm b/examples/02-quake3map.scm new file mode 100644 index 0000000..2087401 --- /dev/null +++ b/examples/02-quake3map.scm @@ -0,0 +1,96 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +;;; Irrlicht 02.Quake3Map example +;;; http://irrlicht.sourceforge.net/docu/example002.html + + +(use-modules (irrlicht) + (ice-9 match)) + +;; ask user for driver +(format #t + "Please select the driver you want for this example: + (a) OpenGL 1.5 + (b) Direct3D 9.0c + (c) Direct3D 8.1 + (d) Burning's Software Renderer + (e) Software Renderer + (f) NullDevice + (otherKey) exit~%~%") + +(define driver (match (read-char) + (#\a 'opengl) + (#\b 'direct3d9) + (#\c 'direct3d8) + (#\d 'burnings) + (#\e 'software) + (#\f 'null) + (_ #f))) + +(when (not driver) + (exit #f)) + +;; start up the engine +(define device + (create-device + #:device-type driver + #:window-size '(640 480))) +(when (not device) + (exit #f)) + +;; instances for doing things +(define driver (get-video-driver device)) +(define scene-manager (get-scene-manager device)) +(define driver-name (get-name driver)) + +;; load Quake3 map +(add-file-archive! (get-file-system device) "media/map-20kdm2.pk3") + +(define mesh (get-mesh scene-manager "20kdm2.bsp")) +(define node (add-octree-scene-node! + scene-manager mesh + #:minimal-polys-per-node 1024)) +(set-position! node '(-1300 -144 -1249)) + +;; FPS camera +(add-camera-scene-node-fps! scene-manager) +(set-visible! (get-cursor-control device) #f) + +;; loop +(define last-fps -1) +(while (run device) + (cond ((is-window-active? device) + (begin-scene driver #:color '(255 200 200 200)) + (draw-all scene-manager) + (end-scene driver) + + (let ((fps (get-fps driver))) + (when (not (= last-fps fps)) + (let ((caption + (format #f "Irrlicht Engine - Quake 3 Map example [~a] FPS:~a" driver-name fps))) + (set-window-caption! device caption)) + (set! last-fps fps)))) + (else + ((@ (irrlicht) yield) device)))) + +;; delete device +(drop! device) +(exit #t) diff --git a/examples/02.Quake3Map.scm b/examples/02.Quake3Map.scm deleted file mode 100644 index 2087401..0000000 --- a/examples/02.Quake3Map.scm +++ /dev/null @@ -1,96 +0,0 @@ -;;; guile-irrlicht --- FFI bindings for Irrlicht Engine -;;; Copyright (C) 2019 Javier Sancho -;;; -;;; This file is part of guile-irrlicht. -;;; -;;; Guile-irrlicht is free software; you can redistribute it and/or modify -;;; it under the terms of the GNU Lesser General Public License as -;;; published by the Free Software Foundation; either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; Guile-irrlicht is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU Lesser General Public -;;; License along with guile-irrlicht. If not, see -;;; . - - -;;; Irrlicht 02.Quake3Map example -;;; http://irrlicht.sourceforge.net/docu/example002.html - - -(use-modules (irrlicht) - (ice-9 match)) - -;; ask user for driver -(format #t - "Please select the driver you want for this example: - (a) OpenGL 1.5 - (b) Direct3D 9.0c - (c) Direct3D 8.1 - (d) Burning's Software Renderer - (e) Software Renderer - (f) NullDevice - (otherKey) exit~%~%") - -(define driver (match (read-char) - (#\a 'opengl) - (#\b 'direct3d9) - (#\c 'direct3d8) - (#\d 'burnings) - (#\e 'software) - (#\f 'null) - (_ #f))) - -(when (not driver) - (exit #f)) - -;; start up the engine -(define device - (create-device - #:device-type driver - #:window-size '(640 480))) -(when (not device) - (exit #f)) - -;; instances for doing things -(define driver (get-video-driver device)) -(define scene-manager (get-scene-manager device)) -(define driver-name (get-name driver)) - -;; load Quake3 map -(add-file-archive! (get-file-system device) "media/map-20kdm2.pk3") - -(define mesh (get-mesh scene-manager "20kdm2.bsp")) -(define node (add-octree-scene-node! - scene-manager mesh - #:minimal-polys-per-node 1024)) -(set-position! node '(-1300 -144 -1249)) - -;; FPS camera -(add-camera-scene-node-fps! scene-manager) -(set-visible! (get-cursor-control device) #f) - -;; loop -(define last-fps -1) -(while (run device) - (cond ((is-window-active? device) - (begin-scene driver #:color '(255 200 200 200)) - (draw-all scene-manager) - (end-scene driver) - - (let ((fps (get-fps driver))) - (when (not (= last-fps fps)) - (let ((caption - (format #f "Irrlicht Engine - Quake 3 Map example [~a] FPS:~a" driver-name fps))) - (set-window-caption! device caption)) - (set! last-fps fps)))) - (else - ((@ (irrlicht) yield) device)))) - -;; delete device -(drop! device) -(exit #t) diff --git a/examples/03-custom-scene-node.scm b/examples/03-custom-scene-node.scm new file mode 100644 index 0000000..21e5be8 --- /dev/null +++ b/examples/03-custom-scene-node.scm @@ -0,0 +1,128 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2019 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +;;; Irrlicht 03.CustomSceneNode example +;;; http://irrlicht.sourceforge.net/docu/example003.html + + +(use-modules (irrlicht) + (ice-9 match)) + +;; ask user for driver +(format #t + "Please select the driver you want for this example: + (a) OpenGL 1.5 + (b) Direct3D 9.0c + (c) Direct3D 8.1 + (d) Burning's Software Renderer + (e) Software Renderer + (f) NullDevice + (otherKey) exit~%~%") + +(define device-type (match (read-char) + (#\a 'opengl) + (#\b 'direct3d9) + (#\c 'direct3d8) + (#\d 'burnings) + (#\e 'software) + (#\f 'null) + (_ #f))) + +(when (not device-type) + (exit #f)) + +;; start up the engine +(define device + (create-device + #:device-type device-type + #:window-size '(640 480))) +(when (not device) + (exit #f)) + +;; create engine and camera +(set-window-caption! device "Custom Scene Node - Irrlicht Engine Demo") + +(define my-node #f) +(define driver (get-video-driver device)) +(define scene-manager (get-scene-manager device)) +(add-camera-scene-node! scene-manager + #:position '(0 -40 0) + #:lookat '(0 0 0)) + +;; create our custom scene node +(define box (make-box3d)) +(define vertices + (list (make-vertex3d '(0 0 10) '(1 1 0) '(255 0 255 255) '(0 1)) + (make-vertex3d '(10 0 -10) '(1 0 0) '(255 255 0 255) '(1 1)) + (make-vertex3d '(0 20 0) '(0 1 1) '(255 255 255 0) '(1 0)) + (make-vertex3d '(-10 0 -10) '(0 0 1) '(255 0 255 0) '(0 0)))) +(define material (make-material #:wireframe #f #:lighting #f)) + +(box3d-reset! box (vertex3d-position (car vertices))) +(for-each + (lambda (vertex) + (box3d-add-internal-point! box (vertex3d-position vertex))) + (cdr vertices)) + +(define (custom-render) + (let ((indices '((0 2 3) (2 1 3) (1 0 3) (2 0 1)))) + (set-material! driver material) + (set-transform! driver 'world (get-absolute-transformation my-node)) + (draw-vertex-primitive-list driver vertices indices))) + +(define (custom-get-bounding-box) + box) + +(define (custom-get-material-count) + 1) + +(define (custom-get-material i) + material) + +(set! my-node (add-custom-scene-node! scene-manager + custom-render + custom-get-bounding-box + custom-get-material-count + custom-get-material + #:parent (get-root-scene-node scene-manager))) + +;; add rotation +(let ((anim (create-rotation-animator scene-manager '(0.8 0 0.8)))) + (add-animator! my-node anim)) + +;; loop +(define frames 0) +(while (run device) + (begin-scene driver #:color '(0 100 100 100)) + (draw-all scene-manager) + (end-scene driver) + + (set! frames (+ frames 1)) + (when (= frames 100) + (let ((fps (get-fps driver)) + (driver-name (get-name driver))) + (let ((caption + (format #f "Irrlicht Engine [~a] FPS:~a" driver-name fps))) + (set-window-caption! device caption))) + (set! frames 0))) + +;; delete device +(drop! device) +(exit #t) diff --git a/examples/03.CustomSceneNode.scm b/examples/03.CustomSceneNode.scm deleted file mode 100644 index 21e5be8..0000000 --- a/examples/03.CustomSceneNode.scm +++ /dev/null @@ -1,128 +0,0 @@ -;;; guile-irrlicht --- FFI bindings for Irrlicht Engine -;;; Copyright (C) 2019 Javier Sancho -;;; -;;; This file is part of guile-irrlicht. -;;; -;;; Guile-irrlicht is free software; you can redistribute it and/or modify -;;; it under the terms of the GNU Lesser General Public License as -;;; published by the Free Software Foundation; either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; Guile-irrlicht is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU Lesser General Public -;;; License along with guile-irrlicht. If not, see -;;; . - - -;;; Irrlicht 03.CustomSceneNode example -;;; http://irrlicht.sourceforge.net/docu/example003.html - - -(use-modules (irrlicht) - (ice-9 match)) - -;; ask user for driver -(format #t - "Please select the driver you want for this example: - (a) OpenGL 1.5 - (b) Direct3D 9.0c - (c) Direct3D 8.1 - (d) Burning's Software Renderer - (e) Software Renderer - (f) NullDevice - (otherKey) exit~%~%") - -(define device-type (match (read-char) - (#\a 'opengl) - (#\b 'direct3d9) - (#\c 'direct3d8) - (#\d 'burnings) - (#\e 'software) - (#\f 'null) - (_ #f))) - -(when (not device-type) - (exit #f)) - -;; start up the engine -(define device - (create-device - #:device-type device-type - #:window-size '(640 480))) -(when (not device) - (exit #f)) - -;; create engine and camera -(set-window-caption! device "Custom Scene Node - Irrlicht Engine Demo") - -(define my-node #f) -(define driver (get-video-driver device)) -(define scene-manager (get-scene-manager device)) -(add-camera-scene-node! scene-manager - #:position '(0 -40 0) - #:lookat '(0 0 0)) - -;; create our custom scene node -(define box (make-box3d)) -(define vertices - (list (make-vertex3d '(0 0 10) '(1 1 0) '(255 0 255 255) '(0 1)) - (make-vertex3d '(10 0 -10) '(1 0 0) '(255 255 0 255) '(1 1)) - (make-vertex3d '(0 20 0) '(0 1 1) '(255 255 255 0) '(1 0)) - (make-vertex3d '(-10 0 -10) '(0 0 1) '(255 0 255 0) '(0 0)))) -(define material (make-material #:wireframe #f #:lighting #f)) - -(box3d-reset! box (vertex3d-position (car vertices))) -(for-each - (lambda (vertex) - (box3d-add-internal-point! box (vertex3d-position vertex))) - (cdr vertices)) - -(define (custom-render) - (let ((indices '((0 2 3) (2 1 3) (1 0 3) (2 0 1)))) - (set-material! driver material) - (set-transform! driver 'world (get-absolute-transformation my-node)) - (draw-vertex-primitive-list driver vertices indices))) - -(define (custom-get-bounding-box) - box) - -(define (custom-get-material-count) - 1) - -(define (custom-get-material i) - material) - -(set! my-node (add-custom-scene-node! scene-manager - custom-render - custom-get-bounding-box - custom-get-material-count - custom-get-material - #:parent (get-root-scene-node scene-manager))) - -;; add rotation -(let ((anim (create-rotation-animator scene-manager '(0.8 0 0.8)))) - (add-animator! my-node anim)) - -;; loop -(define frames 0) -(while (run device) - (begin-scene driver #:color '(0 100 100 100)) - (draw-all scene-manager) - (end-scene driver) - - (set! frames (+ frames 1)) - (when (= frames 100) - (let ((fps (get-fps driver)) - (driver-name (get-name driver))) - (let ((caption - (format #f "Irrlicht Engine [~a] FPS:~a" driver-name fps))) - (set-window-caption! device caption))) - (set! frames 0))) - -;; delete device -(drop! device) -(exit #t) diff --git a/examples/04-movement.scm b/examples/04-movement.scm new file mode 100644 index 0000000..e0592c3 --- /dev/null +++ b/examples/04-movement.scm @@ -0,0 +1,157 @@ +;;; guile-irrlicht --- FFI bindings for Irrlicht Engine +;;; Copyright (C) 2020 Javier Sancho +;;; +;;; This file is part of guile-irrlicht. +;;; +;;; Guile-irrlicht is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-irrlicht is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-irrlicht. If not, see +;;; . + + +;;; Irrlicht 04.Movement example +;;; http://irrlicht.sourceforge.net/docu/example004.html + + +(use-modules (irrlicht) + (ice-9 match)) + +;; ask user for driver +(format #t + "Please select the driver you want for this example: + (a) OpenGL 1.5 + (b) Direct3D 9.0c + (c) Direct3D 8.1 + (d) Burning's Software Renderer + (e) Software Renderer + (f) NullDevice + (otherKey) exit~%~%") + +(define device-type (match (read-char) + (#\a 'opengl) + (#\b 'direct3d9) + (#\c 'direct3d8) + (#\d 'burnings) + (#\e 'software) + (#\f 'null) + (_ #f))) + +(when (not device-type) + (exit #f)) + +;; create event receiver +(define key-is-down '()) +(define (is-key-down? key-code) + (assoc-ref key-is-down key-code)) + +(define (on-event event) + (if (equal? (event-type event) 'key-input-event) + (set! key-is-down + (assoc-set! key-is-down + (event-key-input-key event) + (event-key-input-pressed event)))) + #f) + +(define receiver (make-event-receiver on-event)) + +;; create device +(define device + (create-device + #:device-type device-type + #:window-size '(640 480) + #:receiver receiver)) +(when (not device) + (exit #f)) + +(define driver (get-video-driver device)) +(define scene-manager (get-scene-manager device)) +(define gui-env (get-gui-environment device)) + +;; create the node which will be moved with the WSAD keys +(define ball (add-sphere-scene-node! scene-manager)) +(set-position! ball '(0 0 30)) +(set-material-texture! ball 0 (get-texture driver "media/wall.bmp")) +(set-material-flag! ball 'lighting #f) + +;; create another node, movable using a scene node animator +(let ((cube (add-cube-scene-node! scene-manager)) + (anim (create-fly-circle-animator scene-manager #:center '(0 0 30) #:radius 20))) + (set-material-texture! cube 0 (get-texture driver "media/t351sml.jpg")) + (set-material-flag! cube 'lighting #f) + (add-animator! cube anim) + (drop! anim)) + +;; another scene with a b3d model and a 'fly straight' animator +(let ((ninja (add-animated-mesh-scene-node! + scene-manager (get-mesh scene-manager "media/ninja.b3d"))) + (anim (create-fly-straight-animator + scene-manager '(100 0 60) '(-100 0 60) 3500 #:loop #t))) + (add-animator! ninja anim) + (drop! anim) + + ;; make the model look right + (set-material-flag! ninja 'lighting #f) + (set-frame-loop! ninja 0 13) + (set-animation-speed! ninja 15) + (set-scale! ninja '(2 2 2)) + (set-rotation! ninja '(0 -90 0))) + +;; create a first person shooter camera +(add-camera-scene-node-fps! scene-manager) +(set-visible! (get-cursor-control device) #f) + +;; colorful irrlicht logo +(add-image! gui-env (get-texture driver "media/irrlichtlogoalpha2.tga") '(10 20)) +(let ((diagnostics (add-static-text! gui-env "" '(10 10 400 20)))) + (set-override-color! diagnostics '(255 255 255 0))) + +;; game loop +(let ((timer (get-timer device)) + (driver-name (get-name driver))) + (let ((last-fps -1) + (then (get-time timer)) + (movement-speed 5)) + (while (run device) + (let* ((now (get-time timer)) + (frame-delta-time (/ (- now then) 1000))) + (set! then now) + + ;; check if W, S, A or D are pressed + (let* ((node-position (get-position ball)) + (pos-x (car node-position)) + (pos-y (cadr node-position)) + (pos-z (caddr node-position))) + (if (is-key-down? 'key-w) + (set! pos-y (+ pos-y (* movement-speed frame-delta-time)))) + (if (is-key-down? 'key-s) + (set! pos-y (- pos-y (* movement-speed frame-delta-time)))) + (if (is-key-down? 'key-a) + (set! pos-x (- pos-x (* movement-speed frame-delta-time)))) + (if (is-key-down? 'key-d) + (set! pos-x (+ pos-x (* movement-speed frame-delta-time)))) + (set-position! ball (list pos-x pos-y pos-z)))) + + (begin-scene driver #:color '(255 113 113 133)) + (draw-all scene-manager) + (draw-all gui-env) + (end-scene driver) + + (let ((fps (get-fps driver))) + (when (not (= last-fps fps)) + (let ((caption + (format #f "Movement Example - Irrlicht Engine [~a] fps: ~a" driver-name fps))) + (set-window-caption! device caption)) + (set! last-fps fps)))))) + +;; delete device +(drop! device) +(exit #t) diff --git a/examples/04.Movement.scm b/examples/04.Movement.scm deleted file mode 100644 index e0592c3..0000000 --- a/examples/04.Movement.scm +++ /dev/null @@ -1,157 +0,0 @@ -;;; guile-irrlicht --- FFI bindings for Irrlicht Engine -;;; Copyright (C) 2020 Javier Sancho -;;; -;;; This file is part of guile-irrlicht. -;;; -;;; Guile-irrlicht is free software; you can redistribute it and/or modify -;;; it under the terms of the GNU Lesser General Public License as -;;; published by the Free Software Foundation; either version 3 of the -;;; License, or (at your option) any later version. -;;; -;;; Guile-irrlicht is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU Lesser General Public -;;; License along with guile-irrlicht. If not, see -;;; . - - -;;; Irrlicht 04.Movement example -;;; http://irrlicht.sourceforge.net/docu/example004.html - - -(use-modules (irrlicht) - (ice-9 match)) - -;; ask user for driver -(format #t - "Please select the driver you want for this example: - (a) OpenGL 1.5 - (b) Direct3D 9.0c - (c) Direct3D 8.1 - (d) Burning's Software Renderer - (e) Software Renderer - (f) NullDevice - (otherKey) exit~%~%") - -(define device-type (match (read-char) - (#\a 'opengl) - (#\b 'direct3d9) - (#\c 'direct3d8) - (#\d 'burnings) - (#\e 'software) - (#\f 'null) - (_ #f))) - -(when (not device-type) - (exit #f)) - -;; create event receiver -(define key-is-down '()) -(define (is-key-down? key-code) - (assoc-ref key-is-down key-code)) - -(define (on-event event) - (if (equal? (event-type event) 'key-input-event) - (set! key-is-down - (assoc-set! key-is-down - (event-key-input-key event) - (event-key-input-pressed event)))) - #f) - -(define receiver (make-event-receiver on-event)) - -;; create device -(define device - (create-device - #:device-type device-type - #:window-size '(640 480) - #:receiver receiver)) -(when (not device) - (exit #f)) - -(define driver (get-video-driver device)) -(define scene-manager (get-scene-manager device)) -(define gui-env (get-gui-environment device)) - -;; create the node which will be moved with the WSAD keys -(define ball (add-sphere-scene-node! scene-manager)) -(set-position! ball '(0 0 30)) -(set-material-texture! ball 0 (get-texture driver "media/wall.bmp")) -(set-material-flag! ball 'lighting #f) - -;; create another node, movable using a scene node animator -(let ((cube (add-cube-scene-node! scene-manager)) - (anim (create-fly-circle-animator scene-manager #:center '(0 0 30) #:radius 20))) - (set-material-texture! cube 0 (get-texture driver "media/t351sml.jpg")) - (set-material-flag! cube 'lighting #f) - (add-animator! cube anim) - (drop! anim)) - -;; another scene with a b3d model and a 'fly straight' animator -(let ((ninja (add-animated-mesh-scene-node! - scene-manager (get-mesh scene-manager "media/ninja.b3d"))) - (anim (create-fly-straight-animator - scene-manager '(100 0 60) '(-100 0 60) 3500 #:loop #t))) - (add-animator! ninja anim) - (drop! anim) - - ;; make the model look right - (set-material-flag! ninja 'lighting #f) - (set-frame-loop! ninja 0 13) - (set-animation-speed! ninja 15) - (set-scale! ninja '(2 2 2)) - (set-rotation! ninja '(0 -90 0))) - -;; create a first person shooter camera -(add-camera-scene-node-fps! scene-manager) -(set-visible! (get-cursor-control device) #f) - -;; colorful irrlicht logo -(add-image! gui-env (get-texture driver "media/irrlichtlogoalpha2.tga") '(10 20)) -(let ((diagnostics (add-static-text! gui-env "" '(10 10 400 20)))) - (set-override-color! diagnostics '(255 255 255 0))) - -;; game loop -(let ((timer (get-timer device)) - (driver-name (get-name driver))) - (let ((last-fps -1) - (then (get-time timer)) - (movement-speed 5)) - (while (run device) - (let* ((now (get-time timer)) - (frame-delta-time (/ (- now then) 1000))) - (set! then now) - - ;; check if W, S, A or D are pressed - (let* ((node-position (get-position ball)) - (pos-x (car node-position)) - (pos-y (cadr node-position)) - (pos-z (caddr node-position))) - (if (is-key-down? 'key-w) - (set! pos-y (+ pos-y (* movement-speed frame-delta-time)))) - (if (is-key-down? 'key-s) - (set! pos-y (- pos-y (* movement-speed frame-delta-time)))) - (if (is-key-down? 'key-a) - (set! pos-x (- pos-x (* movement-speed frame-delta-time)))) - (if (is-key-down? 'key-d) - (set! pos-x (+ pos-x (* movement-speed frame-delta-time)))) - (set-position! ball (list pos-x pos-y pos-z)))) - - (begin-scene driver #:color '(255 113 113 133)) - (draw-all scene-manager) - (draw-all gui-env) - (end-scene driver) - - (let ((fps (get-fps driver))) - (when (not (= last-fps fps)) - (let ((caption - (format #f "Movement Example - Irrlicht Engine [~a] fps: ~a" driver-name fps))) - (set-window-caption! device caption)) - (set! last-fps fps)))))) - -;; delete device -(drop! device) -(exit #t)