How to use the payton.scene.collision.CollisionTest function in Payton

To help you get started, we’ve selected a few Payton examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sinanislekdemir / payton / payton / scene / test_geometry.py View on Github external
def test_mesh_collision(self):
        a = Cube()
        b = Cube(width=2.0, height=1.23, depth=1.0)
        b.position = [1.0, 0.2, 0.1]
        c = CollisionTest(callback=dummy, objects=[a, b])
        check = c._mesh_collision(a, b)
        self.assertTrue(check)
github sinanislekdemir / payton / payton / scene / test_geometry.py View on Github external
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)
github sinanislekdemir / payton / payton / scene / test_geometry.py View on Github external
def test_sphere_in_sphere(self):
        a = Sphere(radius=10)
        b = Sphere(radius=2)
        b.position = [2, 2, 0]
        c = CollisionTest(callback=dummy, objects=[a, b])
        check = c._sphere_in_sphere_collision(a, b)
        self.assertTrue(check)
github sinanislekdemir / payton / examples / basics / 12_collision.py View on Github external
from payton.scene.collision import CollisionTest
from payton.scene.geometry import Cube, Sphere


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("test", collision)
github sinanislekdemir / payton / examples / basics / 30_near_far_plane.py View on Github external
if direction == 1:
        scene.active_observer.near -= 0.1
        if scene.active_observer.near < 0.5:
            direction = 2
    if direction == 2:
        scene.active_observer.far -= 0.1
        if scene.active_observer.far < 1:
            direction = 3
    if direction == 3:
        scene.active_observer.far += 0.1
        if scene.active_observer.far > 20:
            direction = 0


scene.active_observer.far = 20
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("test", collision)
github sinanislekdemir / payton / payton / scene / scene.py View on Github external
def add_collision_test(self, name: str, tester: CollisionTest) -> None:
        if not isinstance(tester, CollisionTest):
            logging.error("tester must be an instance of CollisionTest")
            return

        self.collisions[name] = tester
github sinanislekdemir / payton / examples / basics / 12_1_collision_detailed.py View on Github external
return True


def hit_aabb(collision, pairs):
    for pair in pairs:
        pair[0].material.color = [0.0, 1.0, 0]
        pair[1].material.color = [0.0, 1.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])
        return True


scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)

car_object_file = os.path.join(os.path.dirname(__file__), "lib", "Low-Poly-Racing-Car.obj")

spherical_car_1 = Wavefront(filename=car_object_file)
spherical_car_2 = Wavefront(filename=car_object_file)

aabb_car_1 = Wavefront(filename=car_object_file)
aabb_car_2 = Wavefront(filename=car_object_file)

spherical_car_1.position = [-2, 0, 0]
spherical_car_2.position = [-2, 0, 4]

aabb_car_1.position = [2, 0, 0]
aabb_car_2.position = [2, 0, 4]
github sinanislekdemir / payton / payton / scene / scene.py View on Github external
"depth": Shader(
                fragment=depth_fragment_shader, vertex=depth_vertex_shader, geometry=depth_geometry_shader,
            ),
        }
        self.shaders["depth"]._depth_shader = True

        # SDL Related Stuff
        self.window = None
        self.window_width = width
        self.window_height = height
        self._context = None
        self._mouse = [0, 0]
        self._shift_down = False
        self._ctrl_down = False
        self._rotate = False
        self.collisions: Dict[str, CollisionTest] = {}
        self._click_planes: List[CPlane] = []

        self.on_select = on_select
        self.depth_map = 0
        self.depth_map_fbo = 0
        # Main running state
        self.running = False
        self._render_lock = False
        self._shadow_quality = SHADOW_MID
        self._shadow_samples = 20
github sinanislekdemir / payton / examples / basics / 12_1_collision_detailed.py View on Github external
def hit_aabb(collision, pairs):
    for pair in pairs:
        pair[0].material.color = [0.0, 1.0, 0]
        pair[1].material.color = [0.0, 1.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])
        return True


scene = Scene(width=600, height=600)
spherical_collision = CollisionTest(callback=hit_sphere, level=CollisionTest.SPHERICAL)
aabb_collision = CollisionTest(callback=hit_aabb, level=CollisionTest.AABB)

car_object_file = os.path.join(os.path.dirname(__file__), "lib", "Low-Poly-Racing-Car.obj")

spherical_car_1 = Wavefront(filename=car_object_file)
spherical_car_2 = Wavefront(filename=car_object_file)

aabb_car_1 = Wavefront(filename=car_object_file)
aabb_car_2 = Wavefront(filename=car_object_file)

spherical_car_1.position = [-2, 0, 0]
spherical_car_2.position = [-2, 0, 4]

aabb_car_1.position = [2, 0, 0]
aabb_car_2.position = [2, 0, 4]

scene.add_object("scar1", spherical_car_1)