Exemple #1
0
def intersect_ray_spheres_bool(n):
    asm = util.get_asm()
    mc = asm.assemble(ASM1)
    runtime = Runtime()

    #Sphere.intersectbool_asm(runtime, "ray_sphere_intersect")
    Sphere.intersect_asm(runtime, "ray_sphere_intersect")
    ds = runtime.load("test", mc)

    for x in range(n):
        sphere = generate_sphere()
        ray = generate_ray()
        ds["sph.origin"] = v4(sphere.origin)
        ds["sph.radius"] = sphere.radius
        ds["sph.mat_index"] = sphere.material

        ds["r1.origin"] = v4(ray.origin)
        ds["r1.dir"] = v4(ray.dir)

        hp = sphere.intersect(ray, 999999.0)

        runtime.run("test")

        if hp is not False and ds["hit"] == 0:
            print(hp.t, ds["t"], ds["hit"])
        if hp is False and ds["hit"] == 1:
            print(ds["t"], ds["hit"])

        if hp is not False:
            print_hitpoint(ds, hp)
Exemple #2
0
def intersect_ray_spheres_bool(n):
    asm = util.get_asm()
    mc = asm.assemble(ASM1)
    runtime = Runtime()
    
    #Sphere.intersectbool_asm(runtime, "ray_sphere_intersect")
    Sphere.intersect_asm(runtime, "ray_sphere_intersect")
    ds = runtime.load("test", mc)

    for x in range(n):
        sphere = generate_sphere()
        ray = generate_ray()
        ds["sph.origin"] = v4(sphere.origin)
        ds["sph.radius"] = sphere.radius
        ds["sph.mat_index"] = sphere.material

        ds["r1.origin"] = v4(ray.origin)
        ds["r1.dir"] = v4(ray.dir)

        hp = sphere.intersect(ray, 999999.0)
        
        runtime.run("test")
        
        if hp is not False and ds["hit"] == 0:
            print(hp.t, ds["t"], ds["hit"])
        if hp is False and ds["hit"] == 1:
            print(ds["t"], ds["hit"])

        if hp is not False:
            print_hitpoint(ds, hp)
Exemple #3
0
def intersect_sphere(runtime, ds):
    sphere = Sphere(Vector3(0.0, 0.0, 0.0), 1.5, 2)
    direction = Vector3(-7.0, -7.0, -6.0)
    direction.normalize()
    ray = Ray(Vector3(8.0, 7.0, 6.0), direction)
    ds["sph.origin"] = v4(sphere.origin)
    ds["sph.radius"] = sphere.radius
    ds["sph.mat_index"] = sphere.material

    ds["r1.origin"] = v4(ray.origin)
    ds["r1.dir"] = v4(ray.dir)

    hp = sphere.intersect(ray, 999999.0)

    runtime.run("test")
    if hp is not False:
        print(hp.t, ds["t"], ds["hit"])
        print("Python =", hp.t, "Asm = ", ds["hp.t"])
        print("Python =", hp.hit_point)
        print("Asm =", ds["hp.hit"])
        print("Python =", hp.normal)
        print("Asm =", ds["hp.normal"])
        print("Python = ", hp.material, " ASM = ", ds["hp.mat_index"])

        #print(ds["a"], ds["b"], ds["disc"], ds["temp"])
    else:
        print(hp, ds["hit"])
Exemple #4
0
def intersect_sphere(runtime, ds):
    sphere = Sphere(Vector3(0.0, 0.0, 0.0), 1.5, 2)
    direction = Vector3(-7.0, -7.0, -6.0)
    direction.normalize()
    ray = Ray(Vector3(8.0, 7.0, 6.0), direction)
    ds["sph.origin"] = v4(sphere.origin)
    ds["sph.radius"] = sphere.radius
    ds["sph.mat_index"] = sphere.material

    ds["r1.origin"] = v4(ray.origin)
    ds["r1.dir"] = v4(ray.dir)

    hp = sphere.intersect(ray, 999999.0)
    
    runtime.run("test")
    if hp is not False:
        print(hp.t, ds["t"], ds["hit"])
        print("Python =", hp.t, "Asm = ", ds["hp.t"])
        print("Python =", hp.hit_point)
        print("Asm =", ds["hp.hit"])
        print("Python =", hp.normal)
        print("Asm =", ds["hp.normal"])
        print("Python = ", hp.material, " ASM = ", ds["hp.mat_index"])

        #print(ds["a"], ds["b"], ds["disc"], ds["temp"])
    else:
        print (hp, ds["hit"])
