blob: 7f362806edfb30a1cb80a4f6f89568d4e04d76e6 (
plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
|
;;; Chickadee Game Toolkit
;;; Copyright © 2022 David Thompson <dthompson2@worcester.edu>
;;;
;;; Chickadee 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.
;;;
;;; Chickadee 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 (tests matrix)
#:use-module (tests utils)
#:use-module (srfi srfi-64)
#:use-module (chickadee math)
#:use-module (chickadee math matrix)
#:use-module (chickadee math quaternion)
#:use-module (chickadee math vector))
(with-tests "matrix"
(test-group "4x4 matrices"
(test-group "multiplication"
(test-assert "identity"
(let ((m (make-matrix4 0 1 2 3
4 5 6 7
8 9 0 1
2 3 4 5)))
(matrix4= m (matrix4* (make-identity-matrix4) m))))
(test-assert "inverse"
;; Using whole numbers to avoid floating point precision
;; issues where the resulting identity matrix has values very
;; close to 1.0 (like 0.9999999403953552) but not exactly,
;; causing the test to fail.
(let ((m (matrix4-scale (vec3 2 3 4))))
(matrix4= (make-identity-matrix4)
(matrix4* m (matrix4-inverse m))))))
(test-group "transformation"
(test-assert "identity (vec2)"
(let ((v (vec2 1 2)))
(vec2= v (matrix4-transform-vec2 (make-identity-matrix4) v))))
(test-assert "identity (vec3)"
(let ((v (vec3 1 2 3)))
(vec3= v (matrix4-transform-vec3 (make-identity-matrix4) v))))
(test-assert "translate"
(vec3= (vec3 5 7 9)
(matrix4-transform-vec3 (matrix4-translate (vec3 4 5 6))
(vec3 1 2 3))))
(test-assert "scale"
(vec3= (vec3 6 12 20)
(matrix4-transform-vec3 (matrix4-scale (vec3 3 4 5))
(vec3 2 3 4))))
(test-assert "rotate"
(vec3= (vec3 0 1 0)
(matrix4-transform-vec3 (matrix4-rotate
(rotation->quaternion (vec3 0 0 -1)
(/ pi 2)))
(vec3 1 0 0)))))))
|