Ejemplo n.º 1
0
    def test_isect_b(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm_b([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code_bool())
        ds = runtime.load("test", mc)

        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"] != 0)
        if ds["ret"] == 0: self.assertFalse(hp)
Ejemplo n.º 2
0
    def test_isect_b(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm_b([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code_bool())
        ds = runtime.load("test", mc)

        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"]!=0)
        if ds["ret"] == 0: self.assertFalse(hp)
Ejemplo n.º 3
0
    def intersect(self, ray, rectangle, runtime, ds):
        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"] != 0)
        if ds["ret"] == 0: self.assertFalse(hp)
        if hp is not False:
            self.compare(hp, ds, "hp1", ray, rectangle)
Ejemplo n.º 4
0
    def intersect(self, ray, rectangle, runtime, ds):
        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"]!=0)
        if ds["ret"] == 0: self.assertFalse(hp)
        if hp is not False:
            self.compare(hp, ds, "hp1", ray, rectangle)
Ejemplo n.º 5
0
def asm_code(label_ray_mesh_isect, mesh):
    struct_name = mesh.asm_struct_name()
    code = """
        #DATA
    """
    code += Ray.asm_struct() + mesh.asm_struct() + HitPoint.asm_struct() + """
        Ray ray1
    """
    code += struct_name + " mesh1" + """
        Hitpoint hp1
        float min_dist = 99999.000
        float max_dist = 99999.000
        uint32 ret
        float t
        #CODE
        macro eq32 min_dist = max_dist {xmm7}
        macro mov eax, ray1
        macro mov ebx, mesh1
        macro mov ecx, min_dist
        macro mov edx, hp1
    """
    code += "call " + label_ray_mesh_isect + """ 
        mov dword [ret], eax
        macro eq32 t = xmm0 {xmm7}
        #END
    """
    return code
Ejemplo n.º 6
0
def random_ray(ds):
    origin = Vector3(0.0, 0.0, 0.0)
    direction = Vector3(random(), random(), random())
    direction.normalize()
    ray = Ray(origin, direction)
    ray_ds(ds, ray, 'ray1')
    return ray
Ejemplo n.º 7
0
    def test_isect1(self):
        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
        sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2)

        runtime = Runtime()
        assembler = create_assembler()
        sphere.isect_asm([runtime], "ray_sphere_intersection")
        mc = assembler.assemble(self.asm_code())
        ds = runtime.load("test", mc)

        self.intersect(ray, sphere, runtime, ds)
        for i in range(100):
            r = self.random_ray()
            s = self.random_sphere()
            self.intersect(r, s, runtime, ds)
Ejemplo n.º 8
0
    def asm_code_bool(self):
        code = """
            #DATA
        """
        code += Ray.asm_struct() + Rectangle.asm_struct() + """
            Ray ray1
            Rectangle rec1
            float min_dist = 99999.000
            uint32 ret

            #CODE
            macro mov eax, ray1
            macro mov ebx, rec1 
            macro mov ecx, min_dist
            call ray_rectangle_intersection 
            mov dword [ret], eax

            #END
        """
        return code
Ejemplo n.º 9
0
 def asm_code2(self):
     code = """
         #DATA
     """
     code += Ray.asm_struct() + Sphere.asm_struct() + """
         Ray ray1
         Sphere sph1
         float min_dist = 99999.000
         uint32 ret
         float t
         #CODE
         macro mov eax, ray1
         macro mov ebx, sph1
         macro mov ecx, min_dist
         call ray_sphere_intersection 
         mov dword [ret], eax
         macro eq32 t = xmm0 {xmm0}
         #END
     """
     return code
Ejemplo n.º 10
0
    def test_isect1(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code())
        ds = runtime.load("test", mc)

        self.intersect(ray, rectangle, runtime, ds)
Ejemplo n.º 11
0
 def asm_code(self):
     code = """
         #DATA
     """
     code += Ray.asm_struct() + Sphere.asm_struct() + HitPoint.asm_struct() + """
         Ray ray1
         Sphere sph1
         Hitpoint hp1
         float min_dist = 99999.000
         uint32 ret
         #CODE
         macro mov eax, ray1
         macro mov ebx, sph1
         macro mov ecx, min_dist
         macro mov edx, hp1
         call ray_sphere_intersection 
         mov dword [ret], eax
         #END
     """
     return code
Ejemplo n.º 12
0
 def asm_code2(self):
     code = """
         #DATA
     """
     code += Ray.asm_struct() + Sphere.asm_struct() + """
         Ray ray1
         Sphere sph1
         float min_dist = 99999.000
         uint32 ret
         float t
         #CODE
         macro mov eax, ray1
         macro mov ebx, sph1
         macro mov ecx, min_dist
         call ray_sphere_intersection 
         mov dword [ret], eax
         macro eq32 t = xmm0 {xmm0}
         #END
     """
     return code
Ejemplo n.º 13
0
    def asm_code_bool(self):
        code = """
            #DATA
        """
        code += Ray.asm_struct() + Rectangle.asm_struct() + """
            Ray ray1
            Rectangle rec1
            float min_dist = 99999.000
            uint32 ret

            #CODE
            macro mov eax, ray1
            macro mov ebx, rec1 
            macro mov ecx, min_dist
            call ray_rectangle_intersection 
            mov dword [ret], eax

            #END
        """
        return code
Ejemplo n.º 14
0
 def asm_code(self):
     code = """
         #DATA
     """
     code += Ray.asm_struct() + Sphere.asm_struct() + HitPoint.asm_struct(
     ) + """
         Ray ray1
         Sphere sph1
         Hitpoint hp1
         float min_dist = 99999.000
         uint32 ret
         #CODE
         macro mov eax, ray1
         macro mov ebx, sph1
         macro mov ecx, min_dist
         macro mov edx, hp1
         call ray_sphere_intersection 
         mov dword [ret], eax
         #END
     """
     return code
Ejemplo n.º 15
0
    def asm_code(self):
        code = """
            #DATA
        """
        code += Ray.asm_struct() + Rectangle.asm_struct() + HitPoint.asm_struct() + """
            Ray ray1
            Rectangle rec1
            Hitpoint hp1
            float min_dist = 99999.000
            uint32 ret

            #CODE
            mov eax, ray1
            mov ebx, rec1 
            mov ecx, min_dist
            mov edx, hp1
            call ray_rectangle_intersection 
            mov dword [ret], eax

            #END
        """
        return code
Ejemplo n.º 16
0
    def asm_code(self):
        code = """
            #DATA
        """
        code += Ray.asm_struct() + Rectangle.asm_struct(
        ) + HitPoint.asm_struct() + """
            Ray ray1
            Rectangle rec1
            Hitpoint hp1
            float min_dist = 99999.000
            uint32 ret

            #CODE
            mov eax, ray1
            mov ebx, rec1 
            mov ecx, min_dist
            mov edx, hp1
            call ray_rectangle_intersection 
            mov dword [ret], eax

            #END
        """
        return code
Ejemplo n.º 17
0
t = Triangle(v0, v1, v2)

v0 = Vector3(2.6, 4.4, 6.6)
v1 = Vector3(1.2, 1.1, 1.1)
v2 = Vector3(5.1, -1.1, 5.1)

t2 = Triangle(v0, v1, v2)

mgr = ShapeManager()
mgr.add('t1', t)
mgr.add('t2', t2)

origin = Vector3(0.2, 0.4, 0.6)
direction = Vector3(1.2, 1.1, 1.12)
direction.normalize()
ray = Ray(origin, direction)

linear = LinearIsect(mgr)

hit = linear.isect(ray)

runtime = Runtime()
linear.isect_asm([runtime], 'ray_scene_intersection')

code = "#DATA \n"
code += Ray.asm_struct() + HitPoint.asm_struct() + """
    Ray ray1
    Hitpoint hp1
    uint32 ret

    #CODE
Ejemplo n.º 18
0
from renmas3.base import Vector3, Ray
from renmas3.shapes import Triangle, HitPoint
from renmas3.macros import create_assembler

v0 = Vector3(2.2, 4.4, 6.6)
v1 = Vector3(1.1, 1.1, 1.1)
v2 = Vector3(5.1, -1.1, 5.1)

n0 = Vector3(1.1, -1.6, 1.1)
n1 = Vector3(1.1, -2.1, 3.1)
n2 = Vector3(4.1, -0.1, 2.1)

origin = Vector3(0.0, 0.0, 0.0)
direction = Vector3(3, 3.0, 3.01)
direction.normalize()
ray = Ray(origin, direction)
t = Triangle(v0,
             v1,
             v2,
             n0=n0,
             n1=n1,
             n2=n2,
             tu0=0.1,
             tv0=0.6,
             tu1=0.2,
             tv1=0.5,
             tu2=0.45,
             tv2=0.2)

min_dist = 1.93
hit = t.isect(ray, min_dist)
Ejemplo n.º 19
0
def generate_ray(bbox):
    dir = random_in_bbox(bbox) 
    dir.normalize()
    origin = Vector3(0.0, 0.0, 0.0)
    return Ray(origin, dir)
Ejemplo n.º 20
0
t = Triangle(v0, v1, v2, n0=n0, n1=n1, n2=n2, tu0=0.1, tv0=0.6, tu1=0.2,
        tv1=0.5, tu2=0.45, tv2=0.2)

min_dist = 1.93
hit = t.isect(ray, min_dist)

runtime1 = Runtime()
runtimes = [runtime1]

asm = create_assembler()
Triangle.isect_asm(runtimes, "ray_triangle_intersection")

code = """
    #DATA
"""
code += Ray.asm_struct() + Triangle.asm_struct() + HitPoint.asm_struct() + """
    Ray ray1
    Triangle tri1
    Hitpoint hp1
    uint32 ret
    float min_dist = 1.92
    float _xmm0

    #CODE
    macro mov eax, ray1
    macro mov ebx, tri1
    macro mov ecx, min_dist
    macro mov edx, hp1
    call ray_triangle_intersection 
    mov dword [ret], eax
    macro eq32 _xmm0 = xmm0 {xmm0}
Ejemplo n.º 21
0
mgr.add('t2', t2)

origin = Vector3(0.2, 0.4, 0.6)
direction = Vector3(1.2, 1.1, 1.12)
direction.normalize()
ray = Ray(origin, direction)

linear = LinearIsect(mgr)

hit = linear.isect(ray)

runtime = Runtime()
linear.isect_asm([runtime], 'ray_scene_intersection')

code = "#DATA \n"
code += Ray.asm_struct() + HitPoint.asm_struct() + """
    Ray ray1
    Hitpoint hp1
    uint32 ret

    #CODE
    macro mov eax, ray1
    macro mov ebx, hp1
    call ray_scene_intersection 
    mov dword [ret], eax
    #END
"""
asm = create_assembler()
mc = asm.assemble(code)

ds = runtime.load('test', mc)
Ejemplo n.º 22
0
 def random_ray(self):
     origin = Vector3(random(), random(), random())
     direction = Vector3(random(), random(), random())
     direction.normalize()
     return Ray(origin, direction)