250 likes | 361 Views
Assignment 1. Projection, HSR, and Shading. Description. To implement an OpenGL program that does viewing transform , viewing projection , Z buffer , and Gouraud shading based on Phong model. Need to read two kinds of data: Viewing data (*.view) Object data(*.obj). A simple view data.
E N D
Assignment 1 Projection, HSR, and Shading
Description • To implement an OpenGL program that does viewing transform, viewing projection, Z buffer, and Gouraud shading based on Phong model. • Need to read two kinds of data: • Viewing data (*.view) • Object data(*.obj)
A simple view data light -100 -100 100 0 0 0 0.8 0.3 0.8 0.8 0.8 0.8 light 100 100 100 0 0 0 0.2 0.2 0.5 0.8 0.8 0.8 ambient 1 1 0 eye 11.32 -9.23 19.69 vat 0 0 12.5 vup -0.62 0.51 0.6 fovy 45 dnear 10 dfar 1000 viewport 0 0 400 400
Viewing Data 1/5 • Describes lights, viewing parameters, viewport information. • view coordinate system is a right-handed coordinate system. • the viewing direction is negative Z direction in view coordinate system. • the projection is perspective.
Viewing Data 2/5 • light x y z ar ag ab dr dg db sr sg sb • x y z: light position • ar ag ab: light AMBIENT property • dr dg db: light DIFFUSE property • sr sg sb: light SPECULAR property. • There might be multiple light sources.
Viewing Data 3/5 • ambient r g b • r g b : the GLOBAL AMBIENT term • eye x y z • x y z : 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
Viewing Data 4/5 • 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.
Viewing Data 5/5 • viewport x y width height • x y : The lower left corner of the viewport rectangle. • width: viewport width • height: viewport height
A simple object data 1/3 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
A simple object data 2/3 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
A simple object data 3/3 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
Object data 1/5 • Define a set of polygon • each polygon could have its own material property specified by a material name defined in the material library file (*.mtl).
Object data 2/5 • 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
Object data 3/5 • #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
Object data 4/5 • 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
Object data 5/5 • 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 position 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. • http://netghost.narod.ru/gff/graphics/summary/waveobj.htm
A simple material data # Max2Mtl Version 4.0 Mar 10th, 2001 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.1 0.1 0.1 Kd 0.0 1 0.0 Ks 0.3 0.3 0.3 d 1.0 Ns 2.2 illum 2
Material data 1/4 • #comment • indicate this line is a comment • newmtl material_name • create a new material
Material data 2/4 • Ka r g b • define the AMBIENT term • Kd r g b • define the DIFFUSE term • Ks r g b • define the SPECULAR term
Material data 3/4 • d value • Dissolve value. Values from 0~1. • 0 is completely transparent • 1 is opaque • Ns value • define the Phong specular component.
Material data 4/4 • illum value • 0 to disable lighting • 1 for ambient & diffuse only • 2 for full lighting • http://p212.ezboard.com/fnendowingsmiraifrm19.showMessage?topicID=28.topic
Requirement 1/3 • Load the object data and the view data, then write an OpenGL program to draw the object. • We provide a loader to help you load *.obj file. You can add the loader (mesh.cpp, mesh.h ) into your work space, and use the class named mesh to load *.obj file.
Requirement 2/3 • We have some test cases. Your program should be designed as flexible as possible. • Suggestion: receive 2 command line arguments as view data & object data • Ex: prog1.exe box.view box.obj
Requirement 3/3 • At last 5 hotkey: • Press ‘w’ : increase the z value of camera position • Press ‘s’ : decrease the z value of camera position • Press ‘d’ : increase the x value of camera position • Press ‘a’ : decrease the x value of camera position • Press ‘q’ : quit the program
Bonus • More hotkey: • Change light source, change model… • Design mouse function: • Rotate viewport… • Else…