def draw(self): pushMatrix() translate(-self.bounds['x'].delta()/2.0, -self.bounds['y'].delta()/2.0, -self.bounds['z'].delta()/2.0) cube(self.bounds['x'].delta(), self.bounds['y'].delta(), self.bounds['z'].delta()) popMatrix()
def draw(self): for obj in self.tracked_objects: if hasattr(obj, 'active'): color(red) else: color(0.25) pushMatrix() translate(obj.origin) obj.region.draw() popMatrix()
def image_synthesis(objects, observer): tr = rotate(translate(matrix(1), observer.p[:3]), (0, 0, 0), observer[1:]) objects = [obj.transform(tr) for obj in objects] for ob in objects: print(ob.points) return [ obj.polygons for obj in objects if all([all([p.x > d, -Ex <= p.z <= Ex, -Ey <= p.y <= Ey]) for p in obj.points]) ]
def __make_vertex(self): r1, r2, h, n = self.r1, self.r2, self.h, self.n #vertex: v = tr.circle(r1, n) v += [tr.translate(i, [0, 0, h]) for i in tr.circle(r2, n)] v += [[0, 0, 0]] v += [[0, 0, h]] self.v = v
def test_stripes_with_both_an_object_and_a_pattern_transformation(self): black = Color(0, 0, 0) white = Color(1, 1, 1) s = Sphere() s.set_transform(scale(2, 2, 2)) p = StripePattern(white, black) p.set_pattern_transform(translate(0.5, 0, 0)) c = p.pattern_at_shape(s, Point(2.5, 0, 0)) self.assertTrue(c.equals(white))
def robot_arm(): # construct our robot arm hierarchy for drawing in viewer cylinder = Cylinder() # re-use same cylinder instance limb_shape = Node(transform=scale(0.1, 0.5, 0.1), name='limb shape') # make a thin cylinder limb_shape.add(cylinder) # common shape of arm and forearm forearm_node = Node(transform=translate(0, 0.5, 0), name='forearm node') forearm_node.add(limb_shape) rot_forearm_node = RotationControlNode(glfw.KEY_LEFT, glfw.KEY_RIGHT, (1, 0, 0), transform=rotate((1, 0, 0), 45), children=[forearm_node], name='rot forearm node') move_forearm_node = Node(transform=translate(0, 1, 0), children=[rot_forearm_node], name='move forearm node') # robot arm rotation with phi angle arm_node = Node(transform=translate(0, .5, 0), name='arm node') arm_node.add(limb_shape) rot_arm_node = RotationControlNode(glfw.KEY_UP, glfw.KEY_DOWN, (1, 0, 0), children=[arm_node, move_forearm_node], name='rot arm node') move_arm_node = Node(children=[rot_arm_node], name='move arm node') base_shape_size = Node(transform=scale(.5, .1, .5), children=[cylinder], name='base shape size') base_shape_rot = RotationControlNode( glfw.KEY_P, glfw.KEY_O, (0, 1, 0), transform=rotate((0, 0, 1), 0), children=[base_shape_size, move_arm_node], name='base rotation') root_node = Node(children=[base_shape_rot], name='base shape') return root_node
def value(self, time): """ Compute each component's interpolation and compose TRS matrix """ tlerp = self._linterp(time, self.ttimes, self.trans) slerp = self._linterp(time, self.stimes, self.scale) rlerp = self._qinterp(time) rmat = quaternion_matrix(rlerp) tmat = translate(*tlerp) smat = scale(slerp) transformation = tmat @ rmat @ smat return transformation
def main(): """ create a window, add scene objects, then run rendering loop """ viewer = Viewer() # default color shader shader = Shader("color.vert", "color.frag") # ---- let's make our shapes --------------------------------------- # think about it: we can re-use the same cylinder instance! cylinder = Cylinder(shader) # make a flat cylinder base_shape = Node(transform=scale(1, 0.75, 1)) base_shape.add(cylinder) # shape of robot base # make a thin cylinder arm_shape = Node(transform=translate(0, 1.5, 0) @ scale(0.5, 1.5, 0.5)) arm_shape.add(cylinder) # shape of arm # make a thin cylinder forearm_shape = Node(transform=translate(0, 1, 0) @ scale(0.5, 1, 0.5)) forearm_shape.add(cylinder) # shape of forearm # ---- construct our robot arm hierarchy --------------------------- theta = 45.0 # base horizontal rotation angle phi1 = 20.0 # arm angle phi2 = 80.0 # forearm angle transform_forearm = Node( transform=translate(0, 3, 0) @ rotate((0, 0, 1), phi2)) transform_forearm.add(forearm_shape) transform_arm = Node( transform=translate(0, 0.75, 0) @ rotate((0, 0, 1), phi1)) transform_arm.add(arm_shape, transform_forearm) transform_base = Node(transform=rotate((0, 1, 0), theta)) transform_base.add(base_shape, transform_arm) viewer.add(transform_base) # start rendering loop viewer.run()
def test_maximum_recursive_depth(self): w = World() shape = Plane() shape.material.reflective = 0.5 shape.set_transform(translate(0, -1, 0)) r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2)/2, sqrt(2)/2)) i = Intersection(sqrt(2), shape) comps = i.prepare_computations(r) color = w.reflected_color(comps, 0) self.assertTrue(Color(0, 0, 0).equals(color))
def main(): """ create a window, add scene objects, then run rendering loop """ viewer = Viewer() # default color shader shader = Shader("color.vert", "color.frag") # think about it: we can re-use the same cylinder instance! cylinder = Cylinder(shader) # make a flat cylinder base_shape = Node(transform=scale(1, 0.7, 1)) base_shape.add(cylinder) # shape of robot base # make a thin cylinder arm_shape = Node(transform=translate(0, 3, 0) @ scale(0.1, 2.4, 0.1)) arm_shape.add(cylinder) # shape of arm # make a thin cylinder forearm_shape = Node(transform=translate(0, 7, 0) @ scale(0.1, 1.8, 0.1)) forearm_shape.add(cylinder) # shape of forearm theta = 45.0 # base horizontal rotation angle phi1 = 45.0 # arm angle phi2 = 20.0 # forearm angle transform_forearm = Node(transform=rotate((0.6, 0.5, 1), phi2)) transform_forearm.add(forearm_shape) transform_arm = Node(transform=rotate((0.3, 0.1, 0.9), phi1)) transform_arm.add(arm_shape, transform_forearm) transform_base = Node(transform=rotate((0.9, 0.1, 0.2), theta)) transform_base.add(base_shape, transform_arm) viewer.add(transform_base) # place instances of our basic objects # viewer.add(*[mesh for file in sys.argv[1:] for mesh in load(file, shader)]) # if len(sys.argv) < 2: # print('Usage:\n\t%s [3dfile]*\n\n3dfile\t\t the filename of a model in' # ' format supported by assimp.' % (sys.argv[0],)) # start rendering loop viewer.run()
def main(): """ create a window, add scene objects, then run rendering loop """ viewer = Viewer() cylinder = Cylinder() # base base_shape = Node(transform=scale(1, 0.25, 1)) base_shape.add(cylinder) # arm arm_shape = Node(transform=(translate(0, 1, 0) @ scale(0.5, 1, 0.5))) arm_shape.add(cylinder) # forearm forearm_shape = Node(transform=(translate(0, 1, 0) @ scale(0.25, 1, 0.25))) forearm_shape.add(cylinder) # ---- construct our robot arm hierarchy --------------------------- theta = 0 # base horizontal rotation angle phi1 = 0 # arm angle phi2 = 45 # forearm angle transform_forearm = Node( transform=translate(0, 2, 0) @ rotate((1, 0, 0), phi2)) transform_forearm.add(forearm_shape) transform_arm = Node(transform=rotate((1, 1, 0), phi1)) transform_arm.add(arm_shape, transform_forearm) transform_base = Node(transform=rotate((1, 1, 0), theta)) transform_base.add(base_shape, transform_arm) viewer.add(transform_base) # place instances of our basic objects # viewer.add(*[mesh for file in sys.argv[1:] for mesh in load(file)]) if len(sys.argv) < 2: print('Usage:\n\t%s [3dfile]*\n\n3dfile\t\t the filename of a model in' ' format supported by pyassimp.' % (sys.argv[0], )) # start rendering loop viewer.run()
def main(): """ create a window, add scene objects, then run rendering loop """ viewer = Viewer() # cylinder_node = Node(name='my_cylinder', transform=translate(-1, 0, 0), color=(1, 0, 0.5, 1)) # cylinder_node.add(Cylinder()) # viewer.add(cylinder_node) # place instances of our basic objects # viewer.add(*[mesh for file in sys.argv[1:] for mesh in load(file)]) # construct our robot arm hierarchy for drawing in viewer cylinder = Cylinder() # re-use same cylinder instance limb_shape = Node(transform=(scale(0.2, 2, 0.2))) # make a thin cylinder forearm_node = Node( transform=rotate(axis=vec(0, 0, 1), angle=45) @ translate( 0, 0, 0)) # robot arm rotation with phi angle forearm_node.add(limb_shape) # limb_shape = Node(transform=(scale(0.2, 2, 0.2))) # make a thin cylinder limb_shape.add(cylinder) # common shape of arm and forearm arm_node = Node(transform=rotate(axis=vec(0, 0, 1), angle=45) @ translate( 0, 0, 0)) # robot arm rotation with phi angle arm_node.add(limb_shape, forearm_node) # make a flat cylinder base_shape = Node(transform=scale(1, 0.5, 1), children=[cylinder]) base_node = Node(transform=rotate(axis=vec( 0, 1, 0), angle=45)) # robot base rotation with theta angle base_node.add(base_shape, arm_node) viewer.add(base_node) # if len(sys.argv) < 2: # print('Usage:\n\t%s [3dfile]*\n\n3dfile\t\t the filename of a model in' # ' format supported by pyassimp.' % (sys.argv[0],)) # start rendering loop viewer.run()
def test_shade_hit(self): w = World() shape = Plane() shape.material.reflective = 0.5 shape.set_transform(translate(0.0, -1.0, 0.0)) w.objs.append(shape) r = Ray(Point(0.0, 0.0, -3.0), Vector(0.0, -sqrt(2)/2, sqrt(2)/2)) i = Intersection(sqrt(2), shape) comps = i.prepare_computations(r) color = w.shade_hit(comps) self.assertTrue(Color(0.87677, 0.92436, 0.82918).equals(color))
def setparams(self, params): for key in params: if key in ("name", "init_p"): exec "self.%s = params[key]" % (key,) continue if key == "mat": self.mat = mat(params[key]) continue exec """for i in range(len(self.%s)): if params[key][i] == None: continue if params[key][i] < 0: raise NegativeException("Parameters can't be negative") self.%s[i] = params[key][i]""" % ( key, key, ) if self.cylM[1] > self.cylN[0]: raise BadRadiusException("Radius cyl M must be less then radius cyl N") if self.cylD[0] > self.cylF[0]: raise BadRadiusException("Radius cyl D must be less then radius cyl F") if self.cylF[0] > self.cylH[0]: raise BadRadiusException("Radius cyl F must be less then radius cyl H") if self.mat == mat(1): self.mat = tr.translate(self.mat, self.init_p) self.namesofshapes = ( "cylA", "coneB", "coneC", "cylD", "cylE", "cylF", "cylG", "cylH", "coneI", "cylJ", "coneK", "cylL", "cylM", "cylN", ) self.c = self.init_p[:] # calculating base point (for rotation, scaling, etc.) for j in [getattr(self, i)[2] for i in self.namesofshapes]: self.c[2] += j / 2.0 tmp_init_p = [0, 0, 0] for name in self.namesofshapes: sh = getattr(self, name)[:] maxr = sqrt((tmp_init_p[2] - self.c[2]) ** 2 + (sh[0] > sh[1] and sh[0] or sh[1]) ** 2) # may cause bug self.max_radius = maxr > self.max_radius and maxr or self.max_radius # may cause bug self.shapes[name] = Cone(tmp_init_p[:], getattr(self, name)) tmp_init_p[2] += getattr(self, name)[2]
def draw(self, projection, view, model, win=None, **param): assert win is not None self.angle += 0.1 * int(glfw.get_key(win, self.key_up) == glfw.PRESS) self.angle -= 0.1 * int(glfw.get_key(win, self.key_down) == glfw.PRESS) # self.transform = rotate( # axis=self.axis, angle=self.angle) @ self.transform_backup self.transform = translate(x=0.0, y=0.0, z=self.z) @ self.transform_backup # call Node's draw method to pursue the hierarchical tree calling super().draw(projection, view, model, win=win, **param)
def test_under_point1(self): r = Ray(Point(0, 0, -5), Vector(0, 0, 1)) shape = GlassSphere() shape.set_transform(translate(0, 0, 1)) i = Intersection(5, shape) xs = Intersections([i]) comps = i.prepare_computations(r, xs) # print(comps.normalv) # print(comps.point) # print(comps.under_point.z) self.assertTrue(comps.under_point.z > EPSILON / 2) self.assertTrue(comps.point.z < comps.under_point.z)
def key_handler(self, key): self.angle += 0.5 * int(key == self.key_left) self.angle -= 0.5 * int(key == self.key_right) self.x += 1 * (key == self.key_fwd) self.x -= 1 * (key == self.key_bwd) self.z += 1 * (key == self.key_up) self.z -= 1 * (key == self.key_down) self.is_follow = not self.is_follow * (key == self.key_f) # self.transform = self.transform = translate(0, self.z, self.x) @ rotate( self.axis, self.angle) super().key_handler(key)
def __draw(self): """Applies all changes then make and return polygons""" v = self.v v = [tr.translate(i, self.init_p) for i in v] if self.ox_angle: v = [tr.rotate_ox(i, self.rotate_point, self.ox_angle) for i in v] if self.oy_angle: v = [tr.rotate_oy(i, self.rotate_point, self.oy_angle) for i in v] if self.oz_angle: v = [tr.rotate_oz(i, self.rotate_point, self.oz_angle) for i in v] v = [tr.scale(i, self.scale_point, self.sx, self.sy, self.sz) for i in v] self.__make_polygons(v)
def add_ufo_ship(): ufo_mesh = PhongMesh('resources/ufo/ufo.obj') ufo_base = Node(transform=translate(x=-0.6, y=0, z=0) @ scale(x=0.04)) ufo_base.add(ufo_mesh) translate_keys = { 0: vec(-8, 0.8, -10), 1: vec(-7, 0.7, -9), 2: vec(-6, 0.6, -8), 3: vec(-5, 0.5, -7), 4: vec(-4, 0.45, -6), 5: vec(-3, 0.38, -5), 6: vec(-2, 0.35, -4), 7: vec(-1, 0.25, -3), 8: vec(-0.3, 0.15, -2.5), 9: vec(-0.1, -0.1, -1), 10: vec(0.03, -0.25, -0.5), 11: vec(0.09, -0.44, 0.1) } rotate_keys = { 0: quaternion_from_euler(0, 0, 20), 1: quaternion_from_euler(0, 0, 20), 2: quaternion_from_euler(0, 0, 25), 3: quaternion_from_euler(0, 0, 28), 4: quaternion_from_euler(0, 0, 33), 5: quaternion_from_euler(0, 0, 35), 6: quaternion_from_euler(0, 0, 37), 7: quaternion_from_euler(0, 0, 30), 8: quaternion_from_euler(0, 0, 20), 9: quaternion_from_euler(0, 0, 15), 10: quaternion_from_euler(0, 0, 25), 11: quaternion_from_euler(0, 0, 10) } scale_keys = { 0: 0.2, 1: 0.25, 2: 0.3, 3: 0.3, 4: 0.3, 5: 0.3, 6: 0.3, 7: 0.3, 8: 0.3, 9: 0.3, 10: 0.3, 11: 0.3 } keynode = KeyFrameControlNode(translate_keys, rotate_keys, scale_keys) keynode.add(ufo_base) return keynode
def test_reflect1(self): w = World() shape = Plane() shape.material.reflective = 0.5 shape.set_transform(translate(0.0, -1.0, 0.0)) w.objs.append(shape) r = Ray(Point(0.0, 0.0, -3.0), Vector(0.0, -sqrt(2)/2, sqrt(2)/2)) i = Intersection(sqrt(2), shape) comps = i.prepare_computations(r) color = w.reflected_color(comps) # print(color) self.assertTrue(Color(0.19032, 0.2379, 0.14274).equals(color))
def __init__(self, name='', transform=None, children=(), \ translation_matrix=translate(), scale_matrix=scale(1), rotation_quaternion=quaternion(), axe=False, height_ground=0, \ **param): # Set all the arguments self.transform, self.param, self.name, \ self.translation_matrix, self.scale_matrix, self.rotation_quaternion = \ transform, param, name, translation_matrix, scale_matrix, rotation_quaternion self.children = defaultdict(list) self.height_ground = height_ground self.add(*children) if (axe): self.add(Axis()) # Fait bugger le skinning
def update(self, delta): if self.life > 0 and self.life <= self.total_life: self.life -= delta life_ratio = self.life / self.total_life # life_ratio goes from 1 to 0 self.color = (1, life_ratio, 0, 1) self.model = scale(0.5 + 0.5 * life_ratio) @ translate( self.x_offset + self.width * life_ratio * sin(self.height * life_ratio), self.height * (1 - life_ratio), self.z_offset + self.width * life_ratio * sin(self.height * life_ratio)) else: self.life = self.total_life
def test_shadow5(self): w = World() light = Light(Point(0, 0, -10), Color(1, 1, 1)) w.light = light s1 = Sphere() s2 = Sphere() s2.transform = translate(0, 0, 10) w.objs = [s1, s2] r = Ray(Point(0, 0, 5), Vector(0, 0, 1)) i = Intersection(4, s2) comps = i.prepare_computations(r) c = w.shade_hit(comps) self.assertTrue(Color(0.1, 0.1, 0.1).equals(c))
def draw(self, projection, view, model, color_shader, **param): names = ['view', 'projection', 'model'] loc = {n: GL.glGetUniformLocation(color_shader.glid, n) for n in names} GL.glUseProgram(color_shader.glid) translation_matrix = translate(x=1.5, y=0.0, z=1.5) GL.glUniformMatrix4fv(loc['view'], 1, True, view) GL.glUniformMatrix4fv(loc['projection'], 1, True, projection) GL.glUniformMatrix4fv(loc['model'], 1, True, model) self.vertex_array.execute(GL.GL_TRIANGLES)
def transform(root, filename): if not os.path.exists('./ply_gen'): os.makedirs('./ply_gen') # Example transformation. # 1. Read the PLY data file. data = read_ply(os.path.join(root, filename)) # 2. Shift points by the vector (25, -10, 7). data = translate(data, 25, -10, 7) # 3. Rotate points 45 degress around the Z-axis. data = rotate_z(data, 45) # 4. Write the new points into a new PLY data file. write_ply(os.path.join('./ply_gen', filename), [data['x'], data['y'], data['z'], data['x_origin'], data['y_origin'], data['z_origin'], data['GPS_time'], data['reflectance']], ['x', 'y', 'z', 'x_origin', 'y_origin', 'z_origin', 'GPS_time', 'reflectance'])
def test_shade_hit_with_reflective_transparent_material(self): w = World() r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2)/2, sqrt(2)/2)) floor = Plane() floor.set_transform(translate(0, -1, 0)) floor.material.reflective = 0.5 floor.material.transparency = 0.5 floor.material.refractive_index = 1.5 w.objs.append(floor) ball = Sphere() ball.material.color = Color(1, 0, 0) ball.material.ambient = 0.5 ball.set_transform(translate(0, -3.5, -0.5)) w.objs.append(ball) ls = [Intersection(sqrt(2), floor)] xs = Intersections(ls) comps = xs[0].prepare_computations(r, xs) color = w.shade_hit(comps, 5) # print(color) self.assertTrue(Color(0.93391, 0.69643, 0.69243) == color)
def test_shade_hit_with_transparent_material(self): w = World() floor = Plane() floor.set_transform(translate(0, -1, 0)) floor.material.transparency = 0.5 floor.material.refractive_index = 1.5 ball = Sphere() ball.material.color = Color(1., 0., 0.) ball.material.ambient = 0.5 ball.set_transform(translate(0, -3.5, -0.5)) w.objs = [floor, ball] r = Ray(Point(0, 0, -3), Vector(0, -sqrt(2)/2, sqrt(2)/2)) ls = [Intersection(sqrt(2), floor)] xs = Intersections(ls) comps = xs[0].prepare_computations(r, xs) color = w.shade_hit(comps, 5) self.assertTrue(Color(0.93642, 0.68642, 0.68642) == color)
def draw(self, projection, view, model, win=None, **param): assert win is not None self.z_pos -= 0.005 * int( glfw.get_key(win, self.key_forward) == glfw.PRESS) self.z_pos += 0.005 * int( glfw.get_key(win, self.key_backward) == glfw.PRESS) self.x_pos -= 0.005 * int( glfw.get_key(win, self.key_left) == glfw.PRESS) self.x_pos += 0.005 * int( glfw.get_key(win, self.key_right) == glfw.PRESS) self.transform = translate(x=self.x_pos, y=0, z=self.z_pos) super().draw(projection, view, model, win=win, **param)
def construct_houses(self, shader_1, shader_2, transform=identity()): big_houses = [] for j in range(0, 5, 2): if (j % 4 == 2): for i in range(0, 5, 2): big_houses.append( add_object(self.big_house, transform=transform @ translate( 100 * i, 100 * j, 0) @ rotate( (0, 0, 1), random() * 180))) elif (j % 4 == 0): for i in range(1, 4, 2): big_houses.append( add_object(self.big_house, transform=transform @ translate( 100 * i, 100 * j, 0) @ rotate( (0, 0, 1), random() * 90))) else: pass #self.children.extend([add_object(self.trees['autumn_tree'], shader_2, transform=transform@translate(100*3, 100*1, 0)@scale(50))]) self.children.extend(big_houses)
def draw(self, projection, view, model, color_shader, color, scaler, rotater): GL.glUseProgram(color_shader.glid) my_color_location = GL.glGetUniformLocation(color_shader.glid, 'color') # hard coded color : (0.6, 0.6, 0.9) GL.glUniform3fv(my_color_location, 1, color) matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') GL.glUniformMatrix4fv( matrix_location, 1, True, perspective(35, 640 / 480, 0.001, 100) @ translate(0, 0, -1) @ rotate(vec(0, 1, 0), rotater) @ scale(scaler)) # draw triangle as GL_TRIANGLE vertex array, draw array call GL.glBindVertexArray(self.glid) GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) GL.glBindVertexArray(0)
def input_symbol_key(self): self.entry_text_sys_ent.delete(0, tk.END) self.crypt_key_sys_ent.delete(0, tk.END) self.crypt_key_ctrl_bit_sys_ent.delete(0, tk.END) if len(self.crypt_key_ent.get()) == 7: temp = translate(self.crypt_key_ent.get(), 's', 'b') temp = temp[:56] temp_1 = self.ctrlBit(temp) t_out = '' for i in temp_1: t_out+=str(hex(int(i,2))[2:]).zfill(2) self.crypt_key_ctrl_bit_ent.delete(0, tk.END) self.crypt_key_ent.delete(7, tk.END) self.crypt_key_ctrl_bit_ent.insert(0, t_out) if 1 <= self.sys_of_not.get() <= 3: self.change()
def add_hierarchical_model(): # ----------SHAPES--------------- sphere_mesh = Shape('resources/sphere.obj') head_shape = Node( transform=translate(x=1, y=-0.2, z=0.03) @ scale(0.2, 0.18, 0.1)) head_shape.add(sphere_mesh) cylinder = Shape('resources/cylinder.obj') leg_shape1 = Node( transform=translate(x=1, y=-0.25, z=0.05) @ scale(0.01, 0.05, 0.01)) leg_shape1.add(cylinder) leg_shape2 = Node( transform=translate(x=0.92, y=-0.25, z=0.05) @ scale(0.01, 0.05, 0.01)) leg_shape2.add(cylinder) foot_shape1 = Node(transform=translate(x=0.92, y=0.025, z=0.291) @ scale( 0.009, 0.025, 0.01)) foot_shape1.add(cylinder) foot_shape2 = Node( transform=translate(x=1, y=0.025, z=0.291) @ scale(0.009, 0.025, 0.01)) foot_shape2.add(cylinder) # ------- Node Connections--------- transform_foot2 = Node(transform=rotate(axis=(1, 0, 0), angle=89)) transform_foot2.add(foot_shape2) transform_foot1 = Node(transform=rotate(axis=(1, 0, 0), angle=89)) transform_foot1.add(foot_shape1) transform_leg2 = Node(transform=translate(x=0, y=0, z=0)) transform_leg2.add(leg_shape2, transform_foot2) transform_leg1 = Node(transform=translate(x=0, y=0, z=0)) transform_leg1.add(leg_shape1, transform_foot1) transform_body = Node(transform=translate(x=-0.4, y=0, z=0.8)) transform_body.add(transform_leg1, transform_leg2, head_shape) trans_node = TranslationControlNode(glfw.KEY_W, glfw.KEY_S, glfw.KEY_A, glfw.KEY_D) trans_node.add(transform_body) return trans_node
def draw(self, projection, view, model, color_shader, color): GL.glUseProgram(color_shader.glid) # draw triangle as GL_TRIANGLE vertex array, draw array call GL.glBindVertexArray(self.glid) GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) GL.glBindVertexArray(0) # color as shader uniform (deactivated, not receiving this info in VS) my_color_location = GL.glGetUniformLocation(color_shader.glid, 'color') GL.glUniform3fv(my_color_location, 1, color) # projection transform projection_transform = frustum(-2, 2, -2, 2, -2, 2) # triangle transformation transformation = rotate(vec(1, 0, 0), 25) @ scale(0.7) @ translate(0.4, 0.7, 0) transformation = transformation @ projection_transform matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') GL.glUniformMatrix4fv(matrix_location, 1, True, transformation)
def input_hex_key(self): self.crypt_key_ctrl_bit_ent.delete(16, tk.END) self.entry_text_sys_ent.delete(0, tk.END) self.crypt_key_sys_ent.delete(0, tk.END) self.crypt_key_ctrl_bit_sys_ent.delete(0, tk.END) if len(self.crypt_key_ctrl_bit_ent.get()) == 16: t_out = self.ctrlBitReverse(self.crypt_key_ctrl_bit_ent.get()) if translate(t_out, 's', 'h') == '00000000000000': self.zero_value = 1 else: self.zero_value = 0 self.crypt_key_ent.delete(0, tk.END) self.crypt_key_ent.insert(0, t_out) self.crypt_key_ctrl_bit_ent.delete(16, tk.END) if 1 <= self.sys_of_not.get() <= 3: self.change()
def __init__(self, key_forward, key_backward, key_left, key_right, key_toggle, key_toggle2=glfw.KEY_Q, show=True, interact=False, time=1, speed=.5, **param): super().__init__(**param) # forward base constructor named arguments self.axis, self.angle = vec(0, 1, 0), 0 self.key_forward, self.key_backward, self.key_left, self.key_right, self.key_toggle, self.key_toggle2 = key_forward, key_backward, key_left, key_right, key_toggle, key_toggle2 self.transform = translate(0, 0, 0) self.speed = speed self.show = show self.time = time self.interact = interact self.first_time = True
def setparams(self, params): for key in params: if key in ('name', 'init_p'): exec 'self.%s = params[key]' % (key, ) continue if key == 'mat': self.mat = mat(params[key]) continue exec """for i in range(len(self.%s)): if params[key][i] == None: continue if params[key][i] < 0: raise NegativeException("Parameters can't be negative") self.%s[i] = params[key][i]""" % (key, key) if self.cylM[1] > self.cylN[0]: raise BadRadiusException( 'Radius cyl M must be less then radius cyl N') if self.cylD[0] > self.cylF[0]: raise BadRadiusException( 'Radius cyl D must be less then radius cyl F') if self.cylF[0] > self.cylH[0]: raise BadRadiusException( 'Radius cyl F must be less then radius cyl H') if self.mat == mat(1): self.mat = tr.translate(self.mat, self.init_p) self.namesofshapes = ('cylA', 'coneB', 'coneC', 'cylD', 'cylE', 'cylF', 'cylG', 'cylH', 'coneI', 'cylJ', 'coneK', 'cylL', 'cylM', 'cylN') self.c = self.init_p[:] #calculating base point (for rotation, scaling, etc.) for j in [getattr(self, i)[2] for i in self.namesofshapes]: self.c[2] += j / 2.0 tmp_init_p = [0, 0, 0] for name in self.namesofshapes: sh = getattr(self, name)[:] maxr = sqrt((tmp_init_p[2] - self.c[2])**2 + (sh[0] > sh[1] and sh[0] or sh[1])**2) #may cause bug self.max_radius = maxr > self.max_radius and maxr or self.max_radius #may cause bug self.shapes[name] = Cone(tmp_init_p[:], getattr(self, name)) tmp_init_p[2] += getattr(self, name)[2]
def __init__(self, **kwargs): self.pos = kwargs["pos"][:] self.dir_ = kwargs["dir_"][:] self.near_clip_z = kwargs["near_clip_z"] self.far_clip_z = kwargs["far_clip_z"] self.viewport_width = kwargs["viewport_width"] self.viewport_height = kwargs["viewport_height"] self.viewport_center_x = (self.viewport_width - 1) / 2 self.viewport_center_y = (self.viewport_height - 1) / 2 self.aspect_ratio = float(self.viewport_width) / float(self.viewport_height) if kwargs.has_key("mcam"): self.mcam = kwargs["mcam"] else: self.mcam = mat(1) self.fov = kwargs["fov"] self.viewplane_width = 2.0 self.viewplane_height = 2.0 / self.aspect_ratio self.view_dist = 0.5 * self.viewplane_width * tan(rad(self.fov / 2.0)) # init mcam: self.mcam = tr.translate(self.mcam, (-self.pos[0], -self.pos[1], -self.pos[2])) (mat_oz, mat_oy, mat_ox) = tr.camat(self.dir_) self.mcam = self.mcam * mat_oz self.mcam = self.mcam * mat_oy self.mcam = self.mcam * mat_ox
def move(self, vec): self.mat = tr.translate(self.mat, vec) self.c = [self.c[0] + vec[0], self.c[1] + vec[1], self.c[2] + vec[2]]
def router(routedict): ''' communication.run one route. variants: - a route can be just script; - a route can do only incoming - a route can do only outgoing - a route can do both incoming and outgoing - at several points functions from a route script are called - if function is in route script ''' #is there a user route script? try: userscript,scriptname = botslib.botsimport('routescripts',routedict['idroute']) except ImportError: #other errors, eg syntax errors are just passed userscript = scriptname = None #if user route script has function 'main': communication.run 'main' (and do nothing else) if botslib.tryrunscript(userscript,scriptname,'main',routedict=routedict): return #so: if function ' main' : communication.run only the routescript, nothing else. if not (userscript or routedict['fromchannel'] or routedict['tochannel'] or routedict['translateind']): raise botslib.ScriptError(_(u'Route "$route" is empty: no script, not enough parameters.'),route=routedict['idroute']) botslib.tryrunscript(userscript,scriptname,'start',routedict=routedict) #communication.run incoming channel if routedict['fromchannel']: #do incoming part of route: in-communication; set ready for translation; translate botslib.tryrunscript(userscript,scriptname,'preincommunication',routedict=routedict) communication.run(idchannel=routedict['fromchannel'],idroute=routedict['idroute']) #communication.run incommunication #add attributes from route to the received files where={'status':FILEIN,'fromchannel':routedict['fromchannel'],'idroute':routedict['idroute']} change={'editype':routedict['fromeditype'],'messagetype':routedict['frommessagetype'],'frompartner':routedict['frompartner'],'topartner':routedict['topartner'],'alt':routedict['alt']} botslib.updateinfo(change=change,where=where) #all received files have status FILEIN botslib.tryrunscript(userscript,scriptname,'postincommunication',routedict=routedict) if routedict['fromeditype'] == 'mailbag': #mailbag for the route. preprocess.preprocess(routedict,preprocess.mailbag) #communication.run translation if routedict['translateind']: botslib.tryrunscript(userscript,scriptname,'pretranslation',routedict=routedict) botslib.addinfo(change={'status':TRANSLATE},where={'status':FILEIN,'idroute':routedict['idroute']}) transform.translate(idroute=routedict['idroute']) botslib.tryrunscript(userscript,scriptname,'posttranslation',routedict=routedict) #merge messages & communication.run outgoing channel if routedict['tochannel']: #do outgoing part of route botslib.tryrunscript(userscript,scriptname,'premerge',routedict=routedict) envelope.mergemessages(idroute=routedict['idroute']) botslib.tryrunscript(userscript,scriptname,'postmerge',routedict=routedict) #communication.run outgoing channel #build for query: towhere (dict) and wherestring towhere=dict(status=MERGED, idroute=routedict['idroute'], editype=routedict['toeditype'], messagetype=routedict['tomessagetype'], testindicator=routedict['testindicator']) towhere=dict([(key, value) for (key, value) in towhere.iteritems() if value]) #remove nul-values from dict wherestring = ' AND '.join([key+'=%('+key+')s' for key in towhere]) if routedict['frompartner_tochannel_id']: #use frompartner_tochannel in where-clause of query (partner/group dependent outchannel towhere['frompartner_tochannel_id']=routedict['frompartner_tochannel_id'] wherestring += ''' AND (frompartner=%(frompartner_tochannel_id)s OR frompartner in (SELECT from_partner_id FROM partnergroup WHERE to_partner_id =%(frompartner_tochannel_id)s ))''' if routedict['topartner_tochannel_id']: #use topartner_tochannel in where-clause of query (partner/group dependent outchannel towhere['topartner_tochannel_id']=routedict['topartner_tochannel_id'] wherestring += ''' AND (topartner=%(topartner_tochannel_id)s OR topartner in (SELECT from_partner_id FROM partnergroup WHERE to_partner_id=%(topartner_tochannel_id)s ))''' toset={'tochannel':routedict['tochannel'],'status':FILEOUT} botslib.addinfocore(change=toset,where=towhere,wherestring=wherestring) if not routedict['defer']: #do outgoing part of route botslib.tryrunscript(userscript,scriptname,'preoutcommunication',routedict=routedict) communication.run(idchannel=routedict['tochannel'],idroute=routedict['idroute']) #communication.run outcommunication botslib.tryrunscript(userscript,scriptname,'postoutcommunication',routedict=routedict) botslib.tryrunscript(userscript,scriptname,'end',routedict=routedict)
def transform(self, m): v = [tr.translate(mat([i + [1]]), self.init_p).tolist()[0][:3] for i in self.v] v = [(mat([i + [1]]) * m).tolist()[0][:3] for i in v] self.__make_polygons(v)
def routepart(self,routedict): ''' communication.run one route part. variants: - a route can be a routescript - a route can do only incoming - a route can do only outgoing - a route can do both incoming and outgoing - at several points functions from a routescript are called - if function is in routescript ''' self.minta4query_routepart = botslib._Transaction.processlist[-1] #the idta of routepart #if routescript has function 'main': communication.run 'main' (and do nothing else) if botslib.tryrunscript(self.userscript,self.scriptname,'main',routedict=routedict): return #so: if function ' main' : communication.run only the routescript, nothing else. if not (self.userscript or routedict['fromchannel'] or routedict['tochannel'] or routedict['translateind']): raise botslib.ScriptError(_(u'Route "%(idroute)s" is empty: no routescript, not enough parameters.'),routedict) botslib.tryrunscript(self.userscript,self.scriptname,'start',routedict=routedict) #incoming part of route: #- incommunication #- assign attributes from route to incoming files #- preprocessing if routedict['fromchannel']: #only done for edi files from this route-part, this inchannel if routedict['command'] == 'rereceive': rootidta = self.get_minta4query() else: rootidta = self.get_minta4query_routepart() botslib.tryrunscript(self.userscript,self.scriptname,'preincommunication',routedict=routedict) communication.run(idchannel=routedict['fromchannel'],command=routedict['command'],idroute=routedict['idroute'],rootidta=rootidta) #communication.run incommunication #add attributes from route to the received files; where = {'statust':OK,'status':FILEIN,'fromchannel':routedict['fromchannel'],'idroute':routedict['idroute'],'rootidta':rootidta} change = {'editype':routedict['fromeditype'],'messagetype':routedict['frommessagetype'],'frompartner':routedict['frompartner'],'topartner':routedict['topartner'],'alt':routedict['alt']} nr_of_incoming_files_for_channel = botslib.updateinfo(change=change,where=where) botslib.tryrunscript(self.userscript,self.scriptname,'postincommunication',routedict=routedict) if nr_of_incoming_files_for_channel: #unzip incoming files (if indicated) if routedict['zip_incoming'] == 1: #unzip incoming (non-zipped gives error). preprocess.preprocess(routedict=routedict,function=preprocess.botsunzip,rootidta=self.get_minta4query_routepart(),pass_non_zip=False) elif routedict['zip_incoming'] == 2: #unzip incoming if zipped. preprocess.preprocess(routedict=routedict,function=preprocess.botsunzip,rootidta=self.get_minta4query_routepart(),pass_non_zip=True) #run mailbag-module. if botsglobal.ini.getboolean('settings','compatibility_mailbag',False): editypes_via_mailbag = ['mailbag'] else: editypes_via_mailbag = ['mailbag','edifact','x12','tradacoms'] if routedict['fromeditype'] in editypes_via_mailbag: #mailbag for the route. preprocess.preprocess(routedict=routedict,function=preprocess.mailbag,rootidta=self.get_minta4query_routepart(),frommessagetype=routedict['frommessagetype']) #translate, merge, pass through: INFILE->MERGED if int(routedict['translateind']) in [1,3]: #translate: for files in route botslib.tryrunscript(self.userscript,self.scriptname,'pretranslation',routedict=routedict) if routedict['command'] in ['rereceive',]: rootidta = self.get_minta4query() else: rootidta = self.get_minta4query_route() transform.translate(startstatus=FILEIN,endstatus=TRANSLATED,routedict=routedict,rootidta=rootidta) botslib.tryrunscript(self.userscript,self.scriptname,'posttranslation',routedict=routedict) #**merge: for files in this route-part (the translated files) botslib.tryrunscript(self.userscript,self.scriptname,'premerge',routedict=routedict) envelope.mergemessages(startstatus=TRANSLATED,endstatus=MERGED,idroute=routedict['idroute'],rootidta=self.get_minta4query_routepart()) botslib.tryrunscript(self.userscript,self.scriptname,'postmerge',routedict=routedict) elif routedict['translateind'] == 2: #pass-through: pickup the incoming files and mark these as MERGED (==translation is finished) botslib.addinfo(change={'status':MERGED,'statust':OK},where={'status':FILEIN,'statust':OK,'idroute':routedict['idroute'],'rootidta':self.get_minta4query_route()}) #NOTE: routedict['translateind'] == 0 than nothing will happen with the files in this route. #ommunication outgoing channel: MERGED->RAWOUT if routedict['tochannel']: #**build query to add outchannel as attribute to outgoing files*** #filter files in route for outchannel towhere = { 'status':MERGED, 'statust':OK, 'idroute':routedict['idroute'], 'editype':routedict['toeditype'], 'messagetype':routedict['tomessagetype'], 'testindicator':routedict['testindicator'], } towhere = dict((key, value) for key,value in towhere.iteritems() if value) #remove nul-values from dict wherestring = ' AND '.join([key+'=%('+key+')s ' for key in towhere]) if routedict['frompartner_tochannel_id']: #use frompartner_tochannel in where-clause of query (partner/group dependent outchannel towhere['frompartner_tochannel_id'] = routedict['frompartner_tochannel_id'] wherestring += ''' AND (frompartner=%(frompartner_tochannel_id)s OR frompartner in (SELECT from_partner_id FROM partnergroup WHERE to_partner_id=%(frompartner_tochannel_id)s )) ''' if routedict['topartner_tochannel_id']: #use topartner_tochannel in where-clause of query (partner/group dependent outchannel towhere['topartner_tochannel_id'] = routedict['topartner_tochannel_id'] wherestring += ''' AND (topartner=%(topartner_tochannel_id)s OR topartner in (SELECT from_partner_id FROM partnergroup WHERE to_partner_id=%(topartner_tochannel_id)s )) ''' toset = {'status':FILEOUT,'statust':OK,'tochannel':routedict['tochannel']} towhere['rootidta'] = self.get_minta4query_route() nr_of_outgoing_files_for_channel = botslib.addinfocore(change=toset,where=towhere,wherestring=wherestring) if nr_of_outgoing_files_for_channel: #**set asked confirmation/acknowledgements botslib.set_asked_confirmrules(routedict,rootidta=self.get_minta4query_routepart()) #**zip outgoing #for files in this route-part for this out-channel if routedict['zip_outgoing'] == 1: preprocess.postprocess(routedict=routedict,function=preprocess.botszip,rootidta=self.get_minta4query_routepart()) #actual communication: run outgoing channel (if not deferred) #for all files in run that are for this channel (including the deferred ones from other routes) if not routedict['defer']: #determine range of idta to query: if channel was not deferred earlier in run: query only for route part else query for whole run if self.keep_track_if_outchannel_deferred.get(routedict['tochannel'],False) or routedict['command'] in ['resend','automaticretrycommunication']: rootidta = self.get_minta4query() else: rootidta = self.get_minta4query_routepart() if botslib.countoutfiles(idchannel=routedict['tochannel'],rootidta=rootidta): botslib.tryrunscript(self.userscript,self.scriptname,'preoutcommunication',routedict=routedict) communication.run(idchannel=routedict['tochannel'],command=routedict['command'],idroute=routedict['idroute'],rootidta=rootidta) #in communication several things can go wrong. #all outgoing files should have same status; that way all recomnnunication can be handled the same: #- status EXTERNOUT statust DONE (if communication goes OK) #- status EXTERNOUT status ERROR (if file is not communicatied) #to have the same status for all outgoing files some manipulation is needed, eg in case no connection could be made. botslib.addinfo(change={'status':EXTERNOUT,'statust':ERROR},where={'status':FILEOUT,'statust':OK,'tochannel':routedict['tochannel'],'rootidta':rootidta}) botslib.tryrunscript(self.userscript,self.scriptname,'postoutcommunication',routedict=routedict) botslib.tryrunscript(self.userscript,self.scriptname,'end',routedict=routedict)