コード例 #1
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_shell_Sphere_intersect(self):
        from lepton.domain import Sphere
        from lepton.particle_struct import Vec3
        sphere = Sphere((2, 1, -1), 3, 1)
        lines = [
            ((2, 1, -1), (2, 1, 1)),
            ((2.5, 1, -1), (4, 1, -1)),
            ((5, 4, -1), (3.5, 2.5, -1)),
            ((2, 2.5, -1), (2, 1, -1)),
        ]
        expected = [
            ((2, 1, 0), (0, 0, -1)),
            ((3, 1, -1), (-1, 0, 0)),
            ((math.sin(math.pi / 4) * 3 + 2, math.sin(math.pi / 4) * 3 + 1,
              -1), Vec3(1, 1, 0).normalize()),
            ((2, 2, -1), (0, 1, 0)),
        ]

        for (start, end), (point, normal) in zip(lines, expected):
            p, N = sphere.intersect(start, end)
            self.assertVector(p, point)
            self.assertVector(N, normal)

            # Reverse direction should yield same point and inverse normal
            p, N = sphere.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
コード例 #2
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_shell_Sphere_intersect(self):
		from lepton.domain import Sphere
		from lepton.particle_struct import Vec3
		sphere = Sphere((2, 1, -1), 3, 1)
		lines = [
			((2, 1, -1), (2, 1, 1)),
			((2.5, 1, -1), (4, 1, -1)),
			((5, 4, -1), (3.5, 2.5, -1)),
			((2, 2.5, -1), (2, 1, -1)),
		]
		expected = [
			((2, 1, 0), (0, 0, -1)),
			((3, 1, -1), (-1, 0, 0)),
			((math.sin(math.pi/4)*3+2, math.sin(math.pi/4)*3+1, -1),
				Vec3(1, 1, 0).normalize()),
			((2, 2, -1), (0, 1, 0)),
		]

		for (start, end), (point, normal) in zip(lines, expected):
			p, N = sphere.intersect(start, end)
			self.assertVector(p, point)
			self.assertVector(N, normal)

			# Reverse direction should yield same point and inverse normal
			p, N = sphere.intersect(end, start)
			self.assertVector(p, point)
			self.assertVector(N, -Vec3(*normal))
コード例 #3
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_solid_Sphere_intersect(self):
		from lepton.domain import Sphere
		from lepton.particle_struct import Vec3
		sphere = Sphere((0, 1, 2), 2)
		lines = [
			((0, -2, 2), (0, 0, 2)),
			((3, 4, 2), (1, 2, 2)),
			((-1, -1, 0), (0, -1, 2)), # tangential
		]
		expected = [
			((0, -1, 2), (0, -1, 0)),
			((math.sin(math.pi/4)*2, math.sin(math.pi/4)*2+1, 2), 
				Vec3(1, 1, 0).normalize()),
			((0, -1, 2), (0, -1, 0)),
		]

		for (start, end), (point, normal) in zip(lines, expected):
			p, N = sphere.intersect(start, end)
			self.assertVector(p, point)
			self.assertVector(N, normal)

			# Reverse direction should yield same point and inverse normal
			p, N = sphere.intersect(end, start)
			self.assertVector(p, point)
			self.assertVector(N, -Vec3(*normal))
コード例 #4
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_solid_Sphere_intersect(self):
        from lepton.domain import Sphere
        from lepton.particle_struct import Vec3
        sphere = Sphere((0, 1, 2), 2)
        lines = [
            ((0, -2, 2), (0, 0, 2)),
            ((3, 4, 2), (1, 2, 2)),
            ((-1, -1, 0), (0, -1, 2)),  # tangential
        ]
        expected = [
            ((0, -1, 2), (0, -1, 0)),
            ((math.sin(math.pi / 4) * 2, math.sin(math.pi / 4) * 2 + 1, 2),
             Vec3(1, 1, 0).normalize()),
            ((0, -1, 2), (0, -1, 0)),
        ]

        for (start, end), (point, normal) in zip(lines, expected):
            p, N = sphere.intersect(start, end)
            self.assertVector(p, point)
            self.assertVector(N, normal)

            # Reverse direction should yield same point and inverse normal
            p, N = sphere.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
コード例 #5
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_solid_Sphere_grazing_intersect(self):
     from lepton.domain import Sphere
     sphere = Sphere((0, 0, 0), 4)
     p, N = sphere.intersect((-5, 0, 0), (5, 0, 0))
     self.assertVector(p, (-4, 0, 0))
     self.assertVector(N, (-1, 0, 0))
     p, N = sphere.intersect((5, 0, 0), (-5, 0, 0))
     self.assertVector(p, (4, 0, 0))
     self.assertVector(N, (1, 0, 0))
