Inner Product Dot Product Outer Product Cross Product

  • Slides: 50
Download presentation

벡터 내적과 외적 내적(Inner Product, Dot Product) 외적(Outer Product, Cross Product) 정규화 법선벡터 =정규화

벡터 내적과 외적 내적(Inner Product, Dot Product) 외적(Outer Product, Cross Product) 정규화 법선벡터 =정규화 외적벡터 3

지엘의 후면제거 정규화 가시부피 • 법선벡터의 z 값만으로 판단가능 gl. Enable(GL_CULL_FACE); gl. Cull. Face(GL_BACK);

지엘의 후면제거 정규화 가시부피 • 법선벡터의 z 값만으로 판단가능 gl. Enable(GL_CULL_FACE); gl. Cull. Face(GL_BACK); GL_FRONT_AND_BACK gl. Disable(GL_CULL_FACE); 7

표면과 이면 그리기 모드 void gl. Polygon. Mode(GLenum face, GLenum mode) • face: 작업이

표면과 이면 그리기 모드 void gl. Polygon. Mode(GLenum face, GLenum mode) • face: 작업이 가해질 대상 면 • mode: 그리기 모드 gl. Polygon. Mode(GL_FRONT, GL_FILL); gl. Polygon. Mode(GL_BACK, GL_LINE); • GL_FRONT_AND_BACK gl. Cull. Face(GL_BACK); gl. Cull. Face(GL_FRONT); 면A를 그리지 않았을 때 11

코헨-서더런드 알고리즘 class wc. Pt 2 D { public: GLfloat x, y; }; inline

코헨-서더런드 알고리즘 class wc. Pt 2 D { public: GLfloat x, y; }; inline GLint round (const GLfloat a) { return GLint (a + 0. 5); } /* Define a four-bit code for each of the outside regions of a * rectangular clipping window. */ const GLint win. Left. Bit. Code = 0 x 1; const GLint win. Right. Bit. Code = 0 x 2; const GLint win. Bottom. Bit. Code = 0 x 4; const GLint win. Top. Bit. Code = 0 x 8; 15

코헨-서더런드 알고리즘 inline GLint inside (GLint code) { return GLint (!code); } inline GLint

코헨-서더런드 알고리즘 inline GLint inside (GLint code) { return GLint (!code); } inline GLint reject (GLint code 1, GLint code 2) { return GLint (code 1 & code 2); } inline GLint accept (GLint code 1, GLint code 2) { return GLint (!(code 1 | code 2)); } GLubyte encode (wc. Pt 2 D pt, wc. Pt 2 D win. Min, wc. Pt 2 D win. Max) { GLubyte code = 0 x 00; if (pt. x < win. Min. x) code = code | win. Left. Bit. Code; if (pt. x > win. Max. x) code = code | win. Right. Bit. Code; if (pt. y < win. Min. y) code = code | win. Bottom. Bit. Code; if (pt. y > win. Max. y) code = code | win. Top. Bit. Code; return (code); } 16

코헨-서더런드 알고리즘 void line. Clip. Coh. Suth (wc. Pt 2 D win. Min, wc.

코헨-서더런드 알고리즘 void line. Clip. Coh. Suth (wc. Pt 2 D win. Min, wc. Pt 2 D win. Max, wc. Pt 2 D p 1, wc. Pt 2 D p 2){ GLubyte code 1, code 2; GLint done = false, plot. Line = false; GLfloat m; while (!done) { code 1 = encode (p 1, win. Min, win. Max); code 2 = encode (p 2, win. Min, win. Max); if (accept (code 1, code 2)) { done = true; plot. Line = true; } else if (reject (code 1, code 2)) done = true; else { /* Label the endpoint outside the display window as p 1. */ if (inside (code 1)) { swap. Pts (&p 1, &p 2); swap. Codes (&code 1, &code 2); } 17

코헨-서더런드 알고리즘 /* Use slope m to find line-clip. Edge intersection. */ if (p

코헨-서더런드 알고리즘 /* Use slope m to find line-clip. Edge intersection. */ if (p 2. x != p 1. x) m = (p 2. y - p 1. y) / (p 2. x - p 1. x); if (code 1 & win. Left. Bit. Code) { p 1. y += (win. Min. x - p 1. x) * m; p 1. x = win. Min. x; } else if (code 1 & win. Right. Bit. Code) { p 1. y += (win. Max. x - p 1. x) * m; p 1. x = win. Max. x; } else if (code 1 & win. Bottom. Bit. Code) { /* Need to update p 1. x for nonvertical lines only. */ if (p 2. x != p 1. x) p 1. x += (win. Min. y - p 1. y) / m; p 1. y = win. Min. y; } else if (code 1 & win. Top. Bit. Code) { if (p 2. x != p 1. x) p 1. x += (win. Max. y - p 1. y) / m; p 1. y = win. Max. y; } }} 18

GL의 추가 절단면 제공 gl. Clip. Plane(GLenum plane, GLdouble *equation); gl. Enable(GLenum plane); gl.

GL의 추가 절단면 제공 gl. Clip. Plane(GLenum plane, GLdouble *equation); gl. Enable(GLenum plane); gl. Disable(GLenum plane); • plane: 절단면 식별자 GL_CLIP_PLANE 0~ GL_CLIP_PLANE 5 • equation: 평면을 나타낸는 수식의 계수가 있는 배열명 • Ax+By+Cx+D=0 Face[]={A, B, C, D} • 절단면 외부 물체가 절단되고 남는다 38

지-버퍼 알고리즘 지-버퍼(Z-Buffer) 또는 깊이버퍼(Depth Buffer) 지-버퍼 알고리즘 Initialize Frame Buffer with Background Color;

지-버퍼 알고리즘 지-버퍼(Z-Buffer) 또는 깊이버퍼(Depth Buffer) 지-버퍼 알고리즘 Initialize Frame Buffer with Background Color; Initialize Z Buffer with Infinite Distance; for Each Polygon { for Each Pixel { Calculate z of Intersection if (Calculated z < Current z of Z-Buffer) { Update Z-Buffer with Calculate z; Update Frame Buffer with the Color of Current Polygon; } } } 47