예제 #1
0
    def test_collides_example(self):
        vertices = [
            vec3(1.0, -1.0, -1.0), vec3(1.0, -1.0, 1.0),
            vec3(-1.0, -1.0, 1.0), vec3(-1.0, -1.0, -1.0),
            vec3(1.0, 1.0, -0.999999), vec3(0.999999, 1.0, 1.000001),
            vec3(-1.0, 1.0, 1.0), vec3(-1.0, 1.0, -1.0)
        ]
        normals = [
            vec3(1.0, -1.0, -2.0), vec3(2.0, -2.0, 1.0),
            vec3(-2.0, -1.0, 2.0), vec3(-1.0, -2.0, -1.0),
            vec3(2.0, 1.0, -1.0), vec3(1.0, 2.0, 2.0),
            vec3(-1.0, 1.0, 1.0), vec3(-2.0, 2.0, -2.0)
        ]
        box = BoundingBox()
        box.vertices = vertices
        box.normals = normals
        matrix = identity()
        translate(matrix, vec3(0, 0, 25))

        other = BoundingBox()
        other.vertices = vertices
        other.normals = normals
        other_matrix = identity()
        translate(other_matrix, vec3(5, 0, 25))

        collides = CollisionSystem.collides(box, matrix, other, other_matrix)
        self.assertFalse(collides)
예제 #2
0
 def test_translate(self):
     m = identity()
     v = vec3(1, 2, 3)
     translate(m, v)
     self.assertEqual(mat4([
         [1, 0, 0, 1],
         [0, 1, 0, 2],
         [0, 0, 1, 3],
         [0, 0, 0, 1]
     ]), m)
예제 #3
0
    def test_not_collides_simple_position(self):
        box = BoundingBox()
        box.vertices = self.vertices
        box.normals = self.normals

        other = BoundingBox()
        other.vertices = self.vertices
        other.normals = self.normals

        matrix = identity()
        translate(matrix, vec3(3))
        collides = CollisionSystem.collides(box, matrix, other, identity())
        self.assertFalse(collides)
예제 #4
0
 def test_rotate_and_translate(self):
     m = identity()
     rot = vec3(90)
     trans = vec3(1, 2, 3)
     rotate(m, rot)
     translate(m, trans)
     self.assertEqual(mat4([
         [1.0, 0.0, 0.0, 1.0],
         [0.0, 0.0, -1.0, 2.0],
         [0.0, 1.0, 0.0, 3.0],
         [0.0, 0.0, 0.0, 1.0]
     ]), m)
     v = m * vec3(0, 1, 0)
     self.assertEqual(vec3(1, 2, 4), v)