コード例 #6
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_solid_Sphere_grazing_intersect(self):
		from lepton.domain import Sphere
		sphere = Sphere((0, 0, 0), 4)
		p, N = sphere.intersect((-5, 0, 0), (5, 0, 0))
		self.assertVector(p, (-4, 0, 0))
		self.assertVector(N, (-1, 0, 0))
		p, N = sphere.intersect((5, 0, 0), (-5, 0, 0))
		self.assertVector(p, (4, 0, 0))
		self.assertVector(N, (1, 0, 0))
コード例 #7
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_Sphere_stationary_particles(self):
     from lepton.domain import Sphere
     from lepton.particle_struct import Vec3
     sphere = Sphere((0, 1, 2), 2)
     positions = [
         ((0, 1.1, 2.2), (0, 1.1, 2.2)),
         ((3.1, 4, 2), (3.1, 4, 2)),
         ((-0.9, -1, 0), (-0.9, -1, 0)),
     ]
     for start, end in positions:
         self.assertEqual(sphere.intersect(start, end), (None, None))
コード例 #8
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_Sphere_stationary_particles(self):
		from lepton.domain import Sphere
		from lepton.particle_struct import Vec3
		sphere = Sphere((0, 1, 2), 2)
		positions = [
			((0, 1.1, 2.2), (0, 1.1, 2.2)),
			((3.1, 4, 2), (3.1, 4, 2)),
			((-0.9, -1, 0), (-0.9, -1, 0)),
		]
		for start, end in positions:
			self.assertEqual(sphere.intersect(start, end), (None, None))
コード例 #9
0
ファイル: sandbox.py プロジェクト: Dancorg/ShipHell
 def __init__(self, side, pos, objective, mode, size, data, color, speed):
     self.side = side
     self.pos = pos
     self.domain = Sphere(pos, size)
     self.objective = Sphere((objective[0], objective[1], objective[2]), 1)
     self.mode = mode
     self.target = None
     self.size = size
     self.data = data
     self.color = color
     self.speed = speed
     self.particles()
コード例 #10
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_shell_Sphere_generate_contains(self):
        from lepton.domain import Sphere
        sphere = Sphere((1, -2, 4), 3, 2)
        for i in range(20):
            x, y, z = sphere.generate()
            mag = (x - 1)**2 + (y + 2)**2 + (z - 4)**2
            self.failUnless(4 <= mag <= 9, ((x, y, z), mag))
            self.failUnless((x, y, z) in sphere, (x, y, z))

        self.failUnless((3, -2, 4) in sphere)
        self.failUnless((1, 1, 4) in sphere)
        self.failUnless((1, -2, 1.5) in sphere)
        self.failIf((1, -2, 4) in sphere)
        self.failIf((5, 1, 7) in sphere)
コード例 #11
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_shell_Sphere_generate_contains(self):
		from lepton.domain import Sphere
		sphere = Sphere((1, -2, 4), 3, 2)
		for i in range(20):
			x, y, z = sphere.generate()
			mag = (x - 1)**2 + (y + 2)**2 + (z - 4)**2
			self.failUnless(4 <= mag <= 9, ((x, y, z), mag))
			self.failUnless((x, y, z) in sphere, (x, y ,z))

		self.failUnless((3, -2, 4) in sphere)
		self.failUnless((1, 1, 4) in sphere)
		self.failUnless((1, -2, 1.5) in sphere)
		self.failIf((1, -2, 4) in sphere)
		self.failIf((5, 1, 7) in sphere)
コード例 #12
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_solid_Sphere_generate_contains(self):
        from lepton.domain import Sphere
        sphere = Sphere((0, 1, 2), 2)
        for i in range(20):
            x, y, z = sphere.generate()
            mag = x**2 + (y - 1)**2 + (z - 2)**2
            self.failUnless(mag <= 4, ((x, y, z), mag))
            self.failUnless((x, y, z) in sphere, (x, y, z))

        self.failUnless((0, 1, 2) in sphere)
        self.failUnless((1, 2, 3) in sphere)
        self.failUnless((2, 1, 2) in sphere)
        self.failUnless((-2, 1, 2) in sphere)
        self.failIf((2.1, 1, 2) in sphere)
        self.failIf((-2.1, 1, 2) in sphere)
コード例 #13
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_Sphere_closest_point_to(self):
		from lepton.domain import Sphere
		from lepton.particle_struct import Vec3
		sphere = Sphere((0,5,-1), 4.0, 2.0)
		for point, closest, normal in [
			((0,5,-1), (0,5,-1), (0,0,0)),
			((5,5,-1), (4,5,-1), (1,0,0)),
			((0,15,-1), (0,9,-1), (0,1,0)),
			((6,11,5), Vec3(0,5,-1) + Vec3(1,1,1).normalize()*4, Vec3(1,1,1).normalize()),
			((1,5,-1), (2,5,-1), (-1,0,0)),
			((0,8,-1), (0,8,-1), (0,0,0)),
			]:
			p, N = sphere.closest_point_to(point)
			self.assertVector(p, closest)
			self.assertVector(N, normal)
