RASTERIZATION Projection Transformation Orthographic Projection Perspective Projection 2

  • Slides: 123
Download presentation

RASTERIZATION

RASTERIZATION

Projection Transformation ทสำคญ แบบ • Orthographic Projection • Perspective Projection 2

Projection Transformation ทสำคญ แบบ • Orthographic Projection • Perspective Projection 2

Orthographic Projection )ตอ ( http: //www 2. arts. ubc. ca/Theatre. Design/crslib/drft_1/orthint. htm

Orthographic Projection )ตอ ( http: //www 2. arts. ubc. ca/Theatre. Design/crslib/drft_1/orthint. htm

Orthographic Projection )ตอ ( http: //www 2. arts. ubc. ca/Theatre. Design/crslib/drft_1/cad/wdstv. htm

Orthographic Projection )ตอ ( http: //www 2. arts. ubc. ca/Theatre. Design/crslib/drft_1/cad/wdstv. htm

การนยาม Orthographic Projection )ตอ ( • Matrix ของ orthographic projection ตองทำอะไรบา – สง –

การนยาม Orthographic Projection )ตอ ( • Matrix ของ orthographic projection ตองทำอะไรบา – สง – สง x = left ไป x = -1 x = right ไป x = 1 y = bottom ไป y = -1 y = top ไป y = 1 z = -far ไป z = 1 z = -near ไป z = -1

Matrix ของ Orthographic Projection

Matrix ของ Orthographic Projection

คำสง Open. GL เกยวกบ Orthographic Projection • gl. Ortho(left, right, bottom, top, near, far)

คำสง Open. GL เกยวกบ Orthographic Projection • gl. Ortho(left, right, bottom, top, near, far) – คณ matrix ปจจบนดวย matrix ของ orthographic projection ในหนากอน – กอนใชควรเรยก gl. Matrix. Mode(GL_PROJECTION) gl. Load. Identity() กอนเพอเปลยน mode และเคลยรคา projection matrix เดม • gl. Ortho 2 D(left, right, bottom, top) – เหมอนกบ เปน 1 gl. Ortho แตใหคา near เปน 0 และ คา far

Perspective Projection )ตอ (

Perspective Projection )ตอ (

Perspective Projection (cont. ) orthographic perspective

Perspective Projection (cont. ) orthographic perspective

การนยาม Perspective Projection • นยามดวยเลข 6 ตวเหมอนกบ projection orthographic

การนยาม Perspective Projection • นยามดวยเลข 6 ตวเหมอนกบ projection orthographic

การนยาม Perspective Projection) ตอ ( • หา x ใน clip space (x, y, z)

การนยาม Perspective Projection) ตอ ( • หา x ใน clip space (x, y, z) (0, 0, 0)

การนยาม Perspective Projection) ตอ ( • กลาวคอ perspective projection matrix จะตองสง ไปยง

การนยาม Perspective Projection) ตอ ( • กลาวคอ perspective projection matrix จะตองสง ไปยง

Matrix ของ Perspective Projection

Matrix ของ Perspective Projection

คำสง Open. GL เกยวกบ Perspective Projection • gl. Frustum(left, right, bottom, top, near, far)

คำสง Open. GL เกยวกบ Perspective Projection • gl. Frustum(left, right, bottom, top, near, far) – คณ matrix ปจจบนดวย projection ในหนากอน – กอนใชควรเรยก matrix ของ perspective gl. Matrix. Mode(GL_PROJECTION) gl. Load. Identity() กอนเพอเปลยน mode และเคลยรคา matrix เดม projection

คำสง Open. GL เกยวกบ Perspective Projection) ตอ ( • glu. Perspective(fovy, aspect, near, far)

คำสง Open. GL เกยวกบ Perspective Projection) ตอ ( • glu. Perspective(fovy, aspect, near, far) – คณ matrix ปจจบนดวย perspective projection matrix เชนเดยวกบ gl. Frustrum – มผลเหมอนกบสง gl. Frustum โดยได • • top = near * tan(fovy / 2) bottom = -top right = aspect * top left = -right

RASTERIZATION

RASTERIZATION

HIDDEN SURFACE REMOVAL

HIDDEN SURFACE REMOVAL

DEPTH BUFFER ใน OPENGL

DEPTH BUFFER ใน OPENGL

เมอ Render โดยไมม Depth Buffer

เมอ Render โดยไมม Depth Buffer

จรงๆ แลว code เปนอยางน gl. Color 3 d(0. 5, 1, 0. 5); gl. Begin(GL_TRIANGLES);

จรงๆ แลว code เปนอยางน gl. Color 3 d(0. 5, 1, 0. 5); gl. Begin(GL_TRIANGLES); gl. Vertex 3 d(0, 0. 5, 0); gl. Vertex 3 d(-0. 5, 0); gl. Vertex 3 d(0. 5, -0. 5, 0); gl. End(); gl. Color 3 d(1, 0. 5); gl. Begin(GL_TRIANGLES); gl. Vertex 3 d(0, -0. 75, 1); gl. Vertex 3 d(0. 40, 0, 1); gl. Vertex 3 d(-0. 40, 0. 30, -1); gl. End();

การใช Depth Buffer ใน GLUT • เวลาสง glut. Init. Display. Mode ใหเพม GLUT_DEPTH ดวย

การใช Depth Buffer ใน GLUT • เวลาสง glut. Init. Display. Mode ใหเพม GLUT_DEPTH ดวย glut. Init. Display. Mode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH) • เรยก gl. Enable(GL_DEPTH_TEST) • เวลาเรยก gl. Clear ใหเพม GL_DEPTH_BUFFER_BIT gl. Clear(GL_COLOR_BUFFER_BIT | GLUT_DEPTH_BUFFER_BIT)

โคดตวอยาง int main(int argc, char **argv) { glut. Init(&argc, argv); glut. Init. Display. Mode(GLUT_RGBA

โคดตวอยาง int main(int argc, char **argv) { glut. Init(&argc, argv); glut. Init. Display. Mode(GLUT_RGBA | GLUT_DOUBLE); glut. Init. Window. Size(600, 600); glut. Create. Window("No Depth Buffering"); glut. Display. Func(display); gl. Enable(GL_DEPTH_TEST); glut. Main. Loop(); return 0; }

ILLUMINATION

ILLUMINATION