예제 #1
0
 def test_bounding_sphere_collision_false(self):
     a = Sphere(radius=2.0)
     b = Sphere()
     b.position = [4.5, 0.5, 0]
     c = CollisionTest(callback=dummy, objects=[a, b])
     check = c._bounding_sphere_collision(a, b)
     self.assertFalse(check)
예제 #2
0
 def test_sphere_in_sphere_false(self):
     a = Sphere(radius=10)
     b = Sphere(radius=2)
     b.position = [10, 2, 0]
     c = CollisionTest(callback=dummy, objects=[a, b])
     check = c._sphere_in_sphere_collision(a, b)
     self.assertFalse(check)
예제 #3
0
 def test_dist(self):
     a = Sphere()
     b = Sphere()
     b.position = [3, 0, 4]
     c = CollisionTest(callback=dummy, objects=[a, b])
     dist = c._dist(a, b)
     self.assertAlmostEqual(dist, 5)
예제 #4
0
def create_balloon(name, scene, period, total):
    global sphere_count
    x = random.randint(-5, 5)
    y = random.randint(-5, 5)
    sphere = Sphere()
    sphere.material.color = [1, 1, 1]
    sphere.position = [x, y, 10]
    scene.add_object(f"sphere_{sphere_count}", sphere)
    sphere_count += 1
예제 #5
0
def logger(name, scene, period, total):
    if scene.objects["ball"].matrix[3][2] < 0:
        # Do not continue simulation if we hit the ground.
        scene.clocks[name].kill()  # We do not need this clock anymore
        return None

    # Log ball location
    logging.debug("Ball position: x:{} y:{} z:{} t={}".format(
        scene.objects["ball"].matrix[3][0],
        scene.objects["ball"].matrix[3][1],
        scene.objects["ball"].matrix[3][2],
        total,
    ))


#  Definitions
pm_scene = Scene()

ball = Sphere(radius=1, track_motion=True)

# Add ball to the scene
pm_scene.add_object("ball", ball)
pm_scene.observers[0].target_object = ball  # Track the ball

pm_scene.grid.resize(30, 30, 2)

pm_scene.create_clock("motion", 0.01, projectile_motion)
pm_scene.create_clock("logger", 0.05, logger)

pm_scene.run()
예제 #6
0
    sy = math.sin(math.radians(angle * 10)) * 2
    scene.objects["nucleus"].children["particle"].children[
        "sub_particle"
    ].position = [sx, sy, 0]
    scene.lights[0].position = [px, py, 0]
    scene.lights[1].position = [-px, -py, 0]


space = Scene()
space.lights.append(Light())
space.observers[0].position = [20, 20, 20]
space.grid.resize(40, 40, 1)

texture_file = os.path.join(os.path.dirname(__file__), "map.png")

nucleus = Sphere(radius=5, parallels=36, meridians=36)
nucleus.material.texture = texture_file
particle = Sphere()
particle.position = [8, 0, 0]

sub_particle = Sphere(radius=0.5)
sub_particle.position = [0, 2, 0]

nucleus.add_child("particle", particle)
particle.add_child("sub_particle", sub_particle)

space.add_object("nucleus", nucleus)

space.create_clock("motion", 0.01, motion)
print("Hit SPACE to continue animation")
space.run()
예제 #7
0
def hit(collision, pairs):
    for pair in pairs:
        pair[0].material.color = [1.0, 0, 0]
        pair[1].material.color = [1.0, 0, 0]
        # Once there is a hit, system will not check
        # for the same collision, if you want to have the objects
        # back in the collision detection pipeline, you have to do
        # collision.resolve(pair[0], pair[1])


scene = Scene()
collision = CollisionTest(callback=hit)
for i in range(50):
    x = random.randint(-5, 5)
    y = random.randint(-5, 5)
    z = random.randint(-5, 5)
    if i % 2 == 0:
        s = Sphere()
        s.position = [x, y, z]
        scene.add_object("s_{}".format(i), s)
        collision.add_object(s)
    else:
        c = Cube()
        c.position = [x, y, z]
        scene.add_object("c_{}".format(i), c)
        collision.add_object(c)

scene.add_collision_test(collision)
scene.run()