def __init__( self, scale=1.0, translation=None, rotation=None, ): self.things = [] self.subframes = [] if not isinstance(scale, scalar_types): raise TypeError, scale self.s = scale # Translation. if isinstance(translation, Vector): self.T = translation elif translation is not None: translation = tuple(translation) if not ( len(translation) == 3 and all(isinstance(t, scalar_types) for t in translation) ): raise TypeError, translation self.T = Vector(*translation) else: self.T = Vector() # Rotation. if isinstance(rotation, Matrix): self.RM = rotation elif rotation is not None: rotation = tuple(rotation) if not ( len(rotation) == 3 and all(isinstance(a, scalar_types) for a in rotation) ): raise TypeError, rotation ax, ay, az = rotation self.RM = rotx(ax) * roty(ay) * rotz(az) else: self.RM = rotx(0) * roty(0) * rotz(0)
def __init__( self, scale=1.0, translation=None, rotation=None, ): self.things = [] self.subframes = [] if not isinstance(scale, scalar_types): #raise TypeError, scale raise TypeError self.s = scale # Translation. if isinstance(translation, Vector): self.T = translation elif translation is not None: translation = tuple(translation) if not (len(translation) == 3 and all(isinstance(t, scalar_types) for t in translation)): #raise TypeError, translation raise TypeError self.T = Vector(*translation) else: self.T = Vector() # Rotation. if isinstance(rotation, Matrix): self.RM = rotation elif rotation is not None: rotation = tuple(rotation) if not (len(rotation) == 3 and all(isinstance(a, scalar_types) for a in rotation)): #raise TypeError, rotation raise TypeError ax, ay, az = rotation self.RM = rotx(ax) * roty(ay) * rotz(az) else: self.RM = rotx(0) * roty(0) * rotz(0)
def __init__( self, width=320, height=240, x_arc=73.0, y_arc=73.0, focal_distance=2.2, depth=5000.0, ): self.w, self.h = width, height self.xarc, self.yarc = x_arc, y_arc self.FD = focal_distance self.depth = depth self.T = Vector() self.RM = rotx(0) * roty(0) * rotz(0) # Create a list of eight "blank" new Vectors. These will be the # corners of the frustum, used to determine the planes beyond # which a given point is outside the viewable space. self._frustum = [Vector() for _ in range(8)] self._reset() self._getFrustumPlanes()
# c._frustum._reset() # Zoom out a little. c.frame.T.z += -200.0 # Create a dot at world origin (0, 0, 0). origin = dot(c) c.frame.things.append(origin) # Make a cube. cube_frame = Frame3D() c.frame.subframes.append(cube_frame) coords = -1, 1 for x in coords: for y in coords: for z in coords: d = dot(c, 100.0 * x, 100.0 * y, 100.0 * z) cube_frame.things.append(d) # Apply a rotation repeatedly to our cube. N = roty(360 / 30 / 3) # 4 degrees. def delta(): cube_frame.RM *= N c.after(60, delta) # Start everything running. delta() c.start_updating() root.mainloop()
# c._frustum.T.z += 100.0 # c._frustum._reset() # Zoom out a little. c.frame.T.z += -200.0 # Create a dot at world origin (0, 0, 0). origin = dot(c) c.frame.things.append(origin) # Make a cube. cube_frame = Frame3D() c.frame.subframes.append(cube_frame) coords = -1, 1 for x in coords: for y in coords: for z in coords: d = dot(c, 100.0 * x, 100.0 * y, 100.0 * z) cube_frame.things.append(d) # Apply a rotation repeatedly to our cube. N = roty(360/30/3) # 4 degrees. def delta(): cube_frame.RM *= N c.after(60, delta) # Start everything running. delta() c.start_updating() root.mainloop()