10
Sun-Jeong Kim 다각형 그리기 4 th Week, 2008 Computer Graphics 2 Data Structure

다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Sun-Jeong Kim

다각형 그리기

4th Week, 2008

Computer Graphics2

Data Structure

Page 2: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics3

Window Procedure

Computer Graphics4

Drawing a Triangle

Page 3: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics5

실행 결과 (1)

Computer Graphics6

Scan-Line Polygon-Fill Algorithm (1)

Interior pixels along a scan line passing through a polygon fill area

Shortening of an edge

Page 4: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics7

Scan-Line Polygon-Fill Algorithm (2)

A sorted edge table

Computer Graphics8

삼각형의 경우 (1)

Inside-outside test 필요 없음!

Shortening of edges 필요!!

A sorted edge table 생성

(x0, y0)

(x1, y1)

(x2, y2)

Scan-LineNumber

y0 y1 x0 1/m01 y2’ x0 1/m02

y2 y1 x2 1/m21

y0

y2

y2’

y1

Page 5: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics9

삼각형의 경우 (2)

여러분이 구상한 알고리즘이 다음의 삼각형들에대해서도 적용 가능한가?

(x0, y0)

(x1, y1)

(x2, y2)

(x0, y0)

(x1, y1)

(x2, y2) (x1, y1)

(x0, y0)(x2, y2)

Computer Graphics10

예제 – 구조체 정의 변경 (1)

Page 6: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics11

예제 – 구조체 정의 변경 (2)

Computer Graphics12

예제 – 구조체 정의 변경 (3)

Page 7: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics13

Windows 2000/XP 이상의 OS에서 동작

Computer Graphics14

예제 – DrawScene( ) 함수 수정

Page 8: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics15

실행 결과 (2)

Computer Graphics16

연습 문제 (1)

Scanline polygon-filling 알고리즘을 완성해오시오.

마우스 클릭이나 드래그를 이용하여 삼각형의 점들을 입력 받으시오.

Page 9: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics17

사각형의 경우

Inside-outside test 필요 없음! 단, 예외 처리!!

Shortening of edges 필요!!

A sorted edge table 생성

(x0, y0)

(x1, y1)

(x3, y3)

Scan-LineNumber

y0 y1’ x0 1/m01 y3’ x0 1/m03

y1 y2 x1 1/m12

y0

y3

y3’

y2

y1

y1’

(x2, y2)y3 y2 x3 1/m32

Computer Graphics18

연습 문제 (2) – 필수 사항

직사각형(MyRect)을 위한 구조체를 정의하시오.점 2개 (Top-left와 bottom-right)

그리는 멤버 함수 (선 또는 내부 채색)

일반적인 볼록 사각형(MyQuad)를 위한 구조체를정의하시오.

점 4개

그리는 멤버 함수 (선 또는 내부 채색)

Page 10: 다각형그리기graphics.hallym.ac.kr/teach/2008/cg/src/07prac.pdf · 2008. 9. 16. · 7 Computer Graphics Scan-Line Polygon-Fill Algorithm (2) A sorted edge table 8 Computer Graphics

Computer Graphics19

연습 문제 (2) – 선택 사항

오목 사각형의 내부를 채색하는 함수를 구현하시오.

꼬인 사각형의 내부를 판별하고, 채색하는 함수를구현하시오.

마우스 클릭이나 드래그를 이용하여 직사각형과일반적인 사각형의 점들을 입력 받으시오.