| Assignment
#1
Projection,
HSR, and Shading
Objective:
Viewing projection, Z Buffer, Gouraud shading,
OpenGL
Due:
10/21,
2002
Program
Description:
You are
required to implement an OpenGL program that does viewing projection,
Z Buffer, and Gouraud shading based on Phong model. There are two kinds
of data, one is viewing data (*.view),
and the other is object data (*.obj).
Viewing
Data (*.view):
Viewing
data describes lights, viewing parameters, and viewport information.
We assume that the view coordinate system is a right-handed coordinate
system (the viewing direction is negtive Z direction in view coordinate
system) and the projection is perspective. The data format is
described below:
light x
y z ar ag ab dr dg db sr sg sb
(x,y,z):
light POSITION (no "w" term,
because We assume they are all point lights).
(ar,ag,ab): light AMBIENT property.
(dr,dg,db): light DIFFUSE property.
(sr,sg,sb): light SPECULAR property.
**ATTENTION:
There might be multiple light sources.
ambient r
g b
(r,g,b):
the GLOBAL AMBIENT term.
[Hint:
use glLightModel... ]
eye x y z
(x,y,z):
your eye position.
vat x y
z
(x,y,z):
the position you are looking at
vup x y z
(x,y,z):
your up vector.
fovy angle
angle:
your field of view angle.
dnear d
d: The
distance between your eye and near plane.
dfar f
f: The
distance between your eye and far plane.
viewport
x y width height
(x,y):
The lower left corner of the viewport rectangle.
width: viewport width.
height: viewport height.
[Hint:
your should set view frustum and viewport information in GLUT Reshape
callback function].
Object
Data (*.obj):
Object
Data defines a set of polygons and each polygon could have its own material
property specified by a material name defined in the material library
file (*.mtl).
Ex:
box.obj
|
Description |
g
Box01
mtllib ./box.mtl
v -2.5 -2.5 10
v -2.5 2.5 10
v 2.5 2.5 10
v 2.5 -2.5 10
v -2.5 -2.5 15
v 2.5 -2.5 15
v 2.5 2.5 15
v -2.5 2.5 15
# 8 verticies
vn 0 0 -1
vn 0 0 1
vn 0 -1 0
vn 1 0 0
vn 0 1 0
vn -1 0 0
# 6 normals
vt 0 0
vt 0 1
vt 1 1
vt 1 0
# 4 texture coordinates
usemtl m1
f 1/1/1 2/2/1 3/3/1
f 3/3/1 4/4/1 1/1/1
usemtl m2
f 5/1/2 6/2/2 7/3/2
f 7/3/2 8/4/2 5/1/2
usemtl m3
f 1/1/3 4/2/3 6/3/3
f 6/3/3 5/4/3 1/1/3
usemtl m1
f 4/1/4 3/2/4 7/3/4
f 7/3/4 6/4/4 4/1/4
usemtl m2
f 3/1/5 2/2/5 8/3/5
f 8/3/5 7/4/5 3/1/5
usemtl m3
f 2/1/6 1/2/6 5/3/6
f 5/3/6 8/4/6 2/1/6 |
g
obj_name:
specify the object name
mtllib filename: specify the
material library file
v x y z: define the position
of a set of vertex.
The first vertex is indexed by 1 and subsequent vertices
are numbered sequentially
# comment: indicate this line
is a comment
vn x y z: define a set of
normal vector.
The first normal vector is indexed by 1 and
subsequent vertices are numbered sequentially
vt u v: define a set of texture
coordinate
usemtl material_name: specify
which material defined
in the material library file you want to use.
f v1/t1/n1 v2/t2/n2 v3/t3/n3:
define a polygon
consisted of 3 vertex.
(v1,v2,v3) is the index of vertex positoin array for
each vertex.
(t1,t2,t3) is the index of texture coordinate array for
each vertex.
(n1,n2,n3) is the index of normal vector array for
each vertex.
|
For more information
about *.obj, see the webpage:
http://netghost.narod.ru/gff/graphics/summary/waveobj.htm
box.mtl
|
Description |
#
Max2Mtl Version 4.0 Mar
newmtl m1
Ka 0.0 0.0 0.0
Kd 1.0 0 1.0
Ks 0.3 0.3 0.3
d 1.0
Ns 2.2
illum 2
newmtl m2
Ka 0.0 0.0 0.0
Kd 0.0 1 0.0
Ks 0.3 0.3 0.3
d 1.0
Ns 2.2
illum 2
newmtl m3
Ka 0.0 0.0 0.0
Kd 0.0 0.0 1.0
Ks 0.3 0.3 0.3
d 1.0
Ns 2.2
illum 2
|
#
comment: indicate this line is a comment
newmtl material_name: create
a new material
Ka r g b: define the AMBIENT
term
Kd r g b: define the DIFFUSE
term
Ks r g b: define the SPECULAR
term
d value: see the reference.
Ns value: define the Phong
specular component.
illum value: see the reference.
|
For more information
about *.mtl, see the webpage:
http://pub33.ezboard.com/fnendowingsmiraifrm19.showMessage?topicID=28.topic
In order to make
you concentrate on writing OpenGL code, we provide a loader to help
you load *.obj file. You can simply add the loader (mesh.cpp,
mesh.h) to your workspace, and use the
class named mesh to load *.obj file.
The class mesh
has members as follows:
Members
|
Description |
class
material {
float Ka[4];
float Kd[4];
float Ks[4];
float Ns;
}
class Vertex {
int v;
int n;
int t;
int m;
}
class Vec3 {
float ptr[3];
}
class FACE {
Vertex v[3];
}
material mat[100];
vector<Vec3> vList;
vector<Vec3> nList;
vector<Vec3> tList;
vector<FACE> faceList;
int vTotal;
int nTotal;
int tTotal;
int fTotal;
|
The material property
The vertex property
v: index of vList
n: index
of nList
t: index
of tList
m: index
of mat[100]
mat[100]: an array of all materials.
vList: an array of all vertex position.
nList: an array of all normal vector.
tList: an array of all texture coordinate.
faceList: an array of all faces (polygons).
vTotal: the number of vertices.
nTotal: the number of normal vectors.
tTotal: the number of texture coordinate.
fTotal: the number of faces. |
So, here is an
example to load an object file:
#include "mesh.h"
mesh *object;
main()
{
object = new mesh("box.obj");
delete object;
}
and
after you loaded the object file, you can use
for (int i=0;i<object->fTotal;i++)
{
for (int j=0;j<3;j++)
{
object->mat[object->faceList[i][j].m].Ka
or object->nList[object->faceList[i][j].n].ptr
or
object->vList[object->faceList[i][j].v].ptr or
......
}
}
to
access each polygon data directly.
**ATTENTION:
If you are using VC++ 6.0, you may encounter about 100+ warning messages
because of the Microsoft bug:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q167355&
So I suggest you to modify your setting
Project->Settings->C/C++->General->Warning
level->None
to get rid of the annoying messages.
Sample
Input:
There are four test
cases. You can download it to test your program. Your program should
be designed as flexible as possible. My suggestion is that you can design
your program to receive two command line arguments as view data file
and scene data file.
**Ex:
prog1.exe box.view box.obj.
¡@
¡@
|