]> git.jsancho.org Git - guile-assimp.git/commitdiff
New struct types ai-matrix3x3 and ai-matrix4x4
authorJavier Sancho <jsf@jsancho.org>
Thu, 17 Jul 2014 11:13:26 +0000 (13:13 +0200)
committerJavier Sancho <jsf@jsancho.org>
Thu, 17 Jul 2014 11:13:26 +0000 (13:13 +0200)
* src/assimp.scm: New conversion types for matrixes; before matrixes
  were list of numbers.

* src/low-level.scm: Parsers can reverse conversion from scheme to C.

* src/low-level/matrix.scm: New struct types from C matrixes.

src/assimp.scm
src/low-level.scm
src/low-level/matrix.scm [new file with mode: 0644]

index 5c8ccd2b99df311616aa3d2eb292d1be4e818ad2..9954e8212bcb47cab6f070bc22e4f80654e091bb 100644 (file)
@@ -20,6 +20,7 @@
   #:use-module (assimp low-level cimport)
   #:use-module (assimp low-level color)
   #:use-module (assimp low-level material)
+  #:use-module (assimp low-level matrix)
   #:use-module (assimp low-level mesh)
   #:use-module (assimp low-level scene)
   #:use-module (assimp low-level types)
@@ -55,7 +56,7 @@
 
 (define-conversion-type parse-aiNode -> ai-node
   (name (sized-string (field 'mName)))
-  (transformation (field 'mTransformation))
+  (transformation (wrap (parse-aiMatrix4x4 (field 'mTransformation) #:reverse #t) wrap-ai-matrix4x4))
   (parent (wrap (field 'mParent) wrap-ai-node))
   (children (wrap (array (field 'mNumChildren) (field 'mChildren)) wrap-ai-node))
   (meshes (array (field 'mNumMeshes) (field 'mMeshes))))
        ai-vector3d-z)
 
 
+;;; Matrixes
+
+(define-conversion-type parse-aiMatrix3x3 -> ai-matrix3x3
+  (a1 (field 'a1))
+  (a2 (field 'a2))
+  (a3 (field 'a3))
+  (b1 (field 'b1))
+  (b2 (field 'b2))
+  (b3 (field 'b3))
+  (c1 (field 'c1))
+  (c2 (field 'c2))
+  (c3 (field 'c3)))
+
+(export ai-matrix3x3?
+       ai-matrix3x3-contents
+       ai-matrix3x3-a1
+       ai-matrix3x3-a2
+       ai-matrix3x3-a3
+       ai-matrix3x3-b1
+       ai-matrix3x3-b2
+       ai-matrix3x3-b3
+       ai-matrix3x3-c1
+       ai-matrix3x3-c2
+       ai-matrix3x3-c3)
+
+(define-conversion-type parse-aiMatrix4x4 -> ai-matrix4x4
+  (a1 (field 'a1))
+  (a2 (field 'a2))
+  (a3 (field 'a3))
+  (a4 (field 'a4))
+  (b1 (field 'b1))
+  (b2 (field 'b2))
+  (b3 (field 'b3))
+  (b4 (field 'b4))
+  (c1 (field 'c1))
+  (c2 (field 'c2))
+  (c3 (field 'c3))
+  (c4 (field 'c4))
+  (d1 (field 'd1))
+  (d2 (field 'd2))
+  (d3 (field 'd3))
+  (d4 (field 'd4)))
+
+(export ai-matrix4x4?
+       ai-matrix4x4-contents
+       ai-matrix4x4-a1
+       ai-matrix4x4-a2
+       ai-matrix4x4-a3
+       ai-matrix4x4-a4
+       ai-matrix4x4-b1
+       ai-matrix4x4-b2
+       ai-matrix4x4-b3
+       ai-matrix4x4-b4
+       ai-matrix4x4-c1
+       ai-matrix4x4-c2
+       ai-matrix4x4-c3
+       ai-matrix4x4-c4
+       ai-matrix4x4-d1
+       ai-matrix4x4-d2
+       ai-matrix4x4-d3
+       ai-matrix4x4-d4)
+
+
 ;;; Colors
 
 (define-conversion-type parse-aiColor4D -> ai-color4d
   (weights (wrap
            (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address)
            wrap-ai-vertex-weight))
-  (offset-matrix (field 'mOffsetMatrix)))
+  (offset-matrix (wrap (parse-aiMatrix4x4 (field 'mOffsetMatrix) #:reverse #t) wrap-ai-matrix4x4)))
 
 (export ai-bone?
        ai-bone-contents
                 flags)))
 
 (define-public (ai-multiply-matrix4 m1 m2)
-  (let ((cm1 (make-c-struct aiMatrix4x4-type m1))
-       (cm2 (make-c-struct aiMatrix4x4-type m2)))
+  (let ((cm1 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m1)) #:reverse #t))
+       (cm2 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m2)) #:reverse #t)))
     (aiMultiplyMatrix4 cm1 cm2)
-    (parse-c-struct cm1 aiMatrix4x4-type)))
+    (wrap-ai-matrix4x4 cm1)))
index d604789712e14939ca66c66fa64c3a1cb4baf6b3..fd7af9ddea932881e7decdd718c69107d0bde48a 100644 (file)
   #:use-module (system foreign))
 
 
+(define (mk-string . args)
+  (string-concatenate
+   (map (lambda (a)
+         (if (string? a)
+             a
+             (symbol->string (syntax->datum a))))
+       args)))
+
+(define (lambda-mk-symbol x)
+  (lambda args
+    (datum->syntax x
+      (string->symbol
+       (apply mk-string args)))))
+
+
 ;;; Parsers Definition
 
 (define-syntax define-struct-parser
       ((_ name (field type) ...)
        (with-syntax (((field-name ...) (map car #'((field type) ...)))
                     ((field-type ...) (map cadr #'((field type) ...))))
-         #'(define (name pointer)
-            (map cons
-                 '(field-name ...)
-                 (parse-c-struct pointer (list field-type ...)))))))))
+         #'(define* (name pointer-or-data #:key (reverse #f))
+            (cond (reverse
+                   (make-c-struct
+                    (list field-type ...)
+                    pointer-or-data))
+                  (else
+                   (map cons
+                        '(field-name ...)
+                        (parse-c-struct pointer-or-data (list field-type ...)))))))))))
 
 (export-syntax define-struct-parser)
 
 
 (define-syntax define-conversion-type
   (lambda (x)
-    (define (mk-string . args)
-      (string-concatenate
-       (map (lambda (a)
-             (if (string? a)
-                 a
-                 (symbol->string (syntax->datum a))))
-           args)))
-    (define (mk-symbol . args)
-      (datum->syntax x
-        (string->symbol
-        (apply mk-string args))))
+    (define mk-symbol (lambda-mk-symbol x))
     (syntax-case x (->)
       ((_ parser -> name (field-name field-proc) ...)
        (with-syntax ((type? (mk-symbol #'name "?"))
diff --git a/src/low-level/matrix.scm b/src/low-level/matrix.scm
new file mode 100644 (file)
index 0000000..416b4d0
--- /dev/null
@@ -0,0 +1,53 @@
+;;; guile-assimp, foreign interface to libassimp
+;;; Copyright (C) 2014 by Javier Sancho Fernandez <jsf at jsancho dot org>
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program 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 General Public License
+;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+(define-module (assimp low-level matrix)
+  #:use-module (assimp low-level)
+  #:use-module (system foreign))
+
+
+(define-struct-parser parse-aiMatrix3x3
+  (a1 float)
+  (a2 float)
+  (a3 float)
+  (b1 float)
+  (b2 float)
+  (b3 float)
+  (c1 float)
+  (c2 float)
+  (c3 float))
+
+(define-struct-parser parse-aiMatrix4x4
+  (a1 float)
+  (a2 float)
+  (a3 float)
+  (a4 float)
+  (b1 float)
+  (b2 float)
+  (b3 float)
+  (b4 float)
+  (c1 float)
+  (c2 float)
+  (c3 float)
+  (c4 float)
+  (d1 float)
+  (d2 float)
+  (d3 float)
+  (d4 float))
+
+(export parse-aiMatrix3x3
+       parse-aiMatrix4x4)