Exemplo n.º 1
0
    def enable3d(self):
        self.point1 = self.point-(self.mesh_diagonal_norm/60)*self.axis2
        self.point2 = self.point+(self.mesh_diagonal_norm/60)*self.axis2

        self.viewing_angle = 0.0

        pos1, dir1 = from_film(self.point1, axis1=self.axis1, axis2=self.axis2,
                               size=self.size, width=self.film_width)
        pos2, dir2 = from_film(self.point2, axis1=self.axis1, axis2=self.axis2,
                               size=self.size, width=self.film_width)

        self.rays1 = gpu.GPURays(pos1, dir1,
                                 max_alpha_depth=self.max_alpha_depth)
        self.rays2 = gpu.GPURays(pos2, dir2,
                                 max_alpha_depth=self.max_alpha_depth)

        scope_size = (self.size[0]//4, self.size[0]//4)

        scope_pos, scope_dir = from_film(self.point, axis1=self.axis1,
                                         axis2=self.axis2, size=scope_size,
                                         width=self.film_width/4.0)

        self.scope_rays = gpu.GPURays(scope_pos, scope_dir)

        self.scope_pixels_gpu = ga.empty(self.scope_rays.pos.size, dtype=np.uint32)

        self.pixels1_gpu = ga.empty(self.width*self.height, dtype=np.uint32)
        self.pixels2_gpu = ga.empty(self.width*self.height, dtype=np.uint32)
        
        self.distances_gpu = ga.empty(self.scope_rays.pos.size,
                                      dtype=np.float32)
        self.display3d = True
Exemplo n.º 2
0
    def init_gpu(self):
        self.context = gpu.create_cuda_context(self.device_id)

        self.gpu_geometry = gpu.GPUGeometry(self.geometry)
        self.gpu_funcs = gpu.GPUFuncs(gpu.get_cu_module('mesh.h'))
        self.hybrid_funcs = gpu.GPUFuncs(gpu.get_cu_module('hybrid_render.cu'))

        self.gpu_geometries = [self.gpu_geometry]

        self.width, self.height = self.size

        self.npixels = self.width * self.height

        self.clock = pygame.time.Clock()

        self.doom_mode = False
        try:
            if self.width == 640:  # SECRET DOOM MODE!
                print 'shotgun activated!'
                self.doom_hud = pygame.image.load(
                    'images/doomhud.png').convert_alpha()
                rect = self.doom_hud.get_rect()
                self.doom_rect = rect.move(0, self.height - rect.height)
                self.doom_mode = True
        except:
            pass

        lower_bound, upper_bound = self.geometry.mesh.get_bounds()

        self.mesh_diagonal_norm = np.linalg.norm(upper_bound - lower_bound)

        self.scale = self.mesh_diagonal_norm

        self.motion = 'coarse'

        self.nblocks = 64

        self.point = np.array([
            0, -self.mesh_diagonal_norm, (lower_bound[2] + upper_bound[2]) / 2
        ])

        self.axis1 = np.array([0, 0, 1], float)
        self.axis2 = np.array([1, 0, 0], float)

        self.film_width = 35.0  # mm

        pos, dir = from_film(self.point,
                             axis1=self.axis1,
                             axis2=self.axis2,
                             size=self.size,
                             width=self.film_width)

        self.rays = gpu.GPURays(pos, dir, max_alpha_depth=self.max_alpha_depth)

        self.pixels_gpu = ga.empty(self.npixels, dtype=np.uint32)

        self.movie = False
        self.movie_index = 0
        self.movie_dir = None
        self.hybrid_render = False
Exemplo n.º 3
0
    def disable3d(self):
        pos, dir = from_film(self.point, axis1=self.axis1, axis2=self.axis2,
                             size=self.size, width=self.film_width)

        self.rays = gpu.GPURays(pos, dir, max_alpha_depth=self.max_alpha_depth)
        
        self.display3d = False
Exemplo n.º 4
0
    def init_gpu(self):
        self.context = gpu.create_cuda_context(self.device_id)

        self.gpu_geometry = gpu.GPUGeometry(self.geometry)
        self.gpu_funcs = gpu.GPUFuncs(gpu.get_cu_module('mesh.h'))
        self.hybrid_funcs = gpu.GPUFuncs(gpu.get_cu_module('hybrid_render.cu'))

        self.gpu_geometries = [self.gpu_geometry]

        self.width, self.height = self.size

        self.npixels = self.width*self.height

        self.clock = pygame.time.Clock()

        self.doom_mode = False
        
        try:
            if self.width == 640: # SECRET DOOM MODE!
                print 'shotgun activated!'
                self.doom_hud = pygame.image.load('images/doomhud.png').convert_alpha()
                rect = self.doom_hud.get_rect()
                self.doom_rect = rect.move(0, self.height - rect.height)
                self.doom_mode = True
        except:
            pass

        lower_bound, upper_bound = self.geometry.mesh.get_bounds()

        self.mesh_diagonal_norm = np.linalg.norm(upper_bound-lower_bound)

        self.scale = self.mesh_diagonal_norm

        self.motion = 'coarse'

        self.nblocks = 64

        self.point = np.array([0, -self.mesh_diagonal_norm,
                               (lower_bound[2]+upper_bound[2])/2])

        self.axis1 = np.array([0,0,1], float)
        self.axis2 = np.array([1,0,0], float)

        self.film_width = 35.0 # mm

        pos, dir = from_film(self.point, axis1=self.axis1, axis2=self.axis2,
                             size=self.size, width=self.film_width)

        self.rays = gpu.GPURays(pos, dir, max_alpha_depth=self.max_alpha_depth)

        self.pixels_gpu = ga.empty(self.npixels, dtype=np.uint32)

        self.movie = False
        self.movie_index = 0
        self.movie_dir = None
        self.hybrid_render = False