๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŒด Course Review (Master)/๐Ÿš‘ ์ปดํ“จํ„ฐ ๊ทธ๋ž˜ํ”ฝ์Šค

Primitive Transformation ์„ฑ์งˆ ๋ถ„์„ํ•˜๊ธฐ

by UKHYUN22 2024. 3. 4.
728x90

์œ„์˜ ๊ธ€์„ ํ†ตํ•ด Cartesian Coordinate ๋Œ€์‹ 
Homogeneous Coordinate๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ์— ๋Œ€ํ•ด์„œ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

ํ‘œํ˜„ํ•˜๊ณ ์ž ํ•˜๋Š” Transformation์˜ ๊ฒฝ์šฐ Primitive Transformation (Translation, Rotation, Scaling)
์œผ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ž„์˜์˜ ์ง€์  P1์— ๋Œ€ํ•˜์—ฌ Rotation์„ ์ ์šฉํ•˜๋Š” ๊ฒฝ์šฐ
์ด๋ฅผ ์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ๊ฐ„์†Œํ™”ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?

ํ•ด๋‹น ์ง€์ ์€ ์›์ ์œผ๋กœ Translation์„ ํ•œ ๋’ค ํšŒ์ „ํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฐ๋„ θ ๋งŒํผ ํšŒ์ „์‹œํ‚ค๊ณ 
๋‹ค์‹œ ์›๋ž˜์˜ ์ง€์ ์œผ๋กœ Translation์„ ํ•œ๋‹ค๋ฉด ๊ธฐ์กด์˜ Primitiveํ•œ ์„ฑ์งˆ์„ ๋ชจ๋‘ ๋งŒ์กฑ์‹œํ‚ฌ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

 

๊ทธ๋ ‡๋‹ค๋ฉด ๊ธฐ๋ณธ์ ์ธ ์ถ• (x-axis, y-axis)์ด ํšŒ์ „๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ Scaling์ด ์ด๋ฃจ์–ด์ง€๋Š” ๊ฒฝ์šฐ

์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ์š”?

Original ์ถ•์œผ๋กœ๋ถ€ํ„ฐ ํšŒ์ „ํ•œ ๊ฐ๋„ θ๋ฅผ ๋ฐ˜๋Œ€๋กœ ํšŒ์ „์‹œ์ผœ ์›์ ์œผ๋กœ ๋ณต๊ตฌ ์‹œํ‚จ ๋’ค Scaling์„ ์ง„ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜์˜ ๊ทธ๋ฆผ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

๋‹ค์Œ์œผ๋กœ ์•Œ์•„๋ณผ ๊ฒƒ์€ Shear Transformation์ž…๋‹ˆ๋‹ค.

์•„๋ž˜์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์›๋ž˜์˜ ์ด๋ฏธ์ง€๊ฐ€ ๊ฐ ์ถ•์— ๋Œ€ํ•˜์—ฌ ๊ธฐ์šธ์–ด์ ธ ํ‘œํ˜„๋˜๋Š” ๋ณ€ํ™˜์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด Shear Transformation์€ Primitive Transformation์„ Concatenation์œผ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?

์ด ์ฆ๋ช…์€ ์—ฌ๋Ÿฌ๋ถ„๊ป˜ ๋งก๊ฒจ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

Composition of Primitive Transformation์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

Original house ๋ฌผ์ฒด๋ฅผ P1์—์„œ P2๋ผ๋Š” ์ง€์ ์œผ๋กœ ์˜ฎ๊ธฐ๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. 

Primitive Transformation์œผ๋กœ ์–ด๋–ป๊ฒŒ ํ‘œํ˜„ํ•˜๋Š”์ง€ ๋ด…์‹œ๋‹ค.

Original house๋ฅผ ์›์ ์œผ๋กœ Transform ํ•˜๊ณ  Scaling์„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์›ํ•˜๋Š” ํšŒ์ „ ๊ฐ๋„๋งŒํผ

ํšŒ์ „ ์‹œํ‚จ ํ›„ P2 ์œ„์น˜๋กœ Transformation ํ•ฉ๋‹ˆ๋‹ค.

 

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฒƒ์€ 3x3 Matrix์—์„œ ๊ฐ ์Šค์ผ€์ผ ์ƒ์ˆ˜ ๊ฐ’์ด ์–ด๋–ค ๋ณ€ํ™˜์„ ๋Œ€ํ‘œํ•˜๋Š”์ง€ 

์ง๊ด€์ ์œผ๋กœ ๋Š๋ผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Diagonal (r11, r22)  : Scaling Value

Counter Diagonal (r12, r21) : Shearing Value

3 Column value : Translation Value

3 Row value : Homogeneous Coordinate Value

 