Exemple #5
0
def generate_sphere():
    x = random.random() * 10.0 - 5.0
    y = random.random() * 10.0 - 5.0
    z = random.random() * 10.0 - 5.0
    radius = random.random() * 10.0

    sphere = Sphere(Vector3(x, y, z), radius, 2)
    return sphere
Exemple #6
0
def generate_spheres(n):
    dyn_array = util.DynamicArray(Sphere.struct())
    spheres = []

    for x in range(n):
        sphere = generate_sphere()
        dyn_array.add_instance(sphere.struct_params())
        spheres.append(sphere)
    return spheres, dyn_array
Exemple #7
0
def generate_spheres(n):
    dyn_array = util.DynamicArray(Sphere.struct())
    spheres = []
    
    for x in range(n):
        sphere = generate_sphere() 
        dyn_array.add_instance(sphere.struct_params())
        spheres.append(sphere)
    return spheres, dyn_array
Exemple #8
0
def random_sphere():
    x = 0.0
    y = 0.0
    z = 0.0
    radius = 3.0

    v1 = Vector3(x, y, z)
    sphere = Sphere(v1, radius, 99999)

    return sphere
Exemple #9
0

if __name__ == "__main__":

    asm = util.get_asm()
    mc = asm.assemble(ASM)
    #mc.print_machine_code()

    runtime = Runtime()
    #ds = runtime.load("test", mc)

    #intersect_sphere(runtime, ds)
    #intersect_ray_spheres(100000, runtime, ds)
    #intersect_ray_spheres_bool(10)

    Sphere.intersect_asm(runtime, "_sphere_intersect")
    intersect_ray_shape_array("sphere", runtime, "sphere_array",
                              "_sphere_intersect")
    mc = asm.assemble(ASM2)
    ds = runtime.load("test2", mc)
    spheres, dyn_spheres = generate_spheres(1000)

    ray = generate_ray()
    hp = ray_objects(ray, spheres)

    adr = dyn_spheres.get_addr()
    ds["ptr_spheres"] = adr
    ds["nspheres"] = dyn_spheres.size

    ds["r1.origin"] = v4(ray.origin)
    ds["r1.dir"] = v4(ray.dir)
Exemple #10
0
    t = timeit.Timer(lambda : isect(ray, shape_db.shapes()))
    print ("time", t.timeit(1))
    hp = isect(ray, shape_db.shapes())
    hp2 = isect_ray_scene(ray)

    asm = util.get_asm()

    dy_spheres = shape_db.asm_shapes[Sphere]
    dy_planes = shape_db.asm_shapes[Plane]

    #ds["r1.origin"] = v4(ray.origin)
    #ds["r1.dir"] = v4(ray.dir)
    
    runtime = Runtime()

    Sphere.intersect_asm(runtime, "_sphere_intersect")
    intersect_ray_shape_array("sphere", runtime, "sphere_array", "_sphere_intersect")
    Plane.intersect_asm(runtime, "_plane_intersect")
    intersect_ray_shape_array("plane", runtime, "plane_array", "_plane_intersect")

    mc = asm.assemble(ASM)

    ds = runtime.load("test", mc)

    ds["r1.origin"] = v4(ray.origin)
    ds["r1.dir"] = v4(ray.dir)
    ds["ptr_spheres"] = dy_spheres.get_addr()
    ds["nspheres"] = dy_spheres.size
    ds["ptr_planes"] = dy_planes.get_addr()
    ds["nplanes"] = dy_planes.size