Fix maths module's vec* macros and mperspective

This commit is contained in:
Renaud Casenave-Péré 2015-08-27 18:35:25 +02:00
parent 0a5d24fe3e
commit 4985c8a179
2 changed files with 51 additions and 34 deletions

View file

@ -71,8 +71,8 @@
(top range))
(mat (/ (* near 2) (- right left)) 0.0 0.0 0.0
0.0 (/ (* near 2) (- top bottom)) 0.0 0.0
0.0 0.0 (/ (+ far near) (- near far)) (/ (* 2.0 far near) (- near far))
0.0 0.0 -1.0 0.0))))
0.0 0.0 (/ (+ far near) (- near far)) -1.0
0.0 0.0 (/ (* 2.0 far near) (- near far)) 0.0))))
(defun morthogonal (width height)
(mat (/ 2.0 width) 0.0 0.0 0.0

View file

@ -74,44 +74,61 @@
:displaced-index-offset index))))
(defmacro vec (&rest attribs)
(let ((dim (list '+ 0)) type)
(loop for attr in attribs
do (progn
(unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum))))
(if (numberp attr)
(setf (cadr dim) (1+ (cadr dim)))
(setf dim (append dim (list `(dimensions ,attr)))))))
`(make-vector ,(if (eq (cddr dim) nil) (cadr dim) dim) ',type ,@attribs)))
(once-only ((attrib (first attribs)))
(let ((dim (list '+ 0)) type)
(loop for attr in attribs
do (progn
(unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum))))
(if (numberp attr)
(setf (cadr dim) (1+ (cadr dim)))
(setf dim (append dim (list `(dimensions ,attr)))))))
`(make-vector ,(if (eq (cddr dim) nil) (cadr dim) dim)
,(if type
`',type
`(element-type ,attrib))
,@attribs))))
(defmacro vec2 (&rest attribs)
(let (type)
(loop for attr in attribs
do (unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum)))))
`(make-vector 2 ',type ,@attribs)))
(once-only ((attrib (first attribs)))
(let (type)
(loop for attr in attribs
do (unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum)))))
`(make-vector 2 ,(if type
`',type
`(element-type ,attrib))
,@attribs))))
(defmacro vec3 (&rest attribs)
(let (type)
(loop for attr in attribs
do (unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum)))))
`(make-vector 3 ',type ,@attribs)))
(once-only ((attrib (first attribs)))
(let (type)
(loop for attr in attribs
do (unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum)))))
`(make-vector 3 ,(if type
`',type
`(element-type ,attrib))
,@attribs))))
(defmacro vec4 (&rest attribs)
(let (type)
(loop for attr in attribs
do (unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum)))))
`(make-vector 4 ',type ,@attribs)))
(once-only ((attrib (first attribs)))
(let (type)
(loop for attr in attribs
do (unless type
(setf type (cond
((floatp attr) 'single-float)
((integerp attr) 'fixnum)))))
`(make-vector 4 ,(if type
`',type
`(element-type ,attrib))
,@attribs))))
(defmacro defswizzle (attribs)
(labels ((index (attr)