Rigid-body Transformation์ด๋ž€ Shape์ด ๋ณ€ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด Transformation Matrix๋งŒ ๋ณด๊ณ  Rigid-Body์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์„๊นŒ์š”?

๋ฐฉ๋ฒ•์€ (r11,r12)์™€ (r21,r22) ํ–‰๋ ฌ์ด Orthonomal Vector์ธ์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•˜๊ฒŒ ๋‚ด์ ๊ฐ’์ด 0์ธ์ง€ ์•„๋‹Œ์ง€ ํ™•์ธํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

Affine Transformation์ด๋ž€ ํ‰ํ–‰์ด ๋ณด์กด๋˜๋Š” ๋ณ€ํ™˜์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฅผ ์ฆ๋ช…ํ•˜๋Š” ๊ฒƒ๋„ ์—ฌ๋Ÿฌ๋ถ„๊ป˜ ๋งก๊ฒจ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

 

 

๊ทธ๋ ‡๋‹ค๋ฉด ์ด๋Ÿฌํ•œ ๋ณ€ํ™˜์„ ํ†ตํ•ด์„œ ์›€์ง์ด๋Š” Object๋ฅผ ์–ด๋–ป๊ฒŒ ํ‘œํ˜„ํ•ด์•ผ ํ• ๊นŒ์š”?

์ผ์ผ์ด ํ•˜๋‚˜์”ฉ ๋‹ค ํ‘œํ˜„ํ•ด์•ผ ํ•˜๋Š” ๊ฑธ๊นŒ์š”?

Vertex Coordinate Update ์ ‘๊ทผ ๋ฐฉ์‹์— ์˜ํ•˜๋ฉด, ๋งค Frame๋งˆ๋‹ค World Coordinate ์ขŒํ‘œ์˜ ์›€์ง์ž„์„

์‚ฌ์šฉ์ž๊ฐ€ ์ผ์ผ์ด ๋ฐ˜์˜ํ•ด์ค˜์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

 

๋ฌผ๋ก  Homogeneous Coordinate ๋ฐฉ์‹์„ ์ฑ„ํƒํ•จ์— ๋”ฐ๋ผ ์—ฐ์‚ฐ๋Ÿ‰์ด ์ค„์–ด๋“  ๊ฒƒ์€ ์‚ฌ์‹ค์ž…๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์—ฌ๋Ÿฌ ๋‹จ์ ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

์ฒซ ๋ฒˆ์งธ๋กœ ๋งค ์›€์ง์ž„์„ ๊ณ„์†ํ•ด์„œ Frame์— ์ฐ์–ด์ค˜์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด์ง€์š”.

๋‘ ๋ฒˆ์งธ๋กœ๋Š” API ๋ฅผ ์ •์˜ํ•˜๊ธฐ ์–ด๋ ต๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Object์˜ ์ขŒํ‘œ๋ฅผ Pointer๋กœ ๊ณ„์†ํ•ด์„œ

๋ณด๋‚ด์ค˜์•ผ ํ•˜๋Š” Overhead๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

์„ธ ๋ฒˆ์งธ๋กœ๋Š” GPU Utilization ๊ด€์ ์—์„œ ๊ณผ์—ฐ ์ด๊ฒƒ์ด GPU๋ฅผ ์–ผ๋งˆ๋‚˜ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ€์— ๋Œ€ํ•œ

๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ์ปดํ“จํ„ฐ ๊ตฌ์กฐ์—์„œ๋„ Memory Utilization์„ ๋†’์ด๊ธฐ ์œ„ํ•ด Cache๋ฅผ ๋„์ž…ํ•˜๊ณ  ์—ฌ๋Ÿฌ Instruction Rule์„ ๋งŒ๋“ค์—ˆ๋Š”์ง€๋ฅผ ์ƒ๊ฐํ•ด๋ณด๋ฉด ์œ„ ๊ด€์ ์€ ๊ต‰์žฅํžˆ ๋น„ํšจ์œจ์ ์ธ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

Concatenate Primitive Transformation์˜ ์ ‘๊ทผ ๋ฐฉ์‹์„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

glVertex์˜ ์ขŒํ‘œ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” Image๋ฅผ ๊ทธ๋ฆฌ๋Š”๋ฐ ๋ฐ”๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค.

Transformation Matrix๋กœ ๊ฐ ๋ณ€ํ™˜ ์„ฑ์งˆ์„ Matrix์— ๋ฐ˜์˜ํ•˜์—ฌ ์ ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

OpenGL์˜ ๊ฒฝ์šฐ Primitive Transformation ํ•จ์ˆ˜๋Š” glTranslatef, glRotatef, glScalef๋กœ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.