2 (in-package :cl-tuples
)
4 (def-tuple-type matrix33
5 :tuple-element-type single-float
10 (export-tuple-operations matrix33
)
12 (def-tuple-type matrix44
13 :tuple-element-type single-float
14 :elements
(e00 e01 e02 e03
19 (export-tuple-operations matrix44
)
21 (defmacro matrix-dot
(dimension row col
)
22 "Generate the symbols required for a dot
23 product between the row and column of a matrix"
25 ((make-matrix-element-symbol (mat row col
)
26 (intern (string-upcase (format nil
"e~A~A~A" mat row col
)) :cl-tuples
)))
29 (loop for row from
0 below dimension
30 collect
(make-matrix-element-symbol 0 row col
)))
32 (loop for col from
0 below dimension
33 collect
(make-matrix-element-symbol 1 row col
))))
36 for col-sym in col-sym-names
37 for row-sym in row-sym-names
38 collect
`(* ,col-sym
,row-sym
))))))
41 (defmacro transform-vertex2d
(matrix33 vertex2d
)
45 ,matrix33
(e00 e01 e02
49 (+ (* x e00
) (* y e01
) (* w e02
))
50 (+ (* x e10
) (* y e11
) (* w e12
))
51 (+ (* x e20
) (* y e21
) (* w e22
))))))
53 (defmacro transform-vector2d
(matrix33 vector2d
)
57 ,matrix33
(e00 e01 e02
61 (+ (* x e00
) (* y e01
))
62 (+ (* x e10
) (* y e11
))
63 (+ (* x e20
) (* y e21
))))))
65 (defmacro matrix33-product
(m0 m1
)
85 (matrix-dot 3 2 2)))))
88 (defmacro transform-vertex3d
(matrix44 vertex3d
)
92 ,matrix44
(e00 e01 e02 e03
97 (+ (* x e00
) (* y e01
) (* z e02
) (* w e03
))
98 (+ (* x e10
) (* y e11
) (* z e02
) (* w e13
))
99 (+ (* x e20
) (* y e21
) (* z e02
) (* w e23
))
100 (+ (* x e30
) (* y e31
) (* z e32
) (* w e33
))))))
102 (defmacro transform-vector3d
(matrix44 vector3d
)
106 ,matrix44
(e00 e01 e02 e03
111 (+ (* x e00
) (* y e01
) (* z e02
))
112 (+ (* x e10
) (* y e11
) (* z e02
))
113 (+ (* x e20
) (* y e21
) (* z e02
))
114 (+ (* x e30
) (* y e31
) (* z e32
))))))
117 (defmacro matrix44-product
(m0 m1
)
147 (matrix-dot 4 3 3)))))
150 (defun identity-matrix44 ()
157 (defmacro translation-matrix44
(tx ty tz
)
164 (defmacro rotatex-matrix44
(a)
171 (,nsina
,(- (sin a
)))
179 (defmacro rotatey-matrix44
(a)
186 (,nsina
,(- (sin a
)))
194 (defmacro rotatez-matrix44
(a)
201 (,nsina
,(- (sin a
)))