def ioq(ask=True): pipeline = [(('object', 'model'), ('model', ), ('world', )), (('world', ), ('view', 'camera'), ('camera', 'eye')), (('camera', 'eye'), ('projection', ), ('canonical view volume', 'clip')), (('canonical view volume', 'clip'), ('perspective division', ), ('2d', )), (('2d', ), ('viewport', ), ('screen', ))] stage = rv.choose_random_from(pipeline) space_syn = rv.choose_random_from(("space", "coordinates")) qp = ( rv.choose_random_from(stage[0]), rv.choose_random_from(stage[1]), rv.choose_random_from(stage[2]), ) qidx = rv.choose_random_from(range(len(qp))) q = 'The %s transformation transforms %s %s into %s %s.\n' % ( qp[1], qp[0], space_syn, qp[2], space_syn) q = q.replace(qp[qidx], rv.blank()) # hacky: fix phrasing for some terms that don't fit templates q = q.replace("The perspective division transformation", "Perspective division") q = q.replace("canonical view volume %s" % space_syn, "the canonical view volume") a = stage[qidx] categories = [y for x in pipeline for y in x[qidx]] if ask: ua = rv.expect_categorical(q, categories) rv.check_answer(a, ua, q, "input/output", part_of_str_answer_is_in_choices) else: return q, a, (categories)
def directionq(): x = rv.vector3() y = rv.vector3() a = 'a' if (x.dot(y) < 0): a = 'b' elif x.dot(y) == 0: a = 'c' q = "What is the relationship between the following two vectors?\n %s, %s\n a) They point in the same direction\n b) they point in opposite directions\n c) they are perpendicular\n" % ( numpy.array_str(x), numpy.array_str(y)) ua = rv.expect_categorical(q, ('a', 'b', 'c')) rv.check_answer(a, ua, q, "direction")
def samplingq(ask=True): ir = np.random.randint(2**4, 2**7, 2) q1 = "Given a texture of size (%d, %d) and an image of size (%d, %d), how many texels must cover each pixel?" % ( ir[0], ir[0], ir[1], ir[1]) a1 = ir[0] / ir[1] q2 = "Is this a problem of magnification (mag) or minification (min)?" if ir[0] < ir[1]: a2 = "mag" else: a2 = "min" rv.writeModule(dict(zip("ir, a1, a2".split(','), (ir, a1, a2)))) if ask: ua1 = rv.expect_float(q1) rv.check_answer(a1, ua1, q1, "texel:pixel") ua2 = rv.expect_categorical(q2, ('mag', 'min')) rv.check_answer(a2, ua2, q2, "magnification") else: return rv.combine((q1, q2), False), rv.combine((a1, a2), False)
def projectionq(ask=True): projectionqs = [ ("Projectors pass through a *viewpoint*.", 'p'), ("Projectors all are in the same projection *direction*.", 'o'), ("Further objects are smaller.", 'p'), ("Parallel lines are preserved.", 'o'), ("Viewing volume is shaped like a frustum.", 'p'), ("Viewing volume is shaped like a parallelipiped.", 'o'), ("Looks more natural.", 'p'), ("Useful for architectural drawings.", 'o'), ] pq = rv.choose_random_from(projectionqs) q = "For which kind of projection is the following statement true? Answer 'p' for perspective or 'o' for orthographic.\n %s " % pq[ 0] a = pq[1] if ask: ua = rv.expect_categorical(q, ('o', 'p')) rv.check_answer(a, ua, q, "projection") else: return q, a, ()