2020-02-03 05:00:36 +01:00
|
|
|
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
2019-06-25 15:38:00 +02:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2019-09-23 12:42:20 +02:00
|
|
|
// might need special case for this
|
|
|
|
// import gl
|
2019-07-12 07:37:54 +02:00
|
|
|
import glm
|
2019-06-25 15:38:00 +02:00
|
|
|
|
2019-06-26 01:26:26 +02:00
|
|
|
fn cmp(a, b f32) bool {
|
2019-06-25 15:38:00 +02:00
|
|
|
return int(a * 1000) == int(b * 1000)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_ortho() {
|
|
|
|
projection := glm.ortho(0, 200, 400, 0)
|
2019-08-20 10:18:12 +02:00
|
|
|
$if debug {
|
|
|
|
println(projection.data[0])
|
|
|
|
}
|
2019-06-25 15:38:00 +02:00
|
|
|
assert cmp(projection.data[0], 0.01)
|
|
|
|
assert cmp(projection.data[1], 0.000000)
|
|
|
|
assert cmp(projection.data[2], 0.000000)
|
|
|
|
assert cmp(projection.data[3], 0.000000)
|
|
|
|
assert cmp(projection.data[4], 0.000000)
|
|
|
|
assert cmp(projection.data[5], - 0.005000)
|
|
|
|
assert cmp(projection.data[6], 0.000000)
|
|
|
|
assert cmp(projection.data[7], 0.000000)
|
|
|
|
assert cmp(projection.data[8], 0.000000)
|
|
|
|
assert cmp(projection.data[9], 0.000000)
|
|
|
|
assert cmp(projection.data[10], 1.000000)
|
|
|
|
assert cmp(projection.data[11], 0.000000)
|
|
|
|
assert cmp(projection.data[12], - 1.000000)
|
|
|
|
assert cmp(projection.data[13], 1.000000)
|
|
|
|
assert cmp(projection.data[14], 0.000000)
|
|
|
|
assert cmp(projection.data[15], 1.000000)
|
|
|
|
// f := gg.ortho(1,2,3,4)
|
2019-08-05 10:42:58 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
// for debugging broken tetris in gg.o
|
|
|
|
# projection.data[0]=0.010000;
|
|
|
|
# projection.data[1]=0.000000;
|
|
|
|
# projection.data[2]=0.000000;
|
|
|
|
# projection.data[3]=0.000000;
|
|
|
|
# projection.data[4]=0.000000;
|
|
|
|
# projection.data[5]=-0.005000;
|
|
|
|
# projection.data[6]=0.000000;
|
|
|
|
# projection.data[7]=0.000000;
|
|
|
|
# projection.data[8]=0.000000;
|
|
|
|
# projection.data[9]=0.000000;
|
|
|
|
# projection.data[10]=1.000000;
|
|
|
|
# projection.data[11]=0.000000;
|
|
|
|
# projection.data[12]=-1.000000;
|
|
|
|
# projection.data[13]=1.000000;
|
|
|
|
# projection.data[14]=0.000000;
|
|
|
|
# projection.data[15]=1.000000;
|
|
|
|
*/
|
2019-06-25 15:38:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_rotate() {
|
2019-08-20 10:18:12 +02:00
|
|
|
$if debug {
|
|
|
|
println('rotate')
|
|
|
|
}
|
2019-06-25 15:38:00 +02:00
|
|
|
mut m := glm.identity()
|
|
|
|
m = glm.scale(m, glm.vec3(2, 2, 2))
|
2019-08-20 10:18:12 +02:00
|
|
|
$if debug {
|
|
|
|
println(m)
|
|
|
|
}
|
2019-06-25 15:38:00 +02:00
|
|
|
m = glm.rotate_z(m, 1)
|
2019-08-20 10:18:12 +02:00
|
|
|
$if debug {
|
|
|
|
println(m)
|
|
|
|
}
|
2019-06-25 15:38:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_translate() {
|
|
|
|
mut m := glm.identity()
|
|
|
|
m = glm.translate(m, glm.vec3(0, 0, - 0.5))
|
2019-08-20 10:18:12 +02:00
|
|
|
$if debug {
|
|
|
|
println(m)
|
|
|
|
}
|
2019-06-25 15:38:00 +02:00
|
|
|
// TODO
|
|
|
|
// mat4x4((1.000000, 0.000000, 0.000000, 0.000000),
|
|
|
|
// (0.000000, 1.000000, 0.000000, 0.000000),
|
|
|
|
// (0.000000, 0.000000, 1.000000, 0.000000),
|
|
|
|
// (0.000000, 0.000000, -0.500000, 1.000000))
|
|
|
|
}
|
|
|
|
|
2020-05-10 16:49:29 +02:00
|
|
|
fn test_mult() {
|
|
|
|
//TODO improve test
|
|
|
|
mut a := glm.identity()
|
|
|
|
mut b := glm.identity()
|
|
|
|
mut c := glm.identity()
|
|
|
|
a = glm.mult(a, b)
|
|
|
|
for i in 0..15 {
|
|
|
|
assert a.data[i] == c.data[i]
|
|
|
|
}
|
|
|
|
}
|