Menu

[r760]: / trunk / lispbuilder-openrm / cffi / translate.lisp  Maximize  Restore  History

Download this file

55 lines (39 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;; OpenRM library using CFFI for foreign function interfacing...
;; (C)2006 Luke Crook <luke@balooga.com>
;; see COPYING for license
(in-package #:lispbuilder-openrm-cffi)
;; (defun create-list-if-not (var)
;; (if (listp var)
;; var
;; (list var)))
;; (defun vertex-copy (vertices vertex-array)
;; (let ((index 0))
;; (mapcar #'(lambda (vertex)
;; (copy-to-foreign-vertex vertex (cffi:mem-aref vertex-array 'rm-vertex-3d index))
;; (incf index))
;; vertices))
;; vertex-array)
;; (defun color-copy (colors col-array)
;; (let ((index 0))
;; (mapcar #'(lambda (color)
;; (copy-to-foreign-color color (cffi:mem-aref col-array 'RM-color-4D index))
;; (incf index))
;; colors))
;; col-array)
(defctype s-float :float)
;; (defcstruct matrix
;; (m s-float :count 16))
(defmethod translate-to-foreign (value (type (eql 's-float)))
(coerce value 'single-float))
(defmethod translate-to-foreign (value (type (eql 'float-pointer)))
(let ((float-ptr (cffi:foreign-alloc :float)))
(setf (cffi:mem-aref float-ptr :float) value)
(values float-ptr t)))
(defmethod translate-to-foreign (value (type (eql 'float-array)))
(values (cffi:foreign-alloc :float :count (length value) :initial-contents value) t))
(defmethod free-translated-object (ptr (name (eql 'float-pointer)) free-p)
(if free-p
(cffi:foreign-free ptr)))
(defmethod free-translated-object (ptr (name (eql 'float-array)) free-p)
(if free-p
(cffi:foreign-free ptr)))
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.