Assignment 2 Phase 1
description
Transcript of Assignment 2 Phase 1
![Page 1: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/1.jpg)
Assignment 2 Phase 1
TransformationBack-face culling
View frustum culling
![Page 2: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/2.jpg)
Outline
Implement the transformation. Modelview transformation Projection transformation Perspective division Viewport transformation
Implement back-face culling. Bonus: Implement view frustum culling.
![Page 3: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/3.jpg)
Input and Output
Input: *.view *.obj *.mtl Same as assignment 1
Output: Wireframe of the obj with back-face culling
![Page 4: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/4.jpg)
Transformation 1/3
ModelviewMatrix
ModelviewMatrix
ViewportTransformation
ViewportTransformation
ProjectionMatrix
ProjectionMatrix
PerspectiveDivision
VertexVertex
Vertex = Projection * Modelview * Vertex ;
Vertex.xyzw /= Vertex.w;
Vertex = Viewport * Vertex;
![Page 5: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/5.jpg)
Model view
N = (eye - at)/|eye - at|; V = up – (N•up)N; |up| = 1.0
U = V x N ;
gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble atx, GLdouble aty, GLdouble atz,
GLdouble upx, GLdouble upy, GLdoubpe upz );
![Page 6: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/6.jpg)
Model view
Modelview = BT
![Page 7: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/7.jpg)
Projection gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdo
uble far );
![Page 8: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/8.jpg)
Projection
n=near; f=far; t=n*tan( fovy *PI / 180.0 /2); b= -t; r= t* aspect; l= -r;
![Page 9: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/9.jpg)
Projection
Projection = NSH
=
![Page 10: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/10.jpg)
Perspective Division
x /= w; y /= w; z /= w; w /= w;
![Page 11: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/11.jpg)
View Port
Viewport = TS From [-1 , 1 ] to [0 , width (or height) ]
1000
0100
2/010
2/001
height
width
T
1000
0100
002/0
0002/
height
width
S
![Page 12: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/12.jpg)
Back-face culling You can perform
back-face culling in World cord.
View cord.
ZN < 0
Window cord. Clock wise
0NV
Back face
1
3 2
![Page 13: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/13.jpg)
View frustum culling
eliminate the polygon that complete outside the view frustum.
Bonus: view frustum clipping Remove the part of polygon that
outside the view frustum.
![Page 14: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/14.jpg)
How to draw wireframe? Render the image using
glBegin(GL_LINE_LOOP);glVertex2i(x,y);…glEnd();
![Page 15: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/15.jpg)
What to do in reshape function?void GL_reshape(GLsizei w, GLsizei h){
glViewport(viewport->x, viewport->y, viewport->width, viewport->height);
glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(viewport->x, viewport->width,
viewport->y, viewport->height);glMatrixMode(GL_MODELVIEW);glLoadIdentity();
}
![Page 16: Assignment 2 Phase 1](https://reader036.fdocuments.us/reader036/viewer/2022062423/56814d51550346895dba87fd/html5/thumbnails/16.jpg)
UI requirement
Show an input command line. “Please input the file name.” If I type “box”, then read box.obj and b
ox.view etc.