Shadow effect while rolling a sphere
Course:- Computer Graphics
Reference No.:- EM13474

Assignment Help
Expertsmind Rated 4.9 / 5 based on 47215 reviews.
Review Site
Assignment Help >> Computer Graphics

There are two more unit-sphere ?les given in http://cis.poly.edu/cs653/assg3/, with 256 and 1024 triangles, respectively.

Draw the x-, y-, z-axes, the "ground" (the quadrilateral indicating the x-z plane), and roll the wire-frame sphere as in Assignment 2. Your task here is to add the corresponding shadow of the sphere on the ground given a ?xed light source located at position L = (-14.0, 12.0,-3.0, 1.0).

Draw the shadow with color (0.25, 0.25, 0.25, 0.65). Note that the shadow should be the wire- frame sphere projected onto the ground, projected from the light source. As the sphere rolls, the shadow should also "roll" accordingly.

As another option, draw the sphere as a solid sphere and roll it as before, by drawing the sphere triangles as ?lled triangles rather than just drawing the triangle edges. Produce the corresponding shadow effect for this rolling solid sphere as well, using the same shadow color and the same light source location L. (The options are put together by a menu; see Part (b).)

Programming Tips:

1. If you experienced a strange behavior of the z-buffer where some parts of the scene disappear randomly, check your gluPerspective() command; see Useful Tips Item 2 on page 4 for the details.

2. In OpenGL, although the perspective division is automatically done to convert (x, y, z,w) to (x/w, y/w, z/w, 1) for w = 0, the OpenGL implementation actually requires that w > 0. So if you tried q = ( f(x,y,z)/ h(x,y,z) , 0, g(x,y,z)/h(x,y,z) , 1) ≡ (f(x, y, z), 0, g(x, y, z), h(x, y, z)) and it did not work, try to use q = ( -f(x,y,z)/-h(x,y,z) , 0, -g(x,y,z)/-h(x,y,z) , 1) ≡ (-f(x, y, z), 0,-g(x, y, z),-h(x, y, z)).

(b) If you just draw the shadow as in Part (a), then you will see a broken shadow. The unde- sirable effect is especially obvious for the solid sphere. This is because the shadow and the ground are on the same plane, but the z-buffer only has a limited numerical precision. As a result, some portion of the shadow may appear in front of the ground and some portion may appear behind the ground and thus blocked by the ground; the result is unpredictable. Note that what you want here is to make the shadow always appear on top of the ground, i.e., to make the shadow a decal on top of the ground. Use the technique of making a decal, as discussed in class, to achieve the desired effect.

In addition, implement "Shading" as a submenu with 2 submenu entries: "?at shading" and "smooth shading". When lighting is disabled (by choosing "Enable Lighting" and then "No"), both options should just draw the sphere as a solid sphere (see Part (a)) and give the same result.

(c) Provide a global ambient white (with color (1.0, 1.0, 1.0, 1.0)) light, and also provide a directional light source with black ambient color (0.0, 0.0, 0.0, 1.0), white diffuse and specular color (1.0, 1.0, 1.0, 1.0), and position (0.0, 0.0, 1.0, 0.0) in the eye coordinate system. Note that (0.0, 0.0, 1.0, 0.0) is in fact a vector rather than a point, and thus this light source is a distant (directional) light. The colors and the position described above are actually the default values of GL_LIGHT0, so you can set it up by just enabling GL_LIGHT0 without specifying these values. If you do want to specify the values, notice that the position (vector) value is in the eye coordinate system (meaning that the vector is ?xed relative to the viewer), and you have to specify it in an appropriate place in your program; see Useful Tips Item 3 on page 4 for more details. Give your quadrilateral "ground" that indicates the x-z plane a green diffuse color (0.0, 1.0, 0.0) (with default ambient and specular colors), and give your sphere a golden yellow diffuse and specular color (1.0, 0.84, 0.0) (and a default ambient color) with a shininess coef?cient of 125.0. Consider the four unit-sphere ?les given. Actually, there is one more piece of information implicitly given in the ?le format: each triangle (given by the coordinates of its three vertices) has its three vertices ordered such that if the ?ngers of the right hand are curled along the direction of the vertex speci?cation, the thumb will point towards the triangle's outward normal (in this case this normal points towards the outside of the sphere). Augment your data structure from Assignment 2 so that associated with each triangle you also store its outward normal vector of length 1 (i.e., the unit-length outward normal vector).

Recall that the menu entry "Shading" has two submenu entries "?at shading" and "smooth shading". Implement these entries with the following shading effects when "Enable Lighting" is "Yes":

(1) "?at shading"- ?at shade the ?lled triangles of the unit sphere, where the unit-length normal vector associated with each triangle is the normal vector that you just computed and stored.

(2) "smooth shading" - smooth shade the ?lled triangles of the unit sphere. To assign the unit- length vertex normals, use the fact that if the unit sphere is centered at the origin o and v is a point on the surface of the unit sphere, then → ov is the unit-length normal vector at v.


Put your comment

Ask Question & Get Answers from Experts
Browse some more (Computer Graphics) Materials
For an on line poster presentation, you need to use PowerPoint, Visio, MS Word, or another program that allows you to use graphics and pictures along with words to tell a st
Modify the product Program to use a GUI. The GUI should show the data one product at a time, including the product number, the name of the item, the number of units in stock.
Write a program that allows the user to specify a triangle with three mouse presses. After the first mouse press, draw a small dot. After the second mouse press, draw a line
Next, design a class Street that contains a number of equally spaced houses. An object of type Street stores the first house, the last house (which can be anywhere on the sc
Write a GUI application that produces a restaurant bill. You create a bill calculator to generate window output. You should prompt the user to enter all the dishes and their
Modify the Inventory Program to include an add button, a delete button, and a modify button on the GUI. These buttons should allow the user to perform the corresponding acti
The McTavish family connects their three computer systems and a printer wirelessly within their home.tate one additional hardware requirement for setting up this network.
How many bits are there in the operation code, the register code part, and the address part and draw the instruction word format and indicate the number of bits in each part.