def draw(self, width, height, z, full): glUseProgram(self.shaderProgram) glUniformMatrix4fv(self.locations["u_model"], 1, GL_TRUE, np.eye(4)) glUniformMatrix4fv(self.locations["u_view"], 1, GL_TRUE, mat.translation(np.array([0.0, 0.0, -z], np.float32))) glUniformMatrix4fv(self.locations["u_projection"], 1, GL_TRUE, mat.perspective(45.0, float(width)/float(height), 0.1, 1000.0)) glUniform4f(self.locations["u_colormod"], *(np.zeros(4)) if not full else (np.array([0.0, 0.0, 1.0, 0.0], np.float32))) glBindVertexArray(self.vertexArrayObject) glDrawElements(GL_LINES, 24 if full else 8, GL_UNSIGNED_INT, None) glBindVertexArray(0)
def hexagon_edge(): edge = cylinder() edge.minimum = 0 edge.maximum = 1 set_transform( edge, translation(0, 0, -1) * rotation_y(-pi / 6) * rotation_z(-pi / 2) * scaling(0.25, 1, 0.25), ) return edge
def draw(self, width, height, z): glUseProgram(self.shaderProgram) glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_2D, self.texture) glUniform1i(self.locations["u_texture"], 0) glUniformMatrix4fv(self.locations["u_model"], 1, GL_TRUE, np.eye(4)) glUniformMatrix4fv(self.locations["u_view"], 1, GL_TRUE, mat.translation(np.array([0.0, 0.0, -z], np.float32))) glUniformMatrix4fv(self.locations["u_projection"], 1, GL_TRUE, mat.perspective(45.0, float(width)/float(height), 0.1, 1000.0)) glBindVertexArray(self.vertexArrayObject) glDrawArrays(GL_QUADS, 0, 4) glBindVertexArray(0)
def draw(self, width, height, z, full): glUseProgram(self.shaderProgram) glUniformMatrix4fv(self.locations["u_model"], 1, GL_TRUE, np.eye(4)) glUniformMatrix4fv( self.locations["u_view"], 1, GL_TRUE, mat.translation(np.array([0.0, 0.0, -z], np.float32))) glUniformMatrix4fv( self.locations["u_projection"], 1, GL_TRUE, mat.perspective(45.0, float(width) / float(height), 0.1, 1000.0)) glUniform4f( self.locations["u_colormod"], *(np.zeros(4)) if not full else (np.array([0.0, 0.0, 1.0, 0.0], np.float32))) glBindVertexArray(self.vertexArrayObject) glDrawElements(GL_LINES, 24 if full else 8, GL_UNSIGNED_INT, None) glBindVertexArray(0)
def step_impl(context): context.ball = sphere() context.ball.material.color = color(1, 0, 0) context.ball.material.ambient = 0.5 context.ball.transform = translation(0, -3.5, -0.5)
def step_impl(context): context.shape = glass_sphere() context.shape.transform = translation(0, 0, 1)
def step_impl(context): context.floor2 = plane() context.floor2.transform = translation(0, -1, 0) context.floor2.material.reflective = 0.5 context.floor2.material.transparency = 0.5 context.floor2.material.refractive_index = 1.5
def hexagon_corner(): corner = sphere() set_transform(corner, translation(0, 0, -1) * scaling(0.25, 0.25, 0.25)) return corner
def step_impl(context): context.upper = plane() context.upper.material.reflective = 1 context.upper.material.transform = translation(0, 1, 0)
def step_impl(context): context.m = translation(3, 4, 5)
def step_impl(context): assert context.t == translation(0, 0, -8)
def step_impl(context): context.c.transform = rotation_y(pi / 4) * translation(0, -2, 5)
def makeUnitSquare(segs): print 'insegs %s' % segs transforms = [] # the topmost point and leftmost point must be on the hull points = gather_points(segs) xsorted = sorted(points, key=lambda p: p[0]) ysorted = sorted(points, key=lambda p: p[1]) leftset = set(filter(lambda x: x[0] == xsorted[0][0], xsorted)) leftmost = xsorted[0] topmost = ysorted[0] nextleftmost = filter(lambda x: x[0] != leftmost[0], xsorted)[0] print "left %s next %s" % (leftmost, nextleftmost) print "leftset %s" % leftset if len(leftset) > 1: # It is upright left = leftmost[0] bottom = topmost[1] - 1 transform = matrix.translation(-left, -bottom) transforms.append(transform) segs = [s.transform(transform) for s in segs] else: # Rotate it slope = Segment(leftmost, topmost).slope() shearY = [[1,0,0],[Fraction(1,slope),1,0],[0,0,1]] transforms.append(shearY) segshear = [s.transform(shearY) for s in segs] segs = segshear points = gather_points(segshear) ysorted = sorted(points, key=lambda p: p[0]) ymin = ysorted[0][1] ymax = ysorted[-1][1] yminline = sorted(filter(lambda x: x[1] == ymin, ysorted), key=lambda p: p[0]) ymaxline = sorted(filter(lambda x: x[1] == ymax, ysorted), key=lambda p: p[0]) xmin = yminline[0] xmax = ymaxline[0] if xmin == xmax: raise("What to do here?") slope = Segment(xmin,xmax).slope() shearY = [[1,Fraction(-1,slope),0],[0,1,0],[0,0,1]] transforms.append(shearY) segshear = [s.transform(shearY) for s in segshear] segs = segshear points = gather_points(segs) xsorted = sorted(points, key=lambda p: p[0]) ysorted = sorted(points, key=lambda p: p[1]) # We might have damaged the scale by undoing the rotation using shear print 'xsorted', xsorted xscale = xsorted[-1][0] - xsorted[0][0] yscale = ysorted[-1][1] - ysorted[0][1] print xscale, yscale transform = [[Fraction(1,xscale),0,0],[0,Fraction(1,yscale),0],[0,0,1]] transforms.append(transform) squaresegs = [s.transform(transform) for s in segs] points = gather_points(squaresegs) # Translate it xsorted = sorted(points, key=lambda p: p[0]) ysorted = sorted(points, key=lambda p: p[1]) xmin = xsorted[0][0] ymin = ysorted[0][1] transform = matrix.translation(-xmin,-ymin) transforms.append(transform) segs = [s.transform(transform) for s in squaresegs] return segs, transforms
def step_impl(context): context.transform = translation(5, -3, 2)
def step_impl(context): set_pattern_transform(context.pattern, translation(0.5, 1, 1.5))
def step_impl(context): assert context.pattern.transform == translation(1, 2, 3)
def step_impl(context): set_pattern_transform(context.pattern, translation(1, 2, 3))
def step_impl(context): context.C = glass_sphere() context.C.transform = translation(0, 0, 0.25) context.C.material.refractive_index = 2.5
w = world() w.light = point_light(point(-10, 10, -10), color(1, 1, 1)) black = color(0, 0, 0) white = color(1, 1, 1) floor = plane() floor.transform = scaling(0.5, 0.5, 0.5) floor.material.color = color(0.9, 0.9, 0.9) floor.material.specular = 0.3 floor.material.pattern = checkers_pattern(black, white) floor.material.reflective = 0.6 w.objects.append(floor) left_wall = plane() left_wall.transform = (translation(0, 0, 5) * rotation_y(-pi / 4) * rotation_x(pi / 2) * scaling(10, 0.01, 10)) left_wall.material.specular = 0.7 left_wall.material.pattern = stripe_pattern(black, white) w.objects.append(left_wall) right_wall = plane() right_wall.transform = (translation(0, 0, 5) * rotation_y(pi / 4) * rotation_x(pi / 2) * scaling(10, 0.01, 10)) right_wall.material.specular = 0.7 right_wall.material.pattern = stripe_pattern(black, white) w.objects.append(right_wall) middle = sphere() middle.transform = translation(-0.5, 1, 0.5) middle.material = material()
def step_impl(context): context.t = translation(2, 3, 4)
def makeUnitSquare(segs): print 'insegs %s' % segs transforms = [] # the topmost point and leftmost point must be on the hull points = gather_points(segs) xsorted = sorted(points, key=lambda p: p[0]) ysorted = sorted(points, key=lambda p: p[1]) leftset = set(filter(lambda x: x[0] == xsorted[0][0], xsorted)) leftmost = xsorted[0] topmost = ysorted[0] nextleftmost = filter(lambda x: x[0] != leftmost[0], xsorted)[0] print "left %s next %s" % (leftmost, nextleftmost) print "leftset %s" % leftset if len(leftset) > 1: # It is upright left = leftmost[0] bottom = topmost[1] - 1 transform = matrix.translation(-left, -bottom) transforms.append(transform) segs = [s.transform(transform) for s in segs] else: # Rotate it slope = Segment(leftmost, topmost).slope() shearY = [[1, 0, 0], [Fraction(1, slope), 1, 0], [0, 0, 1]] transforms.append(shearY) segshear = [s.transform(shearY) for s in segs] segs = segshear points = gather_points(segshear) ysorted = sorted(points, key=lambda p: p[0]) ymin = ysorted[0][1] ymax = ysorted[-1][1] yminline = sorted(filter(lambda x: x[1] == ymin, ysorted), key=lambda p: p[0]) ymaxline = sorted(filter(lambda x: x[1] == ymax, ysorted), key=lambda p: p[0]) xmin = yminline[0] xmax = ymaxline[0] if xmin == xmax: raise ("What to do here?") slope = Segment(xmin, xmax).slope() shearY = [[1, Fraction(-1, slope), 0], [0, 1, 0], [0, 0, 1]] transforms.append(shearY) segshear = [s.transform(shearY) for s in segshear] segs = segshear points = gather_points(segs) xsorted = sorted(points, key=lambda p: p[0]) ysorted = sorted(points, key=lambda p: p[1]) # We might have damaged the scale by undoing the rotation using shear print 'xsorted', xsorted xscale = xsorted[-1][0] - xsorted[0][0] yscale = ysorted[-1][1] - ysorted[0][1] print xscale, yscale transform = [[Fraction(1, xscale), 0, 0], [0, Fraction(1, yscale), 0], [0, 0, 1]] transforms.append(transform) squaresegs = [s.transform(transform) for s in segs] points = gather_points(squaresegs) # Translate it xsorted = sorted(points, key=lambda p: p[0]) ysorted = sorted(points, key=lambda p: p[1]) xmin = xsorted[0][0] ymin = ysorted[0][1] transform = matrix.translation(-xmin, -ymin) transforms.append(transform) segs = [s.transform(transform) for s in squaresegs] return segs, transforms
def step_impl(context): context.C = translation(10, 5, 7)
def step_impl(context): set_transform(context.s, translation(2, 3, 4))
def step_impl(context): assert context.s.transform == translation(2, 3, 4)
def step_impl(context): set_transform(context.s, translation(0, 1, 0))
floor.material.color = color(1, 0.9, 0.9) floor.material.specular = 0 w.objects.append(floor) # left_wall = sphere() # left_wall.transform = translation(0, 0, 5) * rotation_y(-pi/4) * rotation_x(pi/2) * scaling(10, 0.01, 10) # left_wall.material = floor.material # w.objects.append(left_wall) # right_wall = sphere() # right_wall.transform = translation(0, 0, 5) * rotation_y(pi/4) * rotation_x(pi/2) * scaling(10, 0.01, 10) # right_wall.material = floor.material # w.objects.append(right_wall) middle = sphere() middle.transform = translation(-0.5, 1, 0.5) middle.material = material() middle.material.color = color(0.1, 1, 0.5) middle.material.diffuse = 0.7 middle.material.specular = 0.3 w.objects.append(middle) right = sphere() right.transform = translation(1.5, 0.5, -0.5) * scaling(0.5, 0.5, 0.5) right.material = material() right.material.color = color(0.5, 1, 0.1) right.material.diffuse = 0.7 right.material.specular = 0.3 w.objects.append(right) left = sphere()
def step_impl(context): context.shape = plane() context.shape.material.reflective = 0.5 context.shape.transform = translation(0, -1, 0)