This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.sh
92 lines (77 loc) · 1.48 KB
/
test.sh
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /bin/bash
FACTOR=1
. sincos.sh
. vec.sh
. mat.sh
function assertV ()
{
v=$(eval "echo \$$2")
if [ "$v" = "$3" ]; then
echo $1 :OK
else
echo $1 :NG $2 is not $3 -\> $v
exit -1
fi
}
function assertL ()
{
v=\($(eval echo $(eval echo "\$\{$2[@]\}"))\)
if [ "${v[@]}" = "$3" ]; then
echo $1 :OK
else
echo $1 :NG $2 is not $3 -\> $v
exit -1
fi
}
function main() {
v1=(VEC 1 2 3 4)
v2=(VEC 1 2 3 4)
v3=0
vDot v2 v2 v3
assertV vDot v3 30
v1=(VEC 1 2 3 4)
v2=(VEC 1 2 3 4)
v3=0
vMul v2 2 v3
assertL vMul v3 "(VEC 2 4 6 8)"
v1=(VEC 2 4 6 6)
v3=0
vDiv v1 2 v3
assertL vDiv v3 "(VEC 1 2 3 3)"
v1=(VEC 1 2 3 4)
v2=(VEC 1 2 3 5)
v3=0
vSub v1 v2 v3
assertL vSub v3 "(VEC 0 0 0 -1)"
v1=(VEC 1 2 3 4)
v2=(VEC 1 2 3 5)
v3=0
vAdd v1 v2 v3
assertL vAdd v3 "(VEC 2 4 6 9)"
FACTOR=10
m1=(MAT\
10 10 10 10\
0 10 0 0\
0 0 10 0\
0 0 0 10\
)
mMul m1 m1 v3
assertL mMul v3 "(MAT 10 20 20 20 0 10 0 0 0 0 10 0 0 0 0 10)"
v1=(VEC 10 20 30 40)
mvMul m1 v1 v3
assertL mvMul v3 "(VEC 100 20 30 40)"
FACTOR=1
mScale 1 2 3 v3
assertL mScale v3 "(MAT 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0 1)"
mTrans 1 2 3 v3
assertL mTrans v3 "(MAT 1 0 0 1 0 1 0 2 0 0 1 3 0 0 0 1)"
mRotate 1 2 3 0 v3
assertL mRotate v3 "(MAT 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1)"
mRotate 0 0 1 180 v3
assertL mRotate v3 "(MAT -1 0 0 0 0 -1 0 0 0 0 1 0 0 0 0 1)"
FACTOR=10
mFrustum -10 10 10 -10 20 100 v3
assertL mFrustum v3 "(MAT 20 0 0 0 0 -20 0 0 0 0 -15 50 0 0 -10 0)"
FACTOR=1
}
main