]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - irrlicht/aabbox3d.scm
Support for aabbox3d
[guile-irrlicht.git] / irrlicht / aabbox3d.scm
diff --git a/irrlicht/aabbox3d.scm b/irrlicht/aabbox3d.scm
new file mode 100644 (file)
index 0000000..55d71a4
--- /dev/null
@@ -0,0 +1,63 @@
+;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
+;;; Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+
+
+(define-module (irrlicht aabbox3d)
+  #:use-module (srfi srfi-9)
+  #:use-module (srfi srfi-9 gnu)
+  #:use-module (system foreign)
+  #:use-module ((irrlicht bindings core) #:prefix ffi-core:)
+  #:export (make-aabbox3d
+            aabbox3d-min-edge
+            aabbox3d-max-edge
+            aabbox3d-reset!
+            aabbox3d-add-internal-point!))
+
+(define-record-type <aabbox3d>
+  (make-raw-aabbox3d c-pointer)
+  aabbox3d?
+  (c-pointer aabbox3d-c-pointer))
+
+(define* (make-aabbox3d #:optional (min-edge '(0 0 0)) (max-edge min-edge))
+  (make-raw-aabbox3d
+   (make-c-struct ffi-core:aabbox3d_f32 (append min-edge max-edge))))
+
+(define (aabbox3d-min-edge box)
+  (let ((data (parse-c-struct (aabbox3d-c-pointer box) ffi-core:aabbox3d_f32)))
+    (list-head data 3)))
+
+(define (aabbox3d-max-edge box)
+  (let ((data (parse-c-struct (aabbox3d-c-pointer box) ffi-core:aabbox3d_f32)))
+    (list-tail data 3)))
+
+(define (aabbox3d-reset! box point)
+  (ffi-core:aabbox3d-reset
+   (aabbox3d-c-pointer box)
+   (make-c-struct ffi-core:vector3df point)))
+
+(define (aabbox3d-add-internal-point! box point)
+  (ffi-core:aabbox3d-add-internal-point
+   (aabbox3d-c-pointer box)
+   (make-c-struct ffi-core:vector3df point)))
+
+(set-record-type-printer! <aabbox3d>
+  (lambda (record port)
+    (let ((min (aabbox3d-min-edge record))
+          (max (aabbox3d-max-edge record)))
+      (format port "#<aabbox3d min: ~a max: ~a>" min max))))