コード例 #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 プロジェクト: lordmauve/lepton
    def test_solid_disc_intersect(self):
        from lepton.domain import Disc
        from lepton.particle_struct import Vec3
        normal = Vec3(1, 1, 0).normalize()
        disc = Disc((-2, 0, 1), normal, 1)
        lines = [
            ((-5, 0, 0), (5, 0, 0)),
            ((-2, 1, 1), (-2, -1, 1)),
            ((3, normal.y, 1), (-3, normal.y, 1)),
        ]
        expected = [
            ((-2, 0, 0), -normal),
            ((-2, 0, 1), normal),
            ((-2 - normal.x, normal.y, 1), normal),
        ]

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

            # Reverse direction should yield same point and inverse normal
            p, N = disc.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
コード例 #3
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))
コード例 #4
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_solid_cone_intersect(self):
        from lepton.domain import Cone
        from lepton.particle_struct import Vec3
        cone = Cone((0, 1, 0), (0, -1, 0), 2)
        lines = [
            ((-2, 0, 0), (0, 0, 0)),
            ((3, 1, 0), (-1, 1, 0)),
            ((0, 0, -2), (0, 0, 5)),
            ((0.5, -3, 0), (0.5, -0.5, 0)),
            ((-1, 2, 0), (1, 0, 0)),
            ((-5, -2, 0), (5, 0, 0)),
            ((0, 10, 1), (0, -10, 1)),
            ((1, 1, 0), (-1, -1, 0)),
            ((0, 0, 0), (3, 0, 0)),
        ]
        expected = [
            ((-1, 0, 0), Vec3(-1, 1, 0).normalize()),
            ((0, 1, 0), (0, 1, 0)),
            ((0, 0, -1), Vec3(0, 1, -1).normalize()),
            ((0.5, -1, 0), (0, -1, 0)),
            ((0, 1, 0), (0, 1, 0)),
            ((0, -1, 0), (0, -1, 0)),
            ((0, 0, 1), Vec3(0, 1, 1).normalize()),
            ((0.5, 0.5, 0), Vec3(1, 1, 0).normalize()),
            ((1, 0, 0), Vec3(-1, -1, 0).normalize()),
        ]

        for (start, end), (point, normal) in zip(lines, expected):
            p, N = cone.intersect(start, end)
            self.assertVector(p, point)
            self.assertVector(N, normal)
コード例 #5
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_cone_apex_base_length(self):
     from lepton.domain import Cone
     from lepton.particle_struct import Vec3
     cone = Cone((2, 2, 2), (4, 2, 2), 2)
     self.assertVector(cone.apex, (2, 2, 2))
     self.assertVector(cone.base, (4, 2, 2))
     self.assertEqual(cone.length, 2)
     cone.apex = (2.5, 2, 2)
     self.assertVector(cone.apex, (2.5, 2, 2))
     self.assertVector(cone.base, (4, 2, 2))
     self.assertEqual(cone.length, 1.5)
     cone.base = (3, 3, 3)
     self.assertVector(cone.apex, (2.5, 2, 2))
     self.assertVector(cone.base, (3, 3, 3))
     self.assertEqual(cone.length,
                      (Vec3(2.5, 2, 2) - Vec3(3, 3, 3)).length())
コード例 #6
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_solid_cyl_intersect(self):
        from lepton.domain import Cylinder
        from lepton.particle_struct import Vec3
        cyl = Cylinder((0, -1, 0), (0, 1, 0), 1)
        lines = [
            ((-2, 0, 0), (0, 0, 0)),
            ((2, 1, 0), (0, 1, 0)),
            ((0, 0, -2), (0, 0, 0.8)),
            ((0, 2, 0.5), (0, 0, 0.5)),
            ((0.5, -3, 0), (0.5, -0.5, 0)),
        ]
        expected = [
            ((-1, 0, 0), (-1, 0, 0)),
            ((1, 1, 0), (1, 0, 0)),
            ((0, 0, -1), (0, 0, -1)),
            ((0, 1, 0.5), (0, 1, 0)),
            ((0.5, -1, 0), (0, -1, 0)),
        ]

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

            # Reverse direction should yield same point and inverse normal
            p, N = cyl.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
