Computer Science 102 Quiz 1 Name____________________ Please put your name on both front and BACK of your quiz. Please do not fold your paper. You may depart when you finish. 1. What is the length of the vector (2, -1, 3) 2. Suppose P and Q are points in 3-D space. The vector FROM P TO Q is given by: a. P - Q b. Q - P c. P + Q 3. Compute (1, 2, 3) dot (2, -1, -1) 4. Which of the following is a unit vector in the direction of a arbitrary vector V (circle all that are correct) ||V|| means length of V. a. V / || V || b. || V || V c. V / (V dot V) d. V / sqrt(V dot V) 5. Compute (1, 2, 3) - (3, -2, 1) Computer Science 102 Quiz 2 Name____________________ 1. In the ray tracing model that we will use: a. the viewpoint lies in +z space and b. the viewpoint lies in -x space and the scene lies in -z space the scene lies in +x space c. the viewpoint lies in -z space and d. the viewpoint lies in +x space and the scene lies in +z space the scene lies in -x space 2. A unit vector from the viewpoint toward a pixel on the "screen" always has: a. a negative x component b. a negative y component c. a negative z component d. negative x, y, AND z components 3. Suppose world coordinate dimensions are 8 units wide by 6 units high and the viewpoint is at (4, 3, 6). A unit vector from the viewpoint toward the pixel at the top left corner of the screen has: a. negative x, y, and z components b. negative y and z but positive x c. negative x and y but positive z d. negative x and z but positive y 4. The function that was suggested last time for mapping pixel to world coordinates was: a. world_x = world_size_x * win_x / (win_size_x - 1) b. world_x = world_size_x * (win_size_x - 1) / win_x c. world_x = world_size_x * win_x * (win_size_x - 1) d. world_x = win_size_x * win_x / (world_size_x - 1) 5. Suppose the viewpoint is at location V and the world coordinates of the point on the screen through which a ray passes is W. A vector in the direction the ray is fired is given by: a. V + W b. V - W c. W - V c. (V + W) / 2.0 Computer Science 102 Quiz 3 Name____________________ 1. The elements of a table of attribute types declared as shown are: static char *ac_attrs[] = { "position", /* Current location of aircraft */ "direction", /* Direction of travel */ "speed", /* Speed in NM/hr */ }; a. character strings b. ints c. character variables d. pointers to characters strings 2. In the model description language we described in class a set of attribute values may be followed by: a. } b. an attribute-type c. a or b d. end-of-file 3. In the model description language described in class, end-of-file can legally follow what token(s)? a. { b. } c. a collection of attribute d. any of the above values 4. In the model description language which of the following tokens is an entity-type-name a. green b. material c. } d. viewpoint 5. Which of the following best describes your progress on SP 1 a. I have finished b. I have finished writing but not debugging c. I have downloaded the resource materials, studied aircraft.c and written a some of camera.c d. I have downloaded the resource materials and looked at them but haven't written any new code. e. I have downloaded the resource materials but haven't looked at them yet. f. I have not started. Computer Science 102 Quiz 4 Name____________________ 1. Suppose a list of type list_t contains three items. The number of calls made to free() by list_del() should be a. 1 b. 3 c. 6 d. 7 2. Suppose list_t *list is a pointer to a list that presently has no elements it it. The value of list->head should be: a. NULL b. the address of list->tail c. the address of a link_t d. the address of the last structure item that was removed from the list. 3. Suppose list_t *list points to a correct list header for a non-empty list and link_t *link points to a new link structure to be put on the end of the list. Which of the following approaches will correctly attach the link to the end of the list. a. list->tail = link; b. link->tail = link; list->tail->next = link; link->next = link; c. list->tail->next = link; d. Both a and c but not b. list->tail = link; 4. Suppose list_t *list points to a correct list header for an empty list and link_t *link points to a new link structure to be put on the list. Which of the following approaches will correctly attach the link to the start of the list. a. list->head = link; b. list->head = link; link->next = list->tail; list->tail = link; c. list->head->next = link; d. link->next = list->head; list->tail->next = link; list->tail = link; 5. Suppose the following structures are items on the list: typedef struct entity_type { char e_name[16]; int e_id; } e_t; Given the definition e_t *eloc; the correct way to print e_id value in the e_t structure pointed to by link_t *link is: a. e_t = (e_t *)link->item; b. e_t = (e_t *)link->next; printf("%d\n", e_t->e_id); printf("%d\n", e_t->e_id); c. eloc = (e_t *)link->item; d. eloc = (eloc *)link->item; printf("%d\n", eloc->e_id); printf("%d\n", eloc->e_id); Computer Science 102 Quiz 5 Name____________________ 1. According to Dr. Westall's theory of human behavior, which of the following emotions is most likely to motivate an individual to TAKE ACTION to confront or avoid a potentially harmful situation. a. despair b. hope c. fear d. happiness 2. In your ray tracing system, the INHERITANCE facility of an O-O language will be emulated by the use of: a. structure hierarchies of b. the use of function pointers increasing specialization that may be optionally overridden linked together via void *priv; pointers c. the use of typedef 3. Which is the proper way to declare a pointer to a function that returns an int and takes two ints as parameters: a. int pfun(int, int); b. int *pfun(int, int); c. int *(pfun)(int, int); d. int (*pfun)(int, int); 4. Which is the proper way to make the pointer point to a function named adder. a. pfun = adder; b. pfun = adder(0, 0); c. *pfun = adder; d. pfun = *adder; 5. Which of the following is not a type of illumination specified in a material_t structure: a. specular b. ambient c. diffuse d. incident Computer Science 102 Quiz 6 Name ______________________ 1. Suppose a ray is fired from the viewpoint V in direction D hits the plane at a distance t from V. The coordinates of the hitpoint are: a. P + tN b. V + tP c. D + tV d. V + tD 2. The use of a function pointer hits in the object structure double (*hits)(vec_t *base, vec_t *dir, struct object_type *); allows us to mimic what facility of a true O-O language in C. a. polymorphism d. inheritance c. unitarianism d. nihilism 3. Suppose a ray is fired from coordinate (4, 3, 6) in direction (0.707, 0, -0.707). Assuming it hits an object at a distance 10 units from the source (4, 3, 6) what are the coordinates of the hit point. 4. We will employ a distributed parsing strategy in which each specialization within the inheritance heirarchy is responsible for reading its own attributes. (e.g. object_init reads material but plane_init reads point and normal). Our system is designed to be compatible with C++. This will force us to specify the color of an object (e.g. material green) a. first b. last c. anywhere Computer Science 102 Quiz 7 Name ______________________ 1. Suppose a plane in 3 dimensional space has normal vector N and the P and Q are two different points that both lie in the plane. Which of the following will always have the value 0. a. P dot (Q - N) b. N dot (P - Q) c. N dot P d. P dot (N - Q) 2. Suppose a ray is fired from viewpoint V with unit direction vector D. The ray is parallel to the plane if: a. V dot D = 0 b. V dot N = 0 c. D dot N = 0 d. (N - D) dot V = 0 3. Suppose ray hits the plane at a distance t from V. The coordinates of the hitpoint are: a. P + tN b. V + tP c. D + tV d. V + tD 4. Suppose a plane is defined by N = (0, 0, 1) and Q = (4, 8, -6) where N is the normal and Q is a point on the plane. Suppose V = (4, 2, 3) and D = (0, 0, -1) a. The distance from V to the Hitpoint? b. Give the coordinates of the Hitpoint Hint: Although it is possible to solve this using the plug and pray method with formulas presented in class, this approach will take excessive time and is likely to produce arithmetic errors. The correct approach is to visualize the geometry of the problem in your head (or on paper). If you do that correctly, the solution can be readily computed in your head with resorting to any dot products. Computer Science 102 Quiz 8 Name ______________________ 1. Suppose a sphere is defined by Center = (6, 3, -8) and Radius = 1 Suppose Viewpoint = (6, 3, 4) and Direction = (0, 0, -1). What are the coordinates of the hitpoint ? Finding the intersection of a ray with a sphere requires solving a quadratic equation. 2. The ray misses the sphere entirely if: a. The discriminant is < 0 b. The discriminant is > 0 c. The discriminant is 0 3. The ray passes through the surface of the sphere at two points if a. The discriminant is < 0 b. The discriminant is > 0 c. The discriminant is 0 4. The correct root of the equation to use in determining the hitpoint is a. t = (-b - sqrt(b^2 - 4ac))/2a b. t = (-b + sqrt(b^2 - 4ac))/2a c. Either one will work fine 5. Suppose the center of the sphere is located at C and P is a point on the surface of the sphere. The normal to the surface at P is a. P b. C c. C - P d. P - C Computer Science 102 Quiz 9 Name ______________________ 1. The relation between the functions make_row() and make_pixel() is: a. make_row() calls make_pixel() b. make_pixel() calls make_row() c. they both call each other d. neither calls each other 2. The ray_trace() function is called a. once per image row b. once per pixel c. once per image 3. The camera_write_image() function is called a. once per image row b. once per pixel c. once per image 4. To enable this debugging statement #ifdef DBG_DRGB fprintf(stderr, ..... ); #endif use the following command line: a. gcc -c -g -DBG_DRGB ray.c b. gcc -c -g DBG_DRGB ray.c c. gcc -c -g -DDBG_DRGB ray.c d. gcc -c -g DDBG_DRGB ray.c 5. When storing the color for the pixel at pixel coordinates (x, y) in the pixmap, a. (x, y) corresponds b. col corresponds to x but directly to pixamp (col, row) row corresponds to y - (image height - 1) c. row corresponds to y but col corresponds to x - (image width - 1) Computer Science 102 Quiz A Name____________________ 1. Suppose a tiled plane description looks like: tiled_plane floor { material white normal 0 1 0 point 0 0 0 dimension 2.0 3.0 altmaterial green } For each element of the definition shown below identify the function responsible for reading in the element (some answers may be used more than once or not at all. ___ a. white 1. object_init() 2. plane_init() ___ b. } 3. tplane_init() ___ c. normal 4. model_init() ___ d. green 2. Components of obj->hitloc are used to determine the color of a tile. For a tiled floor the components used are: a. x and y b. y and z c. x and z d. x, y and z Computer Science 102 Quiz B Name ______________________ 1. The cross product (0, 1, 0) and (0, 0, 1): a. (0, 1, 1) b. (0, 0, 1) c. (0, 1, 0) d. (1, 0, 0,) 2. Which of the following is NOT always an attribute of a rotation matrix a. its rows are mutually b. all of its elements are 0 orthogonal c. its inverse is its d. its rows and columns are transpose unit vectors 3. Given three points, P, Q, and R, a normal to the plane that three points define is given by: (x means Cross Product) a. P x R b. (P - Q) x R c. (P - Q) x (R - Q) d. Q x (P - R) 4. The projection of a unit vector V on another unit vector N is given by: a. V dot N b. (N dot V) N c. (V dot N) V d. (N x V) N 5. The projection of a unit vector V on a plane whose normal is N given by: a. V - (N dot V) V b. V - (N dot V) N c. (V dot N) V - V d. (N x V) N Computer Science 102 Quiz C Name ______________________ 1. Which of the following assertions comparing C++ to standard C is FALSE a. C++ supports O-O classes but b. C++ provides a formal inheritance C does not mechanism that C does not. c. C++ supports function and d. C++ compilers produce code that operator overloading but C typically executes much faster than does not. the same program in C. 2. Which of the following best characterizes the relationship of statdard C and C++ a. Standard C is basically a subset b. C++ is basically a subset of of C++ standard C c. They are two independent langauges a standard C compiler will almost never compile a C++ program and vice versa. 3. For this statement to work correctly: list = new list_t; The variable list should be declared: a. list_t *list; b. list_t list; c. int list; 4. If the link_t class provides multiple constructors, the one that is actually used is: a. the first one b. the last one c. randomly chosen d. the one whose formal parameters match the actual arguments passed when a new instance of the class iscreated 5. Suppose the link_t class has a private member named next. Within a link_t member function the value can be correctly accessed in which of the following ways (circle ALL that are correct) a. link->entity = newentity; b. entity = newentity; Computer Science 102 Quiz D Name ______________________ 1. Suppose the cam_t class has a private member named cookie. Within a cam_t member function the value can be correctly accessed in which of the following ways (circle ALL that are correct) a. cookie = CAM_COOKIE; b. this.cookie = CAM_COOKIE; c. this->cookie = CAM_COOKIE; 2. In a C++ program a function whose mission is to process a collection of object_t's (e.g. find_closest_object) a. must be an object_t class method b. must be a standalone C function c. should be either a standalone C function or a method from a class OTHER THAN object_t. 3. When a new instance of a plane_t is created a. only the plane_t's constructor b. only the object_t's constructor will be called will be called c. the plane_t's constructor will d. the object_t's constructor will execute after the object_t's execute after the plane_t's constructor completes. constructor completes 4. The proper way to begin an fplane_t class method dumper whose implementation is outside the class definition is: a. void fplane_t::dumper( b. void dumper::fplane_t( FILE *out) FILE *out) c. fplane_t::void dumper( d. void dumper(fplane_t:: FILE *out) FILE *out) 5. Suppose the fplane_t dumper function contains the following syntax void fplane_t::dumper( FILE *out) { plane_t::dumper(out); which is designed to invoke the dumper function of the plane class just above it. Circle all of the answers below that are TRUE. a. this is THE correct way to do b. the presence of plane_t:: what is intended will cause a syntax error and it needs to be removed c. removing plane_t:: will result in an infinite recursion in which d. the program will work as fplane_t::dumper repeatedly intended with or without calls itself. plane_t:: Computer Science 102 Quiz E Name ______________________ 1. Given the following function prototype: friend inline void vec_sum(vec_t &, vec_t *, vec_t *); and the following declarations: vec_t v1, v2, v3; The proper way to invoke the function is: a. vec_sum(v1, v2, v3); b. vec_sum(v1, &v2, &v3); c. vec_sum(v1, v2, &v3); d. vec_sum(&v1, &v2, v3); 2. Given the following function prototype: friend inline void vec_sum(vec_t &, vec_t &, vec_t *); Identify ALL of the following definitions that would cause illegal duplication ___ a. friend inline void vec_sum(vec_t *, vec_t *, vec_t *); ___ b. friend inline void vec_sum(vec_t &, vec_t , vec_t *); ___ c. friend inline void vec_sum(vec_t *, vec_t &, vec_t *); 3. Suppose the intent is to cause the sum to be stored in the third vector passed to vec sum. Identify all of the following cannot produce the desired result. ___ a. friend inline void vec_sum(vec_t *, vec_t *, vec_t *); ___ b. friend inline void vec_sum(vec_t &, vec_t , vec_t &); ___ c. friend inline void vec_sum(vec_t *, vec_t &, vec_t ); 4. Given the following function prototype: void vec_sum(vec_t &v1, vec_t v2, vec_t *v3); Assuming the objective is to put the sum of the v1 and v2 in v3 which is the correct approach: ___ a. v3->x = v1->x + v2.x; ___ b. v3->x = v1.x + v2.x; ___ c. v3.x = v1->x + v2.x; Computer Science 102 Quiz F Name ______________________ 1. The diffuse intensity the light reflected by an object at the hitpoint is a product of the emissivity of the light, the diffuse reflectivity of the object and the dot product of a. unit vectors pointing b. a unit normal at the object in the direction of the hitpoint and a unit vector light and the direction in the direction of the viewpt of the viewpt from the hit c. a unit normal at the object d. unit vectors pointing from the hitpoint and a unit vector light to the object and the in the direction of the light light to the viewpoint 2. (a continuation of 1) divided by: a. the distance from the light b. the distance from the light to to the viewpt the hitpoint c. the distance from the hitpoint to the object 3. If the dot product in #1 is negative it means that a. the hit object occludes itself b. the hit object is occluded by from the light another object c. the center of the light is visible from the hitpoint 4. In the computation of question 1, a. It is REALLY necessary to use b. it will work OK as long as unit vectors one of the vectors is a unit vector c. It doesn't really make any difference whether unit vectors are used or not. 5. When computing diffuse refectivity as described in questions (1) and (2) the value that is computed a. MUST be stored in the "diffuse" b. Must NOT be stored in "diffuse" drgb_t of the material_t drgb_t of the material_t c. It doesn't matter where it is stored. Computer Science 102 Quiz G Name ______________________ 1. Suppose V and W are vec_t's and a is a scalar double. For each of the following operator overloads indicate whether the overload COULD BE a class method or MUST BE a friend function: V + W a. class method b. friend function a * W a. class method b. friend function V * a a. class method b. friend function !V a. class method b. friend function 2. If I want to overload the * operator to support BOTH a * V and V * a, a. I MUST write two separate b. I must write ONLY one operator* functions operator* c. Depending on my approach I can use either one or two operator* functions 3. Suppose I want to define a cross product operator. Which of the following can I use. Circle all that are correct. a. W * V b. W ! V c. W x V 4. Suppose I want to define a vector length operator. Which of the following can I use. Circle all that are correct. a. | V | b. !V c. -V Computer Science 102 Quiz H Name ______________________ 1. In the rotation matrix used in the fplane_t the plane unit normal vector becomes a. row 0 b. row 1 c. row 2 d. its not used in the matrix 2. row 1 of the rotation matrix is constructed as: a. row 2 x row 0 b. row 0 x row 2 c. the projection of the xdir on the y axis 3. The transformation of the hit point that is done in hit testing is. a. a subtraction followed b. a rotation followed by by a rotation a subtraction c. a rotation and a a subtraction but the order doesn't matter 4. After the hit point is properly transformed a. its x coordinate must be a. its y coordinate must be approximately 0 approximately 0 c. its z coordinate must be d. none of its coordinates approximately 0 need to be near 0. 5. Circle all that are true with respect to the input xdir a. it must be parallel to b. it must not be parallel the plane to the plane normal c. Its y and z coordinates must both be 0. Computer Science 102 Quiz I Name ______________________ 1. In the texture mapping algorithm the size of a pixel in world coords is used in: a. texture_tile() b. texture_fit() c. both of them d. neither one 2. Suppose the size of the screen in world coordinates is 8 units wide and 6 units tall. Suppose the size of the output image is 400 pixels wide and 300 pixels tall. What is the size of a pixel in world coords? 3. Suppose a texture of size 200 pixels wide by 400 pixels tall is being mapped in stretch to fit mode onto a finite plane of size 5 units wide and 4 units tall. Suppose the translated and rotated hitloc is (4.0, 2.0, 0.0). Give the texel coordinates in pixel units assuming a lower left texture origin (DONT perform the upside down correction) 4. Suppose a texture of size 100 pixels wide by 50 pixels tall is being mapped in tiled mode onto a finite plane of size 5 units wide and 4 units tall. Suppose that a pixel size is 0.01 in world coordinates and that the hit point is (2.95, 1.57) Give the texel coordinates in pixel units assuming a lower left texture origin (DONT perform the upside down correction) 5. The texplane_t class is directly derived from the: a. plane_t b. fplane_t c. object_t d. light_t Computer Science 102 Quiz J Name ______________________ Consider the conical spotlight in which the emitted light is constrained by a conical shade. 1. Suppose the spotlight is illuminating a plane. The area illuminated will be circle if a. the dot product of the centerline b. the dot product of the centerline direction and the plane normal is direction and the plane normal is 0 -1 c. never d. always 2. Suppose costheta holds the cosine of the angle of the halfwidth of the cone. A point on the plane is illuminated if and only if the dot product of a unit vector from the light to the hitpoint is a. positive b. negative c. > costheta d. < costheta 3. Two new methods required by the projector type light included a. getemiss and getdiff b. vischeck and illuminate c. vischeck and getdiff d. getemiss and vischeck 4. When a new projector_t is created, instances of which classes will be created. a. projector_t only b. projector_t and light_t c. projector_t, light_t and d. projector_t, light_t, texplane_t texplane_t, fplane_t, plane_t and object_t 5. In creating his new projector_t class, Dr. Westall employed an ugly hack using a global variable to avoid parsing problems that would have occured in which constructor: a. projector_t b. light_t c. texplane_t d. object_t Computer Science 102 Quiz L Name ______________________ 1. Write down all the possible different combinations of the letters {a, b, c, d} taken TWO at a time. 2. In the maze problem, one cause for a move being declared "illegal" was that the coordinates of the proposed move lay OUTSIDE THE MAZE. Another was that the move was inside the maze but had the value 1. What is the other condition that makes a move illegal. 3. To compute n! as quickly and efficiently as possible, the preferred approach is to: a. use recursion b. use a single for loop c. use nested for loops d. all three are equally good 4. Complete the following function that will RECURSIVELY return the SUM 1 + 2 + 3 + ... + n when called with a positive integer parameter n int summer( int n) // return sum 1 + 2 + ... + n { Computer Science 102 Quiz L Name ______________________ 1. There are THREE conditions under which the recursive raytracing stops. One is that the reflected ray doesn't hit any object. What are the other two: a. b. 2. When specular reflection occurs and raytrace() is to be called recursively the base of the new ray is a. the viewpoint b. the light that illuminates the surface c. the hitpoint of the current ray. 3. In creating specular glints a shininess exponent is used. Which of the following best characterizes the useful range of values for the shininess exponent. a. 0.0 to 1.0 b. 1.0 to 10.0 c. 50.0 to 300.0 d. 10^8 to 10^10 4. The visible area of the glint effect is made smaller by: a. decreasing the shininess b. increasing the shininess c. its independent of the shininess 5. The brightness of the glint can be increased by a. increasing the specular b. increasing the emissivity reflectivity of the material of the light that produces it c. both a and b will work. Computer Science 102 Quiz M Name ______________________ 1. In the approach to anti-aliasing that was discussed in class, the number of rays traced per pixel a. is still one ray per pixel b. is some constant number > 1 c. is a random number of rays 2. To perform antialiasing ray direction should be randomized. In the method proposed in class this was done by adding a random offset to a. The x, y components b. The (x, y) pixel coordinates dir.x and dir.y of the of the point at which the ray direction vector was fired c. The (x,y) world coordinates of the point at which the ray was fired. 3. The value to be added in the randomization should be in the range: procedure should be a. (0, 1) b. (-0.5, 0.5) c. (0, 0x7ffffff) 4. Suppose an image of 1000 x 1000 pixels is created with 20 antialised samples per pixel and an average of 5 specular bounces per ray. The total number of calls to ray_trace() is closest to: a. 1,000,000 b. 50,000,000 c. 20,000,000 d. 100,000,000 5. Now suppose that one of the objects in the scene is made partially transparent. The number of ADDITIONAL calls to ray_trace() that this will produce is closest to: a. 1,000,000 b. 20,000,000 c. the number of rays that d. the number of rays that are fired from the viewpoint are fired from the viewpoint and hit the transparent and hit the transparent object object plus the number that bounce into the transparent object. e. the number of rays that are fired from the viewpoint and hit the transparent object plus the number that bounce into the transparent object plus the number of bounces made by each ray that passes through the transparent object.