def render(self): glClearColor(0.2, 0.3, 0.3, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_DEPTH_TEST) glEnable(GL_MULTISAMPLE) glEnable(GL_BLEND) # glEnable(GL_CULL_FACE) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) self.basic_lighting_shader.use() print_opengl_error() model = glm.mat4(1.0) self.basic_lighting_shader.set_mat4('model', np.asarray(model)) view = self.camera.get_view() self.basic_lighting_shader.set_mat4('view', np.asarray(view)) projection = glm.perspective(glm.radians(45.0), 1200. / 900, 0.1, 100.0) self.basic_lighting_shader.set_mat4('projection', np.asarray(projection)) # colors # self.basic_lighting_shader.set_vec3('objectColor', np.array([1.0, 0.5, 0.31], 'f')) self.basic_lighting_shader.set_vec3('lightColor', np.array([1.0, 1.0, 1.0], 'f')) # light lightPos = glm.vec3([1.00, 1.75, 10.0]) self.basic_lighting_shader.set_vec3('lightPos', np.asarray(lightPos)) # camera cameraPos = glm.vec3(glm.column(glm.inverse(view), 3)) self.basic_lighting_shader.set_vec3('viewPos', np.asarray(cameraPos)) # Draw object. if self.draw_mesh: # Draw obstacles. self.basic_lighting_shader.set_vec3('objectColor', get_color('gray')) self.collision_manager.draw(self.basic_lighting_shader.id, True, True) # Draw object. self.basic_lighting_shader.set_vec3('objectColor', get_color('clay')) self.target.draw3d(self.basic_lighting_shader.id) # Draw normals. self.normal_shader.use() self.normal_shader.set_mat4('model', np.asarray(model)) self.normal_shader.set_mat4('view', np.asarray(view)) self.normal_shader.set_mat4('projection', np.asarray(projection)) if self.draw_normals: self.mesh.draw(self.normal_shader) # Draw edges and light. self.lamp_shader.use() self.lamp_shader.set_mat4('model', np.asarray(model)) self.lamp_shader.set_mat4('view', np.asarray(view)) self.lamp_shader.set_mat4('projection', np.asarray(projection)) self.lamp_shader.set_vec3('objectColor', np.ones((3, 1), 'float32')) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) if self.draw_wireframe: # Draw object. self.target.draw3d(self.lamp_shader.id) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) light_model = glm.mat4(1.0) light_model = glm.translate(light_model, lightPos) self.lamp_shader.set_mat4('model', np.asarray(light_model)) # self.light_box.draw(self.lamp_shader) self.lamp_shader.set_mat4('model', np.asarray(model)) self.lamp_shader.set_vec3('objectColor', get_color('teal')) model = glm.mat4(1.0) self.lamp_shader.set_vec3('objectColor', np.ones((3, 1), 'float32')) self.lamp_shader.set_mat4('model', np.asarray(model))
def render2(self): glClearColor(0.2, 0.3, 0.3, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_DEPTH_TEST) glEnable(GL_MULTISAMPLE) # glEnable(GL_BLEND) # glEnable(GL_CULL_FACE) # glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.flat_shader.use() model = glm.mat4(1.0) self.flat_shader.set_mat4('model', np.asarray(model)) view = glm.mat4(1.0) self.flat_shader.set_mat4('view', np.asarray(view)) aspect_ratio = 800. / 600. d = 10 ortho = glm.ortho(-d * aspect_ratio, d * aspect_ratio, -d, d, -100.0, 100.0) # ortho = glm.ortho(-2*aspect_ratio, 2*aspect_ratio, -2, 2, -100.0, 100.0) self.flat_shader.set_mat4('projection', np.asarray(ortho)) self.flat_shader.set_vec3('offset', np.zeros((3, 1), 'float32')) self.flat_shader.set_float('scale', 1.0) self.flat_shader.set_vec3('objectColor', np.ones((3, 1), 'float32')) # self.draw_grid(5, 0.25) # Draw obstacles. self.flat_shader.set_vec3('objectColor', get_color('gray')) self.collision_manager.draw(self.flat_shader.id, True, False) if self.step_on: # Draw object. new_m = point_manipulator() if self.counter >= len(self.path): self.counter = 0 self.config = self.path[self.counter] self.manip_p = self.mnp_path[self.counter] if self.manip_p is not None: for mnp in self.manip_p: p = mnp.p p = p[0:2] new_m.update_config(np.array(p),self.config) self.flat_shader.set_vec3('objectColor', get_color('red')) new_m.obj.draw2d(self.flat_shader.id, True) self.flat_shader.set_vec3('objectColor', get_color('clay')) T2 = config2trans(np.array(self.config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True) # print(self.counter, len(self.path)) time.sleep(0.07) self.counter += 1 if self.visualize: # Draw object. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) for i in range(len(self.key_path)): new_m = point_manipulator() self.config = self.key_path[i] self.manip_p = self.key_mnp_path[i] glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) if self.manip_p is not None: for mnp in self.manip_p: p = mnp.p p = p[0:2] new_m.update_config(np.array(p), self.config) self.flat_shader.set_vec3('objectColor', get_color('red')) new_m.obj.draw2d(self.flat_shader.id, True) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.flat_shader.set_vec3('objectColor', get_color('clay')) T2 = config2trans(np.array(self.config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) i=1 while i < len(self.path): self.flat_shader.set_vec3('objectColor', get_color('clay')) target_config = self.path[i] T2 = config2trans(np.array(target_config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True) i+=2 if self.path_on: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) for i in range(len(self.path)): if i % 5 != 0 and i != len(self.path) - 1: continue self.flat_shader.set_vec3('objectColor', get_color('clay')) target_config = self.path[i] T2 = config2trans(np.array(target_config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True) if self.all_configs_on: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # show all nodes for node in self.nodes: self.flat_shader.set_vec3('objectColor', get_color('clay')) target_config = np.array(node) T2 = config2trans(target_config) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True)
def render2(self): glClearColor(0.2, 0.3, 0.3, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_DEPTH_TEST) glEnable(GL_MULTISAMPLE) # glEnable(GL_BLEND) # glEnable(GL_CULL_FACE) # glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) self.flat_shader.use() model = glm.mat4(1.0) self.flat_shader.set_mat4('model', np.asarray(model)) view = glm.mat4(1.0) self.flat_shader.set_mat4('view', np.asarray(view)) aspect_ratio = 800. / 600. d = 10 ortho = glm.ortho(-d * aspect_ratio, d * aspect_ratio, -d, d, -100.0, 100.0) # ortho = glm.ortho(-2*aspect_ratio, 2*aspect_ratio, -2, 2, -100.0, 100.0) self.flat_shader.set_mat4('projection', np.asarray(ortho)) self.flat_shader.set_vec3('offset', np.zeros((3, 1), 'float32')) self.flat_shader.set_float('scale', 1.0) self.flat_shader.set_vec3('objectColor', np.ones((3, 1), 'float32')) # self.draw_grid(5, 0.25) # Draw obstacles. self.flat_shader.set_vec3('objectColor', get_color('gray')) self.collision_manager.draw(self.flat_shader.id, True, False) if self.example == 'inhand': # self.flat_shader.set_vec3('objectColor', get_color('green')) # config = self.x_start # T2 = config2trans(np.array(config)) # T3 = np.identity(4) # T3[0:2, 3] = T2[0:2, 2] # T3[0:2, 0:2] = T2[0:2, 0:2] # self.targets[0].transform()[:, :] = np.dot(T3, self.T0) # self.targets[0].draw2d(self.flat_shader.id, True) # self.targets[1].transform()[:, :] = np.dot(T3, self.T1) # self.targets[1].draw2d(self.flat_shader.id, True) self.flat_shader.set_vec3('objectColor', get_color('red')) config = self.x_goal T2 = config2trans(np.array(config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.targets[0].transform()[:, :] = np.dot(T3, self.T0) self.targets[0].draw2d(self.flat_shader.id, True) self.targets[1].transform()[:, :] = np.dot(T3, self.T1) self.targets[1].draw2d(self.flat_shader.id, True) else: self.flat_shader.set_vec3('objectColor', get_color('green')) target_config = self.x_start T2 = config2trans(np.array(target_config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True) self.flat_shader.set_vec3('objectColor', get_color('red')) target_config = self.x_goal T2 = config2trans(np.array(target_config)) T3 = np.identity(4) T3[0:2, 3] = T2[0:2, 2] T3[0:2, 0:2] = T2[0:2, 0:2] self.target.transform()[:, :] = T3 self.target.draw2d(self.flat_shader.id, True)