コード例 #7
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_disc_closest_pt_to(self):
     from lepton.domain import Disc
     from lepton.particle_struct import Vec3
     disc = Disc((-3, 1, 2), (0, 1, 1), 4, 1)
     for point, closest, normal in [
         ((-2, 1, 2), (-2, 1, 2), (0, 0, 0)),
         ((-2, 2, 2), (-2, 1.5, 1.5), Vec3(0, 1, 1).normalize()),
         ((-2, -1, 2), (-2, 0, 3), Vec3(0, -1, -1).normalize()),
         ((-3, 5, 8), (-3, 0, 3), Vec3(0, 1, 1).normalize()),
         ((-3, 1, 2), (-3, 1, 2), (0, 0, 0)),
         ((-3, 3, 4), (-3, 1, 2), (0, 0, 0)),
         ((-3, 0, 1), (-3, 1, 2), (0, 0, 0)),
     ]:
         p, N = disc.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
コード例 #8
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)
コード例 #9
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_AABox_intersect(self):
        from lepton.domain import AABox
        from lepton.particle_struct import Vec3
        box = AABox((-3, -1, 0), (-2, 1, 3))
        lines = [
            ((-4, 0, 1), (-2, 0, 1)),
            ((-2.5, -2, 2), (-2.5, -0.5, 2)),
            ((-2.8, 0.5, -1), (-2.8, 0.5, 1)),
            ((-1, 0, 1), (-2, 0, 1)),
            ((-2.5, 2, 2), (-2.5, 1, 2)),
            ((-2.8, 0.5, 4), (-2.8, 0.5, 1)),
        ]
        expected = [
            ((-3, 0, 1), (-1, 0, 0)),
            ((-2.5, -1, 2), (0, -1, 0)),
            ((-2.8, 0.5, 0), (0, 0, -1)),
            ((-2, 0, 1), (1, 0, 0)),
            ((-2.5, 1, 2), (0, 1, 0)),
            ((-2.8, 0.5, 3), (0, 0, 1)),
        ]
        for (start, end), (point, normal) in zip(lines, expected):
            p, N = box.intersect(start, end)
            self.failUnless(start not in box)
            self.failUnless(end in box)
            self.assertVector(p, point)
            self.assertVector(N, normal)

            # Reverse direction should yield same point and inverse normal
            p, N = box.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
コード例 #10
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_hollow_disc_intersect(self):
        from lepton.domain import Disc
        from lepton.particle_struct import Vec3
        disc = Disc((2, 2, 2), (0, 1, 0), 3, 1)
        lines = [
            ((-1, 3, 2), (-1, 0, 2)),
            ((1, 3, 0), (1, 0, 0)),
            ((2, 5, 4), (2, -5, 4)),
            ((3, 1, 2), (5, 3, 2)),
        ]
        expected = [
            ((-1, 2, 2), (0, 1, 0)),
            ((1, 2, 0), (0, 1, 0)),
            ((2, 2, 4), (0, 1, 0)),
            ((4, 2, 2), (0, -1, 0)),
        ]

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

            # Reverse direction should yield same point and inverse normal
            p, N = disc.intersect(end, start)
            self.assertVector(p, point)
            self.assertVector(N, -Vec3(*normal))
コード例 #11
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_line_closest_pt_to(self):
     from lepton.domain import Line
     from lepton.particle_struct import Vec3
     line = Line((0, -1, 0), (0, 2, 0))
     for point, closest, normal in [
         ((-1, 0, 0), (0, 0, 0), (-1, 0, 0)),
         ((1, 1, 1), (0, 1, 0), Vec3(1, 0, 1).normalize()),
         ((0, -2, 0), (0, -1, 0), (0, 0, 0)),
         ((0, 30, 400), (0, 2, 0), (0, 0, 1)),
     ]:
         p, N = line.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
コード例 #12
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    def test_hollow_cone_intersect(self):
        from lepton.domain import Cone
        from lepton.particle_struct import Vec3
        cone = Cone((0, 0, 2), (0, 0, -1), 3, 1)
        lines = [
            ((0, 0, -3), (0, 0, 3)),
            ((0, -5, 0), (0, 5, 0)),
            ((0, 0, 0), (0, 5, 0)),
            ((2, 0, -2), (2, 0, 0)),
            ((0.5, 0, -3), (0.5, 0, 3)),
        ]
        expected = [
            ((0, 0, 2), (0, 0, -1)),
            ((0, -2, 0), Vec3(0, -1, 1).normalize()),
            ((0, 2.0 / 3.0, 0), Vec3(0, -3, -1).normalize()),
            ((2, 0, -1), (0, 0, -1)),
            ((0.5, 0, 0.5), Vec3(-3, 0, -1).normalize()),
        ]

        for (start, end), (point, normal) in zip(lines, expected):
            p, N = cone.intersect(start, end)
            self.assertVector(p, point)
            self.assertVector(N, normal)
