def on_draw(dt): global phi, theta, duration, i, cube_prog, indices window.clear() gl.glEnable(gl.GL_DEPTH_TEST) cube_prog.draw(gl.GL_TRIANGLES, indices) # Rotate cube theta += random.randint(0, 300) # degrees phi += random.randint(0, 300) # degrees view = cube_prog['u_view'].reshape(4, 4) model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube_prog['u_model'] = model cube_prog['u_normal'] = np.array(np.matrix(np.dot(view, model)).I.T) if i < count: framebuffer = np.zeros((window.height, window.width * 3), dtype=np.uint8) gl.glReadPixels(0, 0, window.width, window.height, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, framebuffer) png.from_array(framebuffer, 'RGB').save("color/" + str(dice_val) + "_" + str(i) + '.png') i += 1 else: app.quit() i = 0
def on_mouse_drag(self, x, y, dx, dy, button): model = np.eye(4, dtype=np.float32) self._theta -= dx/5.0 self._phi += dy/5.0 glm.rotate(model, self._theta, 0, 0, 1) glm.rotate(model, self._phi, 1, 0, 0) self["model"] = model
def on_draw(dt): global phi, theta window.clear() # Filled cube gl.glDisable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) cube['u_color'] = 1, 1, 1, 1 cube.draw(gl.GL_TRIANGLES, faces) # Outlined cube gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) cube['u_color'] = 0, 0, 0, 1 cube.draw(gl.GL_LINES, outline) gl.glDepthMask(gl.GL_TRUE) # Make cube rotate theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model
def matrix_model(): model = np.eye(4, dtype=np.float32) model *= size glm.rotate(model, theta, 1, 0, 0) glm.rotate(model, phi, 0, 0, 1) model[3,3] = 1 return model
def on_draw(dt): global phi, theta # Phi and Theta are the cube rotation paramters window.clear() lock.acquire() try: # Disable depth of OpenGL to update background tecture gl.glDisable(gl.GL_DEPTH_TEST) quad.draw(gl.GL_TRIANGLE_STRIP) # R-enable depth gl.glEnable(gl.GL_DEPTH_TEST) # Color of path path["u_color"] = 0, 1, 1 # Filled path path.draw(gl.GL_TRIANGLE_STRIP) # Mask depth gl.glDepthMask(gl.GL_FALSE) # Color of edge lines of path path["u_color"] = 0, 0, 0 # Width of edge lines gl.glLineWidth(10.0) # Draw edge lines with index buffer bline_I path.draw(gl.GL_LINES, bline_I) # Reset line width gl.glLineWidth(1.0) gl.glDepthMask(gl.GL_TRUE) # Define the model matrix with updated rotation model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) for obj in bag.values(): obj["u_color"] = 1, 0, 0 # Filled cube obj.draw(gl.GL_TRIANGLES, I) # Another method to disable depth, instead of disabling it, mask it gl.glDepthMask(gl.GL_FALSE) # Black color for edge lines of cube obj["u_color"] = 0, 0, 0 # Draw the edge lines with the given index buffer obj.draw(gl.GL_LINES, O) # Unmask OpenGL depth aparamter gl.glDepthMask(gl.GL_TRUE) # Model matrix is used to define orientation ,in this case, used to rotate cube obj["model"] = model # Update cube rotations theta += 2.0 # degrees phi += 2.0 # degrees finally: lock.release()
def matrix_model(model): glm.scale(model, self.size, self.size, self.size) glm.rotate(model, self.deg_y, 1, 0, 0) glm.rotate(model, self.deg_x, 0, 0, 1) glm.translate(model, self.mov_x, -self.mov_y, 0) # model[3,3] = 1 return model
def render(self, dt): if not self.draw: return False # View view = np.eye(4, dtype=np.float32) glm.translate(view, self.params["posx"], self.params["posy"], self.params["posz"]) self.program['view'] = view # Model model = np.eye(4, dtype=np.float32) glm.rotate(model, self.params["theta"], 0, 0, 1) glm.rotate(model, self.params["phi"], 0, 1, 0) self.program['model'] = model # Modulations self.program['radius'] = self.params["size"] self.program['cutoff'] = self.params['cutoff'] position = self.program['position'] angles = np.linspace(0, np.pi * self.params["ratio"] * n, n) thet = np.linspace(0, np.pi * self.params["ratio"] * 2, n) distances = np.linspace(0, (0.00005 + self.params["distance"]) * n, n) position[:, 0] = distances * np.sin(angles) * np.cos(thet) position[:, 1] = distances * np.sin(angles) * np.sin(thet) position[:, 2] = distances * np.cos(angles) # Drawing self.window.clear() self.program.draw(gl.GL_POINTS) self.draw = False return True
def on_draw(dt): global phi, theta, frame_index window.clear() cube['u_outline'] = 0.0; cube.draw(gl.GL_TRIANGLES, I) cube['u_outline'] = 1.0; cube.draw(gl.GL_LINES, O) theta += 0.5 phi += 0.5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['u_model'] = model cube['u_model_it'] = np.matrix(model).I.T frame_index += 1 print('current frame: ' + str(frame_index)) if frame_index == 100: print('changing checkboard dimension to 16') cube['u_texture'] = checkerboard(16).view(gloo.Texture2D) elif frame_index == 200: print('changing back checkboard dimension to 8') cube['u_texture'] = checkerboard().view(gloo.Texture2D)
def on_draw(dt): global phi, theta, writer, duration window.clear() gl.glEnable(gl.GL_DEPTH_TEST) cube.draw(gl.GL_TRIANGLES, faces) # Write one frame if writer is not None: if duration > 0: gl.glReadPixels(0, 0, window.width, window.height, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, fbuffer) writer.write_frame(fbuffer) duration -= dt else: writer.close() writer = None # Make cube rotate theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model
def on_draw(dt): global i, t, theta, phi, translate, program t += dt * 1000 if i != np.sum(timestamps < t) - 1: i = np.sum(timestamps < t) - 1 pointcloud = pointclouds[i] n = len(pointcloud) program = gloo.Program(vertex, fragment, count=n) program['position'] = pointcloud[:, :3] program['radius'] = 0.1 * np.ones(n) program['fg_color'] = 0, 0, 0, 1 colors = np.ones((n, 4)) colors[:, 3] = 1 program['bg_color'] = colors program['linewidth'] = 1.0 program['antialias'] = 1.0 program['model'] = np.eye(4, dtype=np.float32) program['projection'] = glm.perspective(45.0, width / float(height), 1.0, 1000.0) program['view'] = view window.clear() program.draw(gl.GL_POINTS) #theta += .5 #phi += .5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) program['model'] = model
def on_mouse_drag(self, x, y, dx, dy, button): model = np.eye(4, dtype=np.float32) self._theta -= dx / 5.0 self._phi += dy / 5.0 glm.rotate(model, self._theta, 0, 0, 1) glm.rotate(model, self._phi, 1, 0, 0) self["model"] = model
def on_draw(dt): global phi, theta, duration window.clear() # Filled cube gl.glDisable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) cube['u_color'] = 1, 1, 1, 1 cube.draw(gl.GL_TRIANGLES, I) # Outlined cube gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) cube['u_color'] = 0, 0, 0, 1 cube.draw(gl.GL_LINES, O) gl.glDepthMask(gl.GL_TRUE) # Rotate cube theta += 0.5 # degrees phi += 0.5 # degrees view = cube['u_view'].reshape(4,4) model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['u_model'] = model cube['u_normal'] = np.array(np.matrix(np.dot(view, model)).I.T)
def on_draw(dt): global phi, theta, duration window.clear() # Filled cube gl.glDisable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) cube['u_color'] = 1, 1, 1, 1 cube.draw(gl.GL_TRIANGLES, I) # Outlined cube gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) cube['u_color'] = 0, 0, 0, 1 cube.draw(gl.GL_LINES, O) gl.glDepthMask(gl.GL_TRUE) # Rotate cube theta += 1.0 # degrees phi += -1.0 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['u_model'] = model
def on_draw(dt): global phi, theta window.clear() # Filled cube gl.glDisable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) cube['u_color'] = 1, 1, 1, 1 cube.draw(gl.GL_TRIANGLES, faces) # Outlined cube gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) cube['u_color'] = 0, 0, 0, 1 cube.draw(gl.GL_LINES, outline) gl.glDepthMask(gl.GL_TRUE) # Make cube rotate theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) transform['model'] = model
def on_draw(dt): window.clear() for cube in self.cubes: cube.draw(gl.GL_TRIANGLES, I) for cube in self.elecs: cube.draw(gl.GL_TRIANGLES, I) # Make cube rotate self.theta += .5 # degrees self.phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, self.theta, 0, 1, 0) colordata = self.conn.recv() self.maxcolor = np.max([self.maxcolor, np.max(colordata)]) self.mincolor = np.min([self.mincolor, np.min(colordata)]) for cube, col in zip(self.cubes, colordata): cube['u_model'] = model cube['a_color'] = repmat( [(col - self.mincolor) / (self.maxcolor - self.mincolor), 0, 1 - ((col - self.mincolor) / (self.maxcolor - self.mincolor)), .3], 8, 1).tolist() for cube in self.elecs: cube['u_model'] = model cube['a_color'] = repmat([0, 1, 0, 1], 8, 1).tolist()
def theta(self, theta): """ Angle (in degrees) around the z axis """ self._theta = theta model = np.eye(4, dtype=np.float32) glm.rotate(model, self._theta, 0, 0, 1) glm.rotate(model, self._phi, 1, 0, 0) self["model"] = model
def matrix_model(): model = np.eye(4, dtype=np.float32) glm.scale(model, self.size, self.size, self.size) glm.rotate(model, self.deg_y, 1, 0, 0) glm.rotate(model, self.deg_x, 0, 1, 0) # glm.translate(model, -self.deg_x/100, -self.deg_y/100, 0) # model[3,3] = 1 return model
def on_draw(dt): global theta, dtheta gl.glClear(gl.GL_COLOR_BUFFER_BIT) program.draw(gl.GL_TRIANGLES, I) theta += dtheta model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) program['model'] = model
def phi(self, phi): """ Angle (in degrees) around the x axis """ self._phi = phi model = np.eye(4, dtype=np.float32) glm.rotate(model, self._theta, 0, 0, 1) glm.rotate(model, self._phi, 1, 0, 0) self["model"] = model
def on_draw(dt): global theta, dtheta gl.glClear(gl.GL_COLOR_BUFFER_BIT) C.draw() theta += dtheta model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) C['model'] = model
def global_adjustment(self): matrix = np.eye(4, dtype=np.float32) # Change xy-plan to ecef coordinate glm.rotate(matrix, 90, 0, 1, 0) glm.rotate(matrix, 90, 1, 0, 0) glm.rotate(matrix, self.yaw, -1, 0, 0) glm.rotate(matrix, self.lat, 0, -1, 0) glm.rotate(matrix, self.lon, 0, 0, 1) self.matrix_global = matrix
def matrix_model(): model = np.eye(4, dtype=np.float32) #model *= size glm.rotate(model, theta, 1, 0, 0) glm.rotate(model, -phi, 0, 1, 0) glm.translate(model, tx, ty, 0) glm.scale(model, size) #model[3,3] = 1 return model
def do_update( self ): M = np.eye( 4 ) M = glm.rotate( M, -90, 1, 0, 0 ) # rotates CCW glm.translate( M, -self.view_xyz[0], -self.view_xyz[1], -self.view_xyz[2] ) glm.rotate( M, self.view_hpr[0], 0, 1, 0 ) glm.rotate( M, self.view_hpr[1], 1, 0, 0 ) self._model = M self["model"] = self._model
def on_draw(dt): window.clear() global ALL_DATA, ALL_N, n, n_particles global rng global omega, phi_g, phi_p global positions, velocities, fitness_scores, best_positions, best_fitness_scores global global_best_position, global_best_fitness Rp = rng.rand() Rg = rng.rand() velocities *= omega velocities += (best_positions - positions) * (phi_p * Rp) velocities += (global_best_position - positions) * (phi_g * Rg) positions += velocities results = Parallel(n_jobs=1)(delayed(evaluate_particle)(particle, pos) for particle, pos in enumerate(positions)) fitness_scores = np.array([f[2] for f in results], dtype=np.float32) diff_indices = np.where(fitness_scores < best_fitness_scores)[0] if len(diff_indices) > 0: best_positions[diff_indices, :] = positions[diff_indices, :] best_fitness_scores[diff_indices] = fitness_scores[diff_indices] new_best_fitness_indices = np.where( fitness_scores < global_best_fitness)[0] if len(new_best_fitness_indices) > 0: new_best_fitness_value = np.min( fitness_scores[new_best_fitness_indices]) new_best_fitness_arg = np.argmin( fitness_scores[new_best_fitness_indices]) global_best_fitness = new_best_fitness_value global_best_position = positions[new_best_fitness_arg] # # # global program ALL_DATA = np.vstack((VIEW_DATA, positions)) program["position"] = 0.75 * ALL_DATA # # # global theta, phi, translate global sx, sy, sz window.clear() program.draw(gl.GL_POINTS) model = np.eye(4, dtype=np.float32) glm.scale(model, sx, sy, sz) glm.rotate(model, theta, 1, 0, 0) glm.rotate(model, phi, 0, 1, 0) glm.translate(model, tx, ty, tz) program["model"] = model
def on_draw(dt): global theta, phi, translate window.clear() program.draw(gl.GL_POINTS) theta += .5 phi += .5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) program['model'] = model
def on_draw(dt): global phi, theta, duration window.clear() spiral.draw(gl.GL_TRIANGLE_STRIP) theta += .1 # degrees phi += .2 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 1, 0) glm.rotate(model, phi, 1, 0, 0) spiral['model'] = model
def on_draw(dt): global phi, theta window.clear() program.draw(gl.GL_TRIANGLES, I) theta += 0.5 phi += 0.5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) program['model'] = model
def on_draw(dt): global phi, theta, duration window.clear() program.draw(gl.GL_TRIANGLES, indices) theta += 0.5 phi += 0.5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) program['model'] = model program['normal'] = np.array(np.matrix(np.dot(view, model)).I.T)
def on_draw(dt): global phi, theta, duration window.clear() program.draw(gl.GL_TRIANGLES, indices) theta += 1.0 # degree phi += 1.0 # degree model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) program['model'] = model
def on_draw(dt): global theta, phi program['position'], program['radius'], program['bg_color'] = next(fx) window.clear() program.draw(gl.GL_POINTS) theta += .5 phi += .5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) program['model'] = model
def on_draw(dt): global phi, theta window.clear() cube.draw(gl.GL_TRIANGLES, tris) theta += 1 phi += -1 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model
def apply_yaw_flip(self): if self.isInverse: matrix = np.eye(4, dtype=np.float32) if self.isYaw: glm.rotate(matrix, self.anchor_yaw, 0, 0, 1) self.data['a_position'] = base_process.sv3d_apply_m4( data=self.data['a_position'],m4=matrix) else: glm.rotate(matrix, self.anchor_yaw, 0, 0, -1) self.data['a_position'] = \ self.data['a_position'] = base_process.sv3d_apply_m4( data=self.data['a_position'], m4=matrix) self.isYaw = not self.isYaw
def on_draw(dt): global phi, theta with pixelate: window.clear() gl.glEnable(gl.GL_DEPTH_TEST) cube.draw(gl.GL_TRIANGLES, faces) theta += 0.5 phi += 0.5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model
def on_draw(dt): global phi, theta with compose: window.clear() gl.glEnable(gl.GL_DEPTH_TEST) cube.draw(gl.GL_TRIANGLES, faces) theta += 0.5 phi += 0.5 model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model
def apply_yaw_flip(self): if self.isInverse: matrix = np.eye(4, dtype=np.float32) if self.isYaw: glm.rotate(matrix, self.anchor_yaw, 0, 0, 1) self.data['a_position'] = base_process.sv3d_apply_m4( data=self.data['a_position'], m4=matrix) else: glm.rotate(matrix, self.anchor_yaw, 0, 0, -1) self.data['a_position'] = \ self.data['a_position'] = base_process.sv3d_apply_m4( data=self.data['a_position'], m4=matrix) self.isYaw = not self.isYaw
def global_position(self, lat=0, lon=0, yaw=0): self.lat, self.lon, self.yaw = lat, lon, yaw glm.rotate(self.u_model, 180, 0, 1, 0) glm.rotate(self.u_model, yaw, 0, 0, -1) glm.rotate(self.u_model, lat, -1, 0, 0) glm.rotate(self.u_model, lon, 0, 1, 0)
def on_draw(dt): global phi, theta window.clear() # Filled cube cube.draw(gl.GL_TRIANGLES, I) # Make cube rotate theta += 1.0 # degrees phi += 1.0 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['model'] = model
def on_draw(dt): global phi, theta window.clear() # Filled cube cube.draw(gl.GL_TRIANGLES, I) # Rotate cube theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['u_model'] = model
def on_draw(dt): global phi, theta, duration window.clear() gl.glDisable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) cube.draw(gl.GL_TRIANGLES, indices) # Rotate cube theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['u_model'] = model
def on_draw(dt): global phi, theta, duration window.clear() gl.glEnable(gl.GL_DEPTH_TEST) cube.draw(gl.GL_TRIANGLES, indices) # Rotate cube theta += 0.5 # degrees phi += 0.5 # degrees view = cube['u_view'].reshape(4,4) model = np.eye(4, dtype=np.float32) glm.rotate(model, theta, 0, 0, 1) glm.rotate(model, phi, 0, 1, 0) cube['u_model'] = model cube['u_normal'] = np.array(np.matrix(np.dot(view, model)).I.T)
def apply_anchor_plus_rotate(self): matrix = self.anchor_matrix glm.rotate(matrix, 180, 0, 1, 0) self.data['a_position'] = base_process.sv3d_apply_m4(data=self.data['a_position'], m4=np.linalg.inv(matrix))
def __init__(self, window_width=1024, window_height=1024, degree=0): self.programs = [] window = app.Window(window_width, window_height, color=(0, 0, 0, 1)) framebuffer = np.zeros((window.height, window.width * 3), dtype=np.uint8) self.deg_x, self.deg_y, self.mov_x, self.mov_y, self.size, self.zoom, self.radius = 0, 0, 0, 0, 1, -200, 200 self.u_model, self.u_view, self.u_projection = np.eye(4, dtype=np.float32), np.eye(4, dtype=np.float32), np.eye( 4, dtype=np.float32) u_view = np.eye(4, dtype=np.float32) glm.rotate(u_view, -90, 1, 0, 0) #glm.rotate(u_view, -70, 1, 0, 0) glm.rotate(u_view, degree + 270, 0, 1, 0) glm.translate(u_view, 0, 0, 0) #(0, 0, -125) self.u_view = u_view self.demo_dt = 0 self.scIdx = 0 @window.event def on_draw(dt): window.clear() demo_idx = 0 for program_object in self.programs: program = program_object.program model = matrix_model(np.copy(program_object.u_model)) #self.deg_x += dt*20 #self.deg_y += dt*40 self.demo_dt += dt/5 demo_idx += 1 ''' if self.demo_dt > 2: if demo_idx == 1: if self.demo_dt > 2.4: if program['alpha'] <= 0.1: continue else: program['alpha'] -= 0.01 elif demo_idx == 2: if self.demo_dt > 2.8: program['alpha'] += 0.01 ''' program['u_model'] = np.dot(model, self.u_model) program['u_view'] = self.u_view program['u_projection'] = self.u_projection if program_object.draw_mode == gl.GL_TRIANGLES: program.draw(program_object.draw_mode, program_object.face) elif program_object.draw_mode == gl.GL_LINES and program_object.name == 'ProgramSFM3DRegion': gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) program.draw(program_object.draw_mode, program_object.O) gl.glDepthMask(gl.GL_TRUE) else: program.draw(program_object.draw_mode) @window.event def on_resize(width, height): ratio = width / float(height) self.u_projection = glm.perspective(64.0, ratio, 1, 10000.0) @window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) @window.event def on_mouse_scroll(x, y, dx, dy): if self.size + dy * 0.1 < 0.1: self.size = 0.1 else: # self.size += dy * 0.1 # self.zoom += dy*1 self.u_view = glm.translate(self.u_view , 0, 0, dy) @window.event def on_mouse_drag(x, y, dx, dy, button): if button == 2: self.deg_y += dy # degrees self.deg_x += dx # degrees elif button == 8: self.mov_y += dy/10 # degrees self.mov_x += dx/10 # degrees @window.event def on_key_press(symbol, modifiers): """ :param symbol: :param modifiers: :return: """ ''' if symbol == 88: # x self.view_orth_vector = np.array([self.radius, 0, 0]) self.program['u_view'] = glm.translation(self.view_orth_vector[0], self.view_orth_vector[1], self.view_orth_vector[2]) elif symbol == 89: # y self.view_orth_vector = np.array([0, self.radius, 0]) self.program['u_view'] = glm.translation(self.view_orth_vector[0], self.view_orth_vector[1], self.view_orth_vector[2]) elif symbol == 90: # z self.view_orth_vector = np.array([0, 0, self.radius]) self.program['u_view'] = glm.translation(self.view_orth_vector[0], self.view_orth_vector[1], self.view_orth_vector[2]) elif symbol == 70: # f self.view_orth_vector = -self.view_orth_vector self.program['u_view'] = glm.translation(self.view_orth_vector[0], self.view_orth_vector[1], self.view_orth_vector[2]) elif symbol == 80: # p gl.glReadPixels(0, 0, window.width, window.height, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, framebuffer) png.from_array(framebuffer, 'RGB').save('screenshot.png') print('Key pressed (symbol=%s, modifiers=%s)' % (symbol, modifiers)) # self.program['color_sel'] = 1 - self.program['color_sel'] ''' #print(symbol) if symbol == 67: # c --> change color for program_object in self.programs: if program_object.name == 'ProgramSFM3DRegion': program_object.program['color_sel'] = 1 - program_object.program['color_sel'] elif symbol == 65: # a --> align sfm to google for program_object in self.programs: if program_object.name == 'ProgramSFM3DRegion' or program_object.name == 'programTrajectory': program_object.align_flip() elif symbol == 73: # i --> inverse google according anchor for program_object in self.programs: if program_object.name == 'ProgramSV3DRegion': program_object.apply_anchor_flip() elif symbol == 89: # y --> rotate google according anchor yaw for program_object in self.programs: if program_object.name == 'ProgramSV3DRegion': program_object.apply_yaw_flip() elif symbol == 80: # p --> print scrren gl.glReadPixels(0, 0, window.width, window.height, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, framebuffer) #png.from_array(framebuffer, 'RGB').save('screenshot{}.png'.format(self.scIdx)) my_texture = np.reshape(framebuffer, (window.height, window.width, 3)) # Some unknown reason # The buffer didn't match what I see in the window my_texture = np.flipud(my_texture) scipy.misc.imsave('yolo.png', my_texture) self.scIdx += 1 def matrix_model(model): glm.scale(model, self.size, self.size, self.size) glm.rotate(model, self.deg_y, 1, 0, 0) glm.rotate(model, self.deg_x, 0, 0, 1) glm.translate(model, self.mov_x, -self.mov_y, 0) # model[3,3] = 1 return model
def info_3d_offs(self): glm.rotate(self.u_model, 180, 0, 1, 0)