def test_glsl_mat4(gsg): param1 = core.LMatrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) param2 = core.NodePath("param2") param2.set_mat(core.LMatrix4( 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)) preamble = """ uniform mat4 param1; uniform mat4 param2; """ code = """ assert(param1[0] == vec4(1, 2, 3, 4)); assert(param1[1] == vec4(5, 6, 7, 8)); assert(param1[2] == vec4(9, 10, 11, 12)); assert(param1[3] == vec4(13, 14, 15, 16)); assert(param2[0] == vec4(17, 18, 19, 20)); assert(param2[1] == vec4(21, 22, 23, 24)); assert(param2[2] == vec4(25, 26, 27, 28)); assert(param2[3] == vec4(29, 30, 31, 32)); """ run_glsl_test(gsg, code, preamble, {'param1': param1, 'param2': param2})
def toggle_debug_cam(self): if not self.debug_cam: mat = p3d.LMatrix4(base.camera.get_mat()) mat.invert_in_place() base.mouseInterfaceNode.set_mat(mat) base.enableMouse() self.debug_cam = True else: base.disableMouse() self.reset_camera() self.debug_cam = False
def update_character(self, task): dt = task.time - self.last_update_char_time self._update_character(task.time, dt) self.character.setPos(self.char_pos) self.set_joint_global_xforms([ core.LMatrix4(*m) for m in self.joint_global_xforms.reshape(31, 16) ]) self.last_update_char_time = task.time return Task.cont
def render_frame(self, context): window = context.window region = context.region view = context.region_data # Calculate dimensions of the display region. pixel_scale = p3d.LVecBase2(1.0 / window.width, 1.0 / window.height) dimensions = p3d.LVecBase4(region.x, region.x + region.width, region.y, region.y + region.height) dimensions.x *= pixel_scale.x dimensions.y *= pixel_scale.x dimensions.z *= pixel_scale.y dimensions.w *= pixel_scale.y self.view_region.set_dimensions(dimensions) # Save GL State glPushAttrib(GL_ALL_ATTRIB_BITS) glPushClientAttrib(~0) glMatrixMode(GL_MODELVIEW) glPushMatrix() glMatrixMode(GL_PROJECTION) glPushMatrix() try: # update window wp = p3d.WindowProperties() wp.set_origin(window.x, window.y) wp.set_size(window.width, window.height) self.win.request_properties(wp) self.engine.open_windows() # update camera proj_mat = p3d.LMatrix4() for i, v in enumerate(view.perspective_matrix): proj_mat.set_col(i, p3d.LVecBase4(*v)) self.view_lens.set_user_mat(proj_mat) self.view_lens.set_view_mat(p3d.LMatrix4.ident_mat()) #draw self.fix_gl_state() self.engine.render_frame() finally: # Restore GL State glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() glPopClientAttrib() glPopAttrib()
def set_joint_global_xforms(self, global_xforms): # Invert global transforms inverse_global_xforms = [None] * NUM_JOINTS for i in PARENT_JOINTS: inverse_global_xforms[i] = core.LMatrix4() inverse_global_xforms[i].invertAffineFrom(global_xforms[i]) # Use each joint's global xform and the inverse of its parent's global xform to # compute and apply its local xform self.joints[0].setMat(global_xforms[0]) for i in range(1, NUM_JOINTS): local_xform = global_xforms[i] * inverse_global_xforms[ JOINT_PARENTS[i]] self.joints[i].setMat(local_xform)
def test_glsl_mat3(gsg): param1 = core.LMatrix4(core.LMatrix3(1, 2, 3, 4, 5, 6, 7, 8, 9)) param2 = core.NodePath("param2") param2.set_mat(core.LMatrix3(10, 11, 12, 13, 14, 15, 16, 17, 18)) preamble = """ uniform mat3 param1; uniform mat3 param2; """ code = """ assert(param1[0] == vec3(1, 2, 3)); assert(param1[1] == vec3(4, 5, 6)); assert(param1[2] == vec3(7, 8, 9)); assert(param2[0] == vec3(10, 11, 12)); assert(param2[1] == vec3(13, 14, 15)); assert(param2[2] == vec3(16, 17, 18)); """ run_glsl_test(gsg, code, preamble, {'param1': param1, 'param2': param2})
def load_matrix(self, mat): lmat = p3d.LMatrix4() for i in range(4): lmat.set_row(i, p3d.LVecBase4(*mat[i * 4: i * 4 + 4])) return lmat