コード例 #14
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	def test_solid_Sphere_generate_contains(self):
		from lepton.domain import Sphere
		sphere = Sphere((0, 1, 2), 2)
		for i in range(20):
			x, y, z = sphere.generate()
			mag = x**2 + (y - 1)**2 + (z - 2)**2
			self.failUnless(mag <= 4, ((x, y, z), mag))
			self.failUnless((x, y, z) in sphere, (x, y ,z))

		self.failUnless((0, 1, 2) in sphere)
		self.failUnless((1, 2, 3) in sphere)
		self.failUnless((2, 1, 2) in sphere)
		self.failUnless((-2, 1, 2) in sphere)
		self.failIf((2.1, 1, 2) in sphere)
		self.failIf((-2.1, 1, 2) in sphere)
コード例 #15
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_Sphere_closest_point_to(self):
     from lepton.domain import Sphere
     from lepton.particle_struct import Vec3
     sphere = Sphere((0, 5, -1), 4.0, 2.0)
     for point, closest, normal in [
         ((0, 5, -1), (0, 5, -1), (0, 0, 0)),
         ((5, 5, -1), (4, 5, -1), (1, 0, 0)),
         ((0, 15, -1), (0, 9, -1), (0, 1, 0)),
         ((6, 11, 5), Vec3(0, 5, -1) + Vec3(1, 1, 1).normalize() * 4,
          Vec3(1, 1, 1).normalize()),
         ((1, 5, -1), (2, 5, -1), (-1, 0, 0)),
         ((0, 8, -1), (0, 8, -1), (0, 0, 0)),
     ]:
         p, N = sphere.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
コード例 #16
0
ファイル: controller_test.py プロジェクト: lordmauve/lepton
 def test_Magnet_controller_defaults(self):
     # Test one attract iteration
     # for direction and magnitude of dv.
     from lepton import controller, domain
     from lepton.domain import Sphere
     sphere = Sphere((0, 0, 0), 5, 0)
     group = self._make_group()
     attract = controller.Magnet(sphere, charge=100)
     self.failUnless(attract.domain is sphere)
     self.assertEqual(attract.charge, 100)
     self.assertEqual(attract.exponent, 2)
     self.failUnless(attract.epsilon > 0)
     attract(1.0, group)
     p = list(group)
     self.assertVector(p[0].position, (10.0, 0.0, 0.0))
     self.assertVector(p[1].position, (0, 0.0, 10.0))
     self.assertVector(p[0].velocity, (-4.0, 0.0, 0.0), tolerance=0.0001)
     self.assertVector(p[1].velocity, (0, 0.0, -4.0), tolerance=0.0001)
