Reall: Fntion Calls to Create Transform Matries Previosl made fntion alls to generate 44 matries for identit, translate, sale, rotate transforms Pt transform matri into CTM Eample mat4 m = Identit(; CTM Matri
Arbitrar Matries Can mltipl b matries from transformation ommands (Translate, Rotate, Sale into CTM Can also load arbitrar 44 matries into CTM Load into CTM Matri 34 2 24 5 3 3 2 2
Matri Staks CTM is atall not jst matri bt a matri STACK Mltiple matries in stak, rrent matri at top Can save transformation matries for se later (psh, pop E.g: Traversing hierarhial data strtres (Ch. 8 Pre 3. OpenGL also maintained matri staks Right now jst implement level CTM Matri stak later for hierarhial transforms
Reading Bak State Can also aess OpenGL variables (and other parts of the state b qer fntions glgetintegerv glgetfloatv glgetbooleanv glgetdoblev glisenabled Eample: to find ot maimm nmber of tetre nits glgetintegerv(gl_max_texture_units, &MaTetreUnits;
Using Transformations Eample: se idle fntion to rotate a be and mose fntion to hange diretion of rotation Start with program that draws be as before Centered at origin Sides aligned with aes
Reall: main. void main(int arg, har **argv { gltinit(&arg, argv; gltinitdisplamode(glut_double GLUT_RGB GLUT_DEPTH; gltinitwindowsie(5, 5; gltcreatewindow("olorbe"; gltreshapefn(mreshape; } gltdisplafn(displa; gltidlefn(spincbe; gltmosefn(mose; glenable(gl_depth_test; gltmainloop(; Calls spincbe ontinosl Whenever OpenGL program is idle
Reall: Idle and Mose allbaks void spincbe( { theta[ais] += 2.; if( theta[ais] > 36. theta[ais] -= 36.; gltpostredispla(; } void mose(int btton, int state, int, int { if(btton==glut_left_button && state == GLUT_DOWN ais = ; if(btton==glut_middle_button && state == GLUT_DOWN ais = ; if(btton==glut_right_button && state == GLUT_DOWN ais = 2; }
Displa allbak void displa( { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT; tm = RotateX(theta[]*RotateY(theta[] *RotateZ(theta[2]; gluniformmatri4fv(matri_lo,,gl_true,tm; gldrawarras(gl_triangles,, N; gltswapbffers(; } Alternativel, we an send rotation angle +ais to verte shader, Let shader form CTM then do rotation Ineffiient: if mesh has, verties eah one forms CTM, redndant!!!!
Using the Model view Matri In OpenGL the model view matri sed to Transform 3D models (translate, sale, rotate Position amera (sing LookAt fntion (net The projetion matri sed to define view volme and selet a amera lens (later Althogh these matries no longer part of OpenGL, good to reate them in or appliations (as CTM
3D? Interfaes Major interative graphis problem: how to se 2D devies (e.g. mose to ontrol 3D objets Some alternatives Virtal trakball 3D inpt devies sh as the spaeball Use areas of the sreen Distane from enter ontrols angle, position, sale depending on mose btton depressed
Compter Graphis 473 Letre : Rotations and Matri Conatenation Prof Emmanel Ag Compter Siene Dept. Worester Poltehni Institte (WPI
Reall: 3D Translate Eample Eample: If we translate a point (2,2,2 b displaement (2,4,6, new loation of point is (4,6,8 objet Translation of objet 8 6 4 6 4 2 2 2 2 Translate(2,4,6 Translation Matri Original point Translated point Translated : 2 + 2 = 4 Translated : 2 + 4 = 6 Translated : 2 + 6 = 4
Reall: 3D Sale Eample If we sale a point (2,4,6 b saling fator (.5,.5,.5 Saled point position = (, 2, 3 6 4 2.5.5.5 3 2 Sale Matri for Sale(.5,.5,.5 Saled : 2.5 = Saled : 4.5 = 2 Saled : 6.5 = 3 Saled point Original point
Nate Robbins Translate, Sale Rotate Demo
Rotating in 3D Man degrees of freedom. Rotate abot what ais? 3D rotation: abot a defined ais Different transform matri for: Rotation abot ais Rotation abot ais Rotation abot ais +
Rotating in 3D New terminolog X roll: rotation abot ais Y roll: rotation abot ais Z roll: rotation abot ais Whih wa is +ve rotation Look in ve diretion (into +ve arrow CCW is +ve rotation +
Rotating in 3D
Rotating in 3D For a rotation angle, abot an ais Define: os sin s s s R -roll or (RotateX
Rotating in 3D s s R -roll (or RotateY s s R -roll (or RotateZ Rles: Write in rotation row, olmn Write in the other rows/olmns Write,s in ret pattern
Eample: Rotating in 3D Qestion: Using -roll eqation, rotate P = (3,,4 b 3 degrees: Answer: = os(3 =.866, s = sin(3 =.5, and M m m m 2 3 m m m 2 22 32 m m m 3 23 33 m m m 4 24 34 Line : 3. +. + 4.s +. = 3.866 + 4.5 = 4.6
3D Rotation Rotate(angle,,, : rotate b angle β abot an arbitrar ais (a vetor passing throgh origin and (,, Note: Anglar position of speified as aimth/longitde (Θ and latitde (φ (,, Origin P Q β
Approah : 3D Rotation Abot Arbitrar Ais Can ompose arbitrar rotation as ombination of: X roll (b an angle β Y roll (b an angle β 2 Z roll (b an angle β 3 M R ( 3 R ( 2 R ( Read in reverse order
Approah : 3D Rotation sing Eler Theorem Classi: se Eler s theorem Eler s theorem: an seqene of rotations = one rotation abot some ais Want to rotate abot arbitrar ais throgh origin Or approah:. Use two rotations to align and ais 2. Do roll throgh angle 3. Negate two previos rotations to de align and ais
Approah : 3D Rotation sing Eler Theorem Note: Anglar position of speified as aimth (Θ and latitde (φ First tr to align with ais
Approah : 3D Rotation sing Eler Theorem Step : Do roll to line p rotation ais with plane ( R Θ
Approah : 3D Rotation sing Eler Theorem Step 2: Do roll to line p rotation ais with ais R ( R ( φ
Approah : 3D Rotation sing Eler Theorem Remember: Or goal is to do rotation b β arond Bt ais is now lined p with ais. So, Step 3: Do roll b β arond ais R ( R ( R ( β
Approah : 3D Rotation sing Eler Theorem Net 2 steps are to retrn vetor to original position Step 4: Do roll in plane φ ( ( ( ( R R R R
Approah : 3D Rotation sing Eler Theorem Step 5: Do roll to retrn to original position Θ ( ( ( ( ( ( R R R R R R
Approah 2: Rotation sing Qaternions Etension of imaginar nmbers from 2 to 3 dimensions Reqires real and 3 imaginar omponents i, j, k q=q +q i+q 2 j+q 3 k Qaternions an epress rotations on sphere smoothl and effiientl
Approah 2: Rotation sing Qaternions Derivation skipped! Chek answer Soltion has lots of smmetr ( ( ( ( ( ( ( ( ( ( 2 2 2 s s s s s s R os sin s Arbitrar ais
Inverse Matries Can ompte inverse matries b general formlas Bt some eas inverse transform observations Translation: T - (d, d, d = T( d, d, d Saling: S (s, s, s = S ( /s, /s, /s Rotation: R (q = R( q Holds for an rotation matri
Instaning Dring modeling, often start with simple objet entered at origin, aligned with ais, and nit sie Can delare one op of eah shape in sene E.g. delare mesh for soldier, 5 instanes to reate arm Then appl instane transformation to its verties to Sale Orient Loate
Referenes Angel and Shreiner, Chapter 3 Hill and Kelle, Compter Graphis Using OpenGL, 3 rd edition