Geometric Objects and Transformations
4. Scalars, Points, and Vectors
Geometric View scalar : a real nmber.7 point : location in space.7,.5,.9 position 만있음. no sie ector : direction magnitde directed line segment 연산법칙 ector point point point point ector ector ector ector
Mathematical View : Space ector space : scalar, ector 가정의됨 scalar-ector mltiplication ector-ector addition ector sm of basis ectors r r r r r w r r r w ai b j r ck affine space : point 개념이들어감 ector-point addition point-point sbtraction p q r r p q Eclidean space : distance 개념이들어감 l
Compter Science View ADT : abstract data tpes C / Jaa class 개념 구현하기쉽고, ADT 개념에최적 we need the operations: scalar :,, point : p, q, r 또는 P, Q, R ector :,, w 4
Operations magnitde of a ector ector-point relationship P Q P Q point-point sbtraction P Q Q R P R 5
Lines line : point, ector 로정의 parametric form affine form d P P 6 Q R Q R Q P Q R Q P Q R P
Coneit cone object object 내의 점을연결한선분이항상 object 내에포함되는 object 수학적표현 P P P P n n,,,, : points L 7 기하학적의미 : shrink wrapping n i P P P P P P P P n i n n n n,,,,,,,, points: L L L L
Prodct dot prodct : 내적 orthogonal : dot prodct 가 인 개의 ector cross prodct : 외적 cos are orthogonal and 8 cross prodct : 외적 right-handed coordinate sstem sin k j i
Planes parametric form line eqation의확장 교재참고 T, P plane eqation n P P n : normal ector P P 9
4. Three-dimensional Primities
Bondar Representation three-dimensional objects cres srfaces olmetric objects efficient wa of representing D objects? 물체의표면 srface 만표현, 내부는비었다고가정 물체의표면은꼭지점 erte 을연결해서표현 물체의표면은 flat cone polgon 으로구성 B-rep bondar representation
4. Coordinate Sstems and Frames
Coordinate Sstem or Frame coordinate sstem : basis ector들로정의 frame : reference point origin 가더필요 실제로는 coordinate sstem 과혼용 basis ectors :,, reference point : P ector : w point : PP η η η [ ]
Coordinate Transform original basis ectors,, new basis ectors,, mapping w 4 M [ ] [ ] [ ] M w
Homogeneos Coordinates ector : matri 로 coordinate transform 가능 point 어떻게 transform 할것인가? w P P η η η 5 어떻게 transform 할것인가? 4 4 matri : homogeneos coordinate 도입 [ ] P P P η η η η η η [ ] P w
Coordinate Transform : Point original frame,,, P new frame,,, Q mapping in new frame frame in original Q P P 6 in new frame Q 4 4 4 Q P 4 4 4 M [ ] [ ] [ ] P P Q M w
Frames in OpenGL two transform matrices world frame camera frame glmatrimodegl_projection object frame world frame glmatrimodegl_modelveiw world frame glmatrimodegl_modelveiw glmatrimodegl_projection camera frame camera 방향 object frame 7
4.4 Modeling a Colored Cbe
Modeling a Cbe erte 정의 GLfloat ertices[8][] { {.,.,. }, // {.,.,. }, // {.,.,. }, // {.,.,. }, // {.,.,. }, // 4 {.,.,. }, // 5 {.,.,. }, // 6 {.,.,. } // 7 }; 7 6 4 5 9
Modeling a Cbe face 정의 glbegingl_polygon; glvertefertices[]; glvertefertices[]; glvertefertices[]; glvertefertices[]; glend ; otward facing normal ector 는항상외부를향한다. right-hand rle 7 6 4 5
Data Strctre erte-list representation 개의 erte 를 개의 face 가공유가능 list 구조 : inde 로 erte 를 share
Color Cbe erte 마다 color 설정 GLfloat colors[8][] { {.,.,. }, // black {.,.,. }, // red {.,.,. }, // ellow {.,.,. }, // green {.,.,. }, // ble {.,.,. }, // magenta {.,.,. }, // white {.,.,. } // can }; 7 6 4 5
Face 출력함수 oid qadint a, int b, int c, int d { glbegingl_polygon; glcolorfcolors[a]; glvertefertices[a]; glcolorfcolors[b]; glvertefertices[b]; glcolorfcolors[c]; glvertefertices[c]; glcolorfcolors[d]; glvertefertices[d]; glend; } /* face 별로출력 */ oid colorcbeoid { qad,,,; qad,,7,6; qad,4,7,; qad,,6,5; qad4,5,6,7; qad,,5,4; }
Bilinear Interpolation face 의각 erte 가서로다른색깔일수도있다. face 전체를어떻게칠할것인가? bilinear interpolation edge 상의점 : linear interpolation C C C C C face 상의점 : 다시 linear interpolation C 45 4 문제점! flatness 가보장되어야한다 C C C 5 4
Scan-line Interpolation flatness 를해결하기위한방법 polgon 을일단 screen 에 project 한후에, bi-linear interpolation 5
Verte Arra object 를 draw 하는과정에서의 bottleneck? 개의 erte 가 번사용된다. erte 정보 : 좌표 개 4 bte / float btes color 정보 : R,G,B 개 4 bte / float btes face 하나출력에총 4 4 btes 96 bte 전송 자료전송을최소화하는방법? client-serer model erte 정보, color 정보를한번만 serer에보낸다 inde 로이를사용 6
Verte Arra enable the erte arra glenableclinetstategl_vertex_array; glenableclientstategl_color_array; color, erte arra 전송 glvertepointer, GL_FLOAT,, ertices; glcolorpointer, GL_FLOAT,, colors; oid glvertepointerglint sie, GLenm tpe, GLsiei stride, const GLoid* pointer; sie : 좌표의수,,4 stride : 건너뛸 bte 수 : tightl packed pointer : 자료의시작위치 7
Verte Arra inde 정보 : 4 indices for 6 faces GLbte cbeindices[4]{,,,,,,7,6,,4,7,,,,6,5, 4,5,6,7,,,5,4 }; 실제 draw gldrawelementsgl_quads, 4, GL_UNSIGNED_BYTE, cbeindices; oid gldrawelementsglenm mode, GLsiei cont, GLenm tpe, const GLoid* indices; mode : GL_POLYGON, GL_QUADS, 8
4.5 Affine Transformations
Transformation transformation transform point / ector 다른 point / ector 로 mapping 하는함수 affine transformation linear fnction 으로제한한경우 homogeneos coordinate 수식으로는 q Ap 4 4 4 p p p
Affine Transformation 특징 linearit 보장 : line 은 transform 후에도 line parallel 한 line들은 transform 후에도 parallel angle presering : 각도는그대로유지됨
4.6 Rotation, Translation, and Scaling
Translation translation : 물체를평행이동 P ' P d 이동전 이동후
Rotation D rotation 원점기준의회전, ' ' cos sin sin cos D rotation a fied point a line : 회전축 rotation angle : 회전각도 4
Scaling 물체의크기를조절 물체의크기를 배 < < : 축소 > : 확대 < : reflection scaling reflection 5
Rigid-bod Transformation rigid-bod transformation : object 의크기가불변 예 : translation, rotation non-rigid-bod transformation : object 크기에변화 예 : scaling rigid-bod transformation non-rigid-bod transformation 6
4.7 Transformations in Homogeneos Coordinates
Translation p : 새로운 point, p : 원래 point ' ' ' ' p p,, ' ', ', 8 translation,, ' T Tp p,, ' T p T p
Scaling,, ' S Sp p,, ' ', ', 9,,,, S S scaling non - niform Otherwise, scaling Uniform
Rotation, D s. D rotation : 회전축을필요로한다 D : 평면이므로, 축이회전축 D : 회전축을임의로설정가능 각좌표축에대한회전 임의의회전축에대한회전 : 뒤에 회전축 4
좌표축중심의 rotation 비교적간단 -ais rotation D 경우와동일 ' ', ', ' p,, p r r 4 cos sin sin cos ' ' ' p R p '
좌표축중심의 rotation -ais rotation cos sin sin cos ' ' ' p R p ' 4 -ais rotation cos sin sin cos ' ' ' p R p '
Rotation 의중요성질 inerse 계산을빨리할수있다 T R R R R sin cos 4 cos sin sin cos cos sin T R R R
Reflection plane :,,,, RF 44 plane :,,,, plane :,,,,
Shearing -ais shearing cot ' ' cot ' 45 cot H H H
4.8 Concatenation of Transformations
Matri Concatenation matri 여러개를곱하는경우 즉, transformation 여러개가적용되는경우 q q CB Ap C B Ap 다른방법 : point 여러개를 transformation 하는경우 graphics package 들이사용중. M CB A q Mp 47
Eample : Rotation abot a line fied point P f 를지나면서 축에평행한 line 을중심으로회전 회전이전 회전이후 48
Eample : Rotation abot a line cos sin cos sin sin cos sin cos f f f f f f f f M p T R p T M 49
General Rotation,, 축의순서로,, 각도씩회전 MR R R 5
Instance Transformation object 를 transformation 시키는일반적인방법 scale, rotate, translate 순서 M T p f R R R S s, s, s 5
General D Rotation 임의의회전축을중심으로 rotation. Translate the object so that the rotation ais passes throgh the origin.. Rotate the object so that the rotation ais coincides with one of the coordinate ais.. Perform the specified rotation. 4. step 의역연산 R 5. step 의역연산 T,,,, 5
Step. Translation a, b, c,, 회전축 : 점,, 을지나고, 기울기가 a, b, c 인직선 5,, T
Step. align with -ais / a, b, c, b, c ' 54,, '' a,, d d a d c d b d b d c R d b d c sin ' ' cos cos ' ' b c b c
Step. align with -ais /,, 55 '' a,, d d a d '' '' cos a a d a sin '' sin sin '' '' d a a d R
Step. align with -ais / 정리하면, 벡터를 -ais 에일치시키는연산은 d b d c a d R R 56 R R 의역연산은나중에사용 R R d c d b d a R R
Step. Rotate abot -ais 57 cos sin sin cos R
Step 4, 5: 원상복귀 step 4: step 5: 정리하면, R R T 58 P R P T R R R R R T R '
4.9 OpenGL Transformation Matrices
CTM crrent transformation matri : OpenGL 에서관리 object frame 기준 전처리 후처리 camera frame 기준 world frame camera frame camera 방향 object frame 6
OpenGL CTM matri model-iew : world frame 까지변환 affine projection : camera frame 으로변환 non-affine erte C camera projection C modeliew erte object 6
CTM 관련연산들 matri 선택 glmatrimodegl_modelview; C C projection or C modeliew C I glloadidentit ; C CT gltranslateft, t, t; C CS glscalefs, s, s; C CR glrotatefdegree,,, ; C M glloadmatrifmatri; C CM glmltmatrifmatri; 현재 matri 보관 glpshmatri ; 보관했던 matri 복귀 glpopmatri ; 6
Eample : Spinning Cbe register callbacks in main gltdisplafncdispla; gltidlefncspincbe; gltmosefncmose; mose callback : btton 에따라, 회전축교체 static GLint ais ; // ais oid moseint btn, int state, int, int { if state GLUT_DOWN { if btnglut_left_button ais ; // ais if btnglut_middle_button ais ; // ais if btnglut_right_button ais ; // ais } } 6
Eample : Spinning Cbe idle callback : 현재회전축의회전각도증가 static GLfloat theta[] {.,.,. }; oid spincbeoid { } theta[ais].; if theta[ais] > 6. theta[ais] 6.; gltpostredispla; 64
Eample : Spinning Cbe displa callback rotate the cbe, draw, and swap bffers oid displaoid { glcleargl_color_buffer_bit GL_DEPTH_BUFFER_BIT; glloadidentit; glrotateftheta[],.,.,.; glrotateftheta[],.,.,.; glrotateftheta[],.,.,.; colorcbe; glflsh; gltswapbffers; } 65
4. Interfaces to D Applications
Simple Screen-based Approach 문제점 : too man control parameters 회전각 : 각축마다하나씩 위치 : translate ector 입력도가능 bt, mose btton 은 ~ 개뿐 해결책 a poor interface screen 전체를 inpt pad 로사용, 축중심으로 만큼회전 축중심으로 만큼회전 67
Virtal Trackball Approach mose 가화면상에서 drag irtal trackball 영역 dragging 화면상에서 프로그램의해석 68
Virtal Trackball Approach ector n 을중심으로각도 만큼회전 n p p sin n qaternion approach 의기본개념 dragging 끝점 dragging 시작점 69