コード例 #17
0
ファイル: magnet.py プロジェクト: lordmauve/lepton
    gluPerspective(70, 1.0 * widthWindow / heightWindow, 0.001, 10000.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()


win.on_resize = resize

electron_lifetime = 22
max_electrons = 6
trail_lifetime = 4.5

texture = image.load(os.path.join(os.path.dirname(__file__),
                                  'flare3.png')).get_texture()
texturizer = SpriteTexturizer(texture.id)

nucleus = Sphere((0, 0, 0), 5)
protons = ParticleGroup(renderer=BillboardRenderer(texturizer),
                        controllers=[
                            Movement(),
                        ])
proton_emitter = StaticEmitter(template=Particle(
    size=(30, 30, 0),
    color=(0.5, 1.0, 0.2, 0.5),
),
                               size=[(26, 26, 0), (30, 30, 0), (34, 34, 0)],
                               deviation=Particle(rotation=(0, 0,
                                                            math.pi / 6), ))

proton_emitter.emit(3, protons)

electrons = ParticleGroup(renderer=BillboardRenderer(texturizer),
コード例 #18
0
 def __init__(self, position, radius):
     self.domain = Sphere(position, radius)
     self.controller = Bounce(self.domain,
                              bounce=1.5,
                              friction=-0.25,
                              callback=self.set_bumper_color)
コード例 #19
0
    def __init__(self,
                 x,
                 y,
                 z,
                 r,
                 side=-1,
                 hp=50,
                 controlable=False,
                 weapon_range=5,
                 dispersion=5,
                 agility=50,
                 weapon_base_damage=2,
                 guidance=100,
                 shortguide=0,
                 partColor=(0.6, 0.5, 0.2, 1),
                 firerate=10,
                 shots=1,
                 vo=30,
                 maxvel=10,
                 ammoMaxvel=20,
                 combatDistance=50,
                 behavior=0,
                 commander=None,
                 multipleTargets=False,
                 name="",
                 ammoDamp=0.98):
        self.name = name
        self.domain = Sphere(
            (x, y, z), r
        )  # a.center -> vector del centro , a.outer_radius -> radio externo , a.inner_radius -> radio interno
        self.size = r
        self.controller = Collector(self.domain, callback=self.contact)
        self.magnet = Magnet(self.domain, charge=guidance, exponent=shortguide)
        self.commander = commander
        self.mission = self.domain.center
        self.target = None
        self.alive = True
        self.targetMode = ['standard', 1]
        self.behavior = behavior  # 0:free 1: escort 2: slave
        self.hp = hp
        self.agility = agility
        self.maxvel = maxvel
        self.timer = {0: 0, 1: 2, 2: 0, 3: 0, 4: 0}  # timers placeholder
        self.counter = {0: 0, 1: 0}  # counters placeholder
        self.side = side
        self.combatDistance = combatDistance
        self.velocity = Vec3(0, 0, 0)
        self.multipleTargets = multipleTargets
        self.firerate = firerate
        self.weapon_base_damage = weapon_base_damage
        wbd = self.weapon_base_damage
        rr = r * 2
        self.dispersion = dispersion
        self.vo = vo
        self.ammoDamp = ammoDamp
        self.ammoMaxvel = ammoMaxvel
        self.shots = shots
        self.weapon_range = weapon_range
        self.xx = self.yy = self.zz = 0
        self.Objective = Sphere((0, 0, 0), 1)
        self.color = partColor  # (0.4,0.5,0.4,0.5)
        #self.prevController = Collector(self.domain)#DUMMY CONTROLLER
        self.controlable = controlable
        self.impacto = ParticleGroup(renderer=BillboardRenderer(texturizer),
                                     controllers=[
                                         Lifetime(1),
                                         Fader(fade_out_start=0,
                                               fade_out_end=1),
                                     ])
        self.deathplosion = ParticleGroup(
            renderer=BillboardRenderer(texturizer),
            controllers=[
                Lifetime(self.size / 5 + 1),
                Fader(fade_out_start=0, fade_out_end=self.size / 5 + 1),
            ])
        self.selector_emitter = StaticEmitter(template=Particle(
            position=(0, 0, 0),
            color=self.color,
        ))
        self.impacto_emitter = StaticEmitter(
            template=Particle(
                position=(0, 0, 0),
                color=(0.9, 0.8, 0.8),
            ),
            position=self.domain,
            #size=[(5, 5, 5), (10, 10, 10), (15, 15, 15)],
        )
        self.hull = ParticleGroup(renderer=BillboardRenderer(texturizer2),
                                  controllers=[
                                      Lifetime(100000),
                                      Movement(max_velocity=self.maxvel,
                                               damping=0.98),
                                      Magnet(self.Objective,
                                             charge=self.agility,
                                             exponent=0),
                                  ])
        emiter = StaticEmitter(position=self.domain,
                               template=Particle(
                                   color=self.color,
                                   size=(rr, rr, rr),
                               ))
        emiter.emit(1, self.hull)

        if trails:
            if maxvel / r >= 20:
                self.trail = ParticleGroup(
                    renderer=BillboardRenderer(texturizer2),
                    controllers=[
                        Lifetime(trailSize[0]),
                        Fader(fade_in_start=0,
                              fade_in_end=0.1,
                              fade_out_start=0,
                              fade_out_end=trailSize[0]),
                        Growth(-1 * r),
                        PerParticleEmitter(self.hull,
                                           rate=trailSize[1],
                                           template=Particle(
                                               color=self.color,
                                               size=(rr, rr, rr),
                                           )),
                    ])

        self.ammo = ParticleGroup(renderer=BillboardRenderer(texturizer),
                                  controllers=[
                                      self.magnet,
                                      Movement(min_velocity=0,
                                               max_velocity=self.ammoMaxvel,
                                               damping=self.ammoDamp),
                                      Lifetime(self.weapon_range),
                                      Fader(fade_out_start=self.weapon_range -
                                            1,
                                            fade_out_end=self.weapon_range),
                                  ])

        self.weapon = PerParticleEmitter(
            self.hull,  # rate=self.firerate,
            template=Particle(
                velocity=self.velocity,  # fixed value
                position=(self.getPosition()),
                color=partColor,
            ),
            position=self.domain,
            size=[(wbd * 0.5, wbd * 0.5, wbd * 0.5), (wbd, wbd, wbd),
                  (wbd * 1.5, wbd * 1.5, wbd * 1.5)],
            deviation=Particle(
                velocity=(self.dispersion, self.dispersion,
                          self.dispersion * d3),
                rotation=(0, 0, math.pi / 6),
                #color=(0.05,0.05,0.05,0),
            ))