def __init__(self, target, up, theta_eq, phi_eq, r_eq): self.target = mp.array(target) self.up = mp.array(up) self.theta_eq = theta_eq self.phi_eq = phi_eq self.r_eq = r_eq self.pos = mp.array([0, 0, 0]) self.start_time = time.monotonic()
def init(self, pos, dir, speed, radius, texture): self.pos = mp.array(pos) self.dir = mp.array(dir) self.speed = speed self.radius = radius self.texture = texture self.opacity = 1. self.fading = False
def update(self, dt): for b in self.enabled_balls(): b.update(dt) for b in self.enabled_balls(): if b.get_distance_to(mp.array([0, 0, 0])) > self.scene.active_shape.radius: self._reset_ball(b)
def test_triangle_contains(self): tri = mp.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]]) self.assertTrue(mp.triangle_contains_point(tri, mp.array([.1, .1, 0]))) self.assertFalse( mp.triangle_contains_point(tri, mp.array([1.5, 1.5, 0]))) self.assertFalse(mp.triangle_contains_point(tri, mp.array([.4, -9, 0]))) self.assertFalse(mp.triangle_contains_point(tri, mp.array([-5, .2, 0]))) self.assertFalse(mp.triangle_contains_point(tri, mp.array([-1, -1, 0]))) self.assertFalse(mp.triangle_contains_point(tri, mp.array([-.1, 9, 0]))) self.assertFalse(mp.triangle_contains_point(tri, mp.array([5, -.8, 0])))
def __init__(self, shape, index, vertices, texcoords, normals): self.shape = shape self.index = index self.triangles = [] self.midpoint = sum(vertices) / len(vertices) self.normal = mp.triangle_normal(vertices[0:3]) self.wire_color = mp.array([1, 1, 1, 1]) self.face_color_normal = mp.array([1, 1, 1, .1]) self.face_color_highlighted = mp.array([1, 1, 1, 1]) self.highlight_time = 0. self.wire_vao = gfx.VAO() with self.wire_vao: self.wire_vao.create_vbo_attrib(0, vertices) for i in range(1, len(vertices) - 1): i0, i1, i2 = 0, i, i + 1 _triplet = lambda arr: [arr[i0], arr[i1], arr[i2]] triangle = Triangle(self, _triplet(vertices), _triplet(texcoords), _triplet(normals), [True, i2 == len(vertices) - 1, i == 1]) self.triangles.append(triangle)
def __init__(self, scene, distance, texture): self.scene = scene self.texture = texture self.vertices = mp.array( self.QUADS)[:, [[1, 0, 2], [2, 0, 3]]].reshape(-1, 3) * distance self.program = gfx.Program(SKYBOX_VS, SKYBOX_FS) self.vao = gfx.VAO() with self.vao: self.vao.create_vbo_attrib(0, self.vertices) if self.texture is not None: with self.program: self.program.set_uniform('t_skybox', self.texture.number)
def test_intersect_plane_sphere(self): p0 = mp.array([-.866, 0, -.5]) p1 = mp.array([+.866, 0, -.5]) p2 = mp.array([0, 0, 1]) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, .4, 0]), mp.array([0, -.1, 0])) assert_close(t, 4) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, .4, 0]), mp.array([0, .1, 0])) assert_close(t, -4) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, -.4, 0]), mp.array([0, .1, 0])) assert_close(t, 4) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([-1, -1, -1]), mp.array([.1, .1, .1])) assert_close(t, 10) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([-1, -1, -1]), mp.array([-.1, -.1, -.1])) assert_close(t, -10) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, .4, 0]), mp.array([1, 0, 0])) self.assertEqual(t, np.inf) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, -.4, 0]), mp.array([1, 0, 0])) self.assertEqual(t, -np.inf) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, .4, 0]), mp.array([0, -.1, 0]), .1) assert_close(t, 3) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, -.4, 0]), mp.array([0, .1, 0]), .1) assert_close(t, 3) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, .4, 0]), mp.array([0, -.1, 0]), .2) assert_close(t, 2) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, -.4, 0]), mp.array([0, .1, 0]), .2) assert_close(t, 2) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, .4, 0]), mp.array([0, -.1, 0]), .5) assert_close(t, -1) t, p = mp.intersect_plane_sphere([p0, p1, p2], mp.array([0, -.4, 0]), mp.array([0, .1, 0]), .5) assert_close(t, -1)
def __init__(self, scene, pos, speed, target, up): self.scene = scene self.pos = mp.array(pos) self.speed = mp.array(speed) self.target = mp.array(target) self.up = mp.array(up)