def draw_scene(self, shader): # ---------------------------------------------------------------------- # 1. Setup shader uniforms # ---------------------------------------------------------------------- shader.use() # model view projection model = glm.mat4(1.0) shader.set_mat4('model', np.asarray(model)) view = self.camera.get_view() shader.set_mat4('view', np.asarray(view)) ortho = self.camera.get_projection() shader.set_mat4('projection', np.asarray(ortho)) # lighting lightPos = np.array(self.light_pos) shader.set_vec3('lightPos', lightPos) shader.set_vec3('lightColor', np.array([1.0, 1.0, 1.0], 'f')) cameraPos = glm.vec3(glm.column(glm.inverse(view), 3)) shader.set_vec3('viewPos', np.asarray(cameraPos)) # ---------------------------------------------------------------------- # 2. Draw scene # ---------------------------------------------------------------------- glLineWidth(2) self.system.draw(shader) self.system.collider.draw(shader) self.draw_grid(shader)
def move(self): # x_increase = math.cos(math.radians(self.camera.x_angle + 90)) * self.speed # z_increase = math.sin(math.radians(self.camera.x_angle + 90)) * self.speed pre_pos = glm.vec3(glm.column(glm.translate(glm.mat4(self.model.matrix4), glm.vec3(0, 0, 5)), 3)) if pre_pos[0] <= 0.49 and pre_pos[0] >= -0.49 \ and pre_pos[1] <= 0.49 and pre_pos[1] >= 0 \ and pre_pos[2] <= 0.49 and pre_pos[2] >= -0.49: self.model.translate(0, 0, 5)
def getLocalXYZFromAngles(self, angles, len1, len2, joint2Offs): #state_start = time.time() resultTm = glm.mat4x4() resultTm = glm.rotate(resultTm, angles[0], glm.vec3([1.0, 0.0, 0.0])) resultTm = glm.translate(resultTm, joint2Offs) resultTm = glm.rotate(resultTm, angles[1], glm.vec3([0.0, 1.0, 0.0])) resultTm = glm.translate(resultTm, len1) resultTm = glm.rotate(resultTm, angles[2], glm.vec3([0.0, 1.0, 0.0])) resultTm = glm.translate(resultTm, len2) point = glm.vec3(glm.column(resultTm, 3)) #print("tm",(time.time()-state_start)*1000.0) return point '''
def draw_scene(self, shader): # ---------------------------------------------------------------------- # 1. Setup shader uniforms # ---------------------------------------------------------------------- shader.use() # model view projection model = glm.mat4(1.0) shader.set_mat4('model', np.asarray(model)) view = self.camera.get_view() shader.set_mat4('view', np.asarray(view)) width = self.window.width height = self.window.height projection = glm.perspective(glm.radians(50.0), width/height, 0.1, 100.0) shader.set_mat4('projection', np.asarray(projection)) # lighting lightPos = np.array(self.light_pos) shader.set_vec3('lightPos', lightPos) shader.set_vec3('lightColor', np.array([1.0, 1.0, 1.0], 'f')) cameraPos = glm.vec3(glm.column(glm.inverse(view), 3)) shader.set_vec3('viewPos', np.asarray(cameraPos)) # ---------------------------------------------------------------------- # 2. Draw scene # ---------------------------------------------------------------------- self.system.draw(shader) # self.hand.draw(shader) # self.baton.draw(shader) if self.show_grid: self.grid.draw(shader) if self.show_contact_frames or self.show_contacts or self.show_velocities: self.draw_contact_frames(shader)
def pos(self, new_pos): self.__matrix = glm.column(self.__matrix, 3, glm.vec4(*new_pos, 1.0))
def pos(self): return glm.vec3(glm.column(self.__matrix, 3))
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))