コード例 #13
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_cyl_closest_pt_to(self):
     from lepton.domain import Cylinder
     from lepton.particle_struct import Vec3
     cyl = Cylinder((-2, 3, 0), (0, 3, 0), 3, 2)
     for point, closest, normal in [
         ((-1, 7, 0), (-1, 6, 0), (0, 1, 0)),
         ((-2, 3, -6), (-2, 3, -3), (0, 0, -1)),
         ((0, 6, 3), Vec3(0, 3, 0) + Vec3(0, 1, 1).normalize() * 3,
          Vec3(0, 1, 1).normalize()),
         ((-2.2, 5.5, 0), (-2, 5.5, 0), (-1, 0, 0)),
         ((-5, 10, 0), (-2, 6, 0), (-1, 0, 0)),
         ((-10, 3, 1), (-2, 3, 2), (-1, 0, 0)),
         ((0.5, 0, 0), (0, 0, 0), (1, 0, 0)),
         ((3, 5, 0), (0, 5, 0), (1, 0, 0)),
         ((20, 3, -0.1), (0, 3, -2), (1, 0, 0)),
             # points inside cylinder and along axis
         ((-0.5, 5.5, 0), (-0.5, 5.5, 0), (0, 0, 0)),
         ((-1, 3, 0), (-1, 3, 0), (0, 0, 0)),
         ((-30, 3, 0), (-2, 3, 0), (0, 0, 0)),
         ((30, 3, 0), (0, 3, 0), (0, 0, 0)),
     ]:
         p, N = cyl.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
コード例 #14
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_point_closest_point_to(self):
     from lepton.domain import Point
     from lepton.particle_struct import Vec3
     point = Point((4, 5, 6))
     p, N = point.closest_point_to((4, 6, 6))
     self.assertVector(p, (4, 5, 6))
     self.assertVector(N, (0, 1, 0))
     p, N = point.closest_point_to((0, 5, 6))
     self.assertVector(p, (4, 5, 6))
     self.assertVector(N, (-1, 0, 0))
     p, N = point.closest_point_to((3, 4, 5))
     self.assertVector(p, (4, 5, 6))
     self.assertVector(N, Vec3(-1, -1, -1).normalize())
     p, N = point.closest_point_to((4, 5, 6))
     self.assertVector(p, (4, 5, 6))
     self.assertVector(N, (0, 0, 0))
コード例 #15
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_oblique_Plane(self):
     from lepton.domain import Plane
     from lepton.particle_struct import Vec3
     normal = Vec3(3, 4, 5).normalize()
     plane = Plane((0, 0, 0), normal)
     self.assertEqual(tuple(plane.point), (0, 0, 0))
     self.assertEqual(tuple(plane.normal), tuple(normal))
     self.failIf(normal in plane)
     self.failUnless(plane.point in plane)
     self.failUnless(-normal in plane)
     p, N = plane.intersect((0, 1, 0), (0, -1, 0))
     self.assertVector(p, (0, 0, 0))
     self.assertVector(N, normal)
     p, N = plane.intersect((0, -1, 0), (0, 1, 0))
     self.assertVector(p, (0, 0, 0))
     self.assertVector(N, -normal)
コード例 #16
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 def test_cone_closest_pt_to(self):
     from lepton.domain import Cone
     from lepton.particle_struct import Vec3
     cone = Cone((0, 1, -2), (3, -2, -2), math.sqrt(18), 1)
     for point, closest, normal in [
         ((1, 2, -2), (1, 1, -2), (0, 1, 0)),
         ((-1, -1, -2), (0, -1, -2), (-1, 0, 0)),
         ((-1, -2, -2), (0, -2, -2), (-1, 0, 0)),
         ((-1, 3, -1), (0, 1, -2), Vec3(-1, 1, 0).normalize()),
         ((-4, 5, -2), (0, 1, -2), Vec3(-1, 1, 0).normalize()),
         ((6, 0, -2), (5.5, 0.5, -2), Vec3(1, -1, 0).normalize()),
         ((1.566666, -0.566666, -2.1), (1.5, -0.5, -2.5),
          Vec3(-1, 1, -6).normalize()),
         ((2, 0, -3.5), (2, 0, -3.5), (0, 0, 0)),
         ((10, -9, -2), (0, 1, -2), Vec3(1, -1, 0).normalize()),
         ((1, 0, -2), (0, 1, -2), Vec3(1, -1, 0).normalize()),
         ((0, 1, -2), (0, 1, -2), (0, 0, 0)),
     ]:
         p, N = cone.closest_point_to(point)
         self.assertVector(p, closest)
         self.assertVector(N, normal)
コード例 #17
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),
            ))
コード例 #18
0
 def getPositionVec3(self):
     return Vec3(self.domain.center[0], self.domain.center[1],
                 self.domain.center[2])