forked from unitoftime/glitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_test.go
49 lines (42 loc) · 814 Bytes
/
math_test.go
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
package glitch
import (
"fmt"
"testing"
)
func TestDotProduct(t *testing.T) {
a := Vec3{1, 2, 3}
b := Vec3{1, 5, 7}
dot := a.Dot(b)
if dot != 32 {
panic("Should be 32")
}
}
func TestAngle(t *testing.T) {
a := Vec3{2, -4, -1}
b := Vec3{1, 5, 2}
angle := a.Angle(b)
// Should be: 2.4928086
fmt.Println(angle)
}
func TestRotate(t *testing.T) {
a := Vec3{1, 0, 0}
b := a.Rotate2D(3.14159/2)
fmt.Println(b)
}
func TestProjectUnproject(t *testing.T) {
data := []Vec3{
Vec3{},
Vec3{1, 2, 3},
}
// Arbitrary matrix
mat := Mat4Ident
mat.Translate(-100.2, -200.8, 0).
Scale(0.7, 0.4, 1.0).
Translate(200.9, 300.1, 0)
for i := range data {
intermediate := mat.Apply(data[i])
result := mat.Inv().Apply(intermediate)
fmt.Println("In: ", data[i])
fmt.Println("Out: ", result)
}
}