Interactive system for shading of a 3D object.
- Manipulate Normal Vectors
- Create Light sources
- Difference between flat shading and Gouraud shading
1. Assign normal vectors:
In OpenGL, you need to specify a normal vector to each vertex of a face (polygon). For example, the following statements indicate that the vertex (1,1,1) is assigned with a normal vector (1,0,0).
glNormal3f(1, 0, 0);
glVertex3f(1, 1, 1);
2. Create light sources:
In OpenGL, you can create a light source with a specific property, such as position, color and direction by a function called glLightfv() or glLightf(), as follows:
void glLightfv(GLenum light, GLenum pname, const TYPE *param);
void glLightf(GLenum light, GLenum pname, TYPE param);
glLightfv() has three function parameters. The first one indicates the identity of a light source, which can be one of the values from GL LIGHT0 to GL LIGHT7. The second one indicates the name of a property, which can be one of the following values
- GL POSITION
- GL AMBIENT, GL DIFFUSE, GL SPECULAR
- GL SPOT DIRECTION
Three shading models: flat, Gouraud, and phong. With the flat model, the
colors of points in the same face are identical. So, it is common that the flat model is not good at retaining 3D strucutre of an object. With the Gouraud model, the colors of points in a face are interpolated by the colors of the vertex of the face. Recall that the colors of different vertices of a face are usually different even if they are assigned with the same normal vector. Therefore, the colors of points in a face are different.
OpenGL provides implementation of the flat and Gouraud shading. In OpenGL, you can specify a shading model by the following function:
void glShadeModel(GLenum mode);
where mode can be GL FLAT or GL SMOOTH. GL SMOOTH implies the Gouraud shading model.
4. User interaction:
The system allows a use to use a popup menu to select a shading model, i.e., the flat shading or Gouraud shading model.
The system allows a user to use the keyboard to change the position of a selected light source. The user can use the key 0 and 1 to select a light source. Furthermore, the user can use the following 2 keys to change the position of the selected light source.
- j – move the light source to its left
- l – move the light source to its right. Implement one more keyboard interaction as follow:
- r – rotate counter clockwise 10 degrees horizontally, i.e., around the vertical line passing through the center of the object. You can use the glRotate() function. But keep in mind that you also need two translation transformation, in addition to glRotate().
5. Input data:
The input data is stored in a file named something.obj. A data object file may contain three symbols: #, v and f. # indicates a comment line. In general, Comments are optional, i.e., a data file may not have any comment lines. To simplify the I/O access in this project, you can assume that the first two lines in a data file are comments that have the information of the number of vertices and the number of polygons. The symbol v indicates a vertex of x, y and z coordindates. The symbol f indicates a face (polygon) consisting of a set of vertices. The following is an example of the data file for a house object.
# 10 vertices
# 7 polygons
v 0 0 54
v 16 0 54
v 16 10 54
v 8 16 54
v 0 10 54
v 0 0 30
v 16 0 30
v 16 10 30
v 8 16 30
v 0 10 30
f 1 2 3 4 5
f 2 7 8 3
f 7 6 10 9 8
f 6 1 5 10
f 2 1 6 7
f 3 8 9 4
f 10 5 4 9
For this house object, the first vertex has the coordinates (0, 0, 54). The first face has 5 vertices, i.e., 1st, 2nd, . . ., 5-th vertices. To further simplify the I/O access in this project, you can assume that each face is a triangle. Thus, each face consists exact three vertices.
NOTE: source code and readme required
************* Complete Description in ATTACHMENT**************
Được trao cho:
8 freelancer đang chào giá trung bình $83 cho công việc này
Hello.... I can do a genuine version for you ... I love opengl, and I should be a good option for this project. 2 days or less ... Best regards!