Projecion & Ineracion Algebra of projecion Canonical viewing volume rackball inerface ransform Hierarchies Preview of Assignmen #2 Lecure 8 Comp 236 Spring 25 Projecions Our lives are grealy simplified by he fac ha viewing ransformaions ransform he eye o he origin and he look-a direcion (opical axis) o a specified coordinae axis. his reduces he range of projecion marices. A projecion maps all 3-D coordinaes ono a desired viewing plane. hus, making our 3-D ino a 2-D image. his sor of mapping is no affine like all of he ransforms we ve discussed hus far. In fac, projecion marices do no ransform poins from our affine space back ino he same space. hey ransform poins ino somehing differen. Usually, we will use a projecion marix o reduce he dimensionally of our affine poins. hus, we should expec projecion marices o be less han full rank. 2/4/25 Lecure 9 2 Orhographic Projecion he simples form of projecion, is o simply projec all poins along lines parallel o he z-axis. his form of projecion is called orhographic or parallel. I is he ommon form of projecion used by drafs people for op, boom, and side views. he advanage of parallel projecion is ha he you can make accurae easuremens of image feaures in he wo dimensions ha remain. he isadvanage is ha he images don appear naural (i.e. hey lack perspecive oreshorening). ere is an example of an parallel rojecion of our scene. oice ha he parallel lines of he iled floor remain parallel fer orhographic projecion. Orhographic Projecion he projecion marix for orhographic projecion is very simple x y z x y z here are some problems wih his simple form, however. o begin wih he unis of he ransformed poins are sill he same as he model. his is grea for drafing, bu in our case we d like o unis ha are model-independen. his will allow us o perform a wide range of operaions using normalized coordinaes.
Normalized Device Coordinaes herefore we will compose our projecion wih a se of scale and a ranslaion ha maps our coordinaes in unis o normalized device coordinaes. Orhographic Projecions o NDC Here is he mapping: x y z righ 2 lef Some saniy checks: x lef x op boom 2 far 2 (righ lef ) righ lef (op boom) op boom (far ) far righ lef righ lef righ 2 lef lef righ lef righ lef x y z We also scale he z coordinae in exacly he same way (i.e. all z values beween and far are mapped from o respecively). echnically, his coordinae is no par of he projecion. Bu, we will use his value of z for oher purposes. x righ x 2 righ lef righ lef righ righ lef righ lef righ lef 2/4/25 Lecure 9 5 2/4/25 Lecure 9 6 Orhographic Projecion in OpenGL his marix is consruced by he following OpenGL call: void glorho(double lef, double righ, double boom, double op, double, double far ); And he 2-D version (anoher GL uiliy funcion): Perspecive Projecion Ariss (Donaello, Brunelleschi, Durer, and Da Vinci) during he renaissance discovered he imporance of perspecive for making images appear realisic. his oudaes mahemaicians by more han 3 years. Perspecive causes objecs er o he viewer o appear larger han he same objec would appear farher away. Anoher for inroducing homogenous coordinaes o compuer graphics was o accomplish perspecive projecions using li operaors. void gluorho2d( double lef, GLdouble righ, double boom, GLdouble op); Which is jus a call o glorho( ) wih - and far ;
Signs of Perspecive Noice how lines known o be parallel in image space appear o converge o a single poin when viewed in perspecive. his is an imporan aribue of lines in projecive spaces, hey always inersec a a poin. Perspecive Projecion he simples ransform for perspecive projecion is: wx wy w x y z We hen apply our rules for a projecive spaces, o find our preferred poin (he one wih a fourh componen of ) by dividing each elemen of he vecor by w. In his example projecion marix, w is simply he z componen. 2/4/25 Lecure 9 9 2/4/25 Lecure 9 Normalized Perspecive As in he orhographic case, perspecive projecion preserves he unis of -space. Once again, o simplify laer operaions we would like o specify a perspecive projecion where some specific range of -space coordinaes are mapped o a Normalized coordinae sysem. NDC Perspecive Marix his can be accomplished wih a clever composiion of ransforms wih our projecion marix. wx wy wz w righ 2 lef (righ lef ) righ lef (op boom) op 2 boom op boom far far 2 far far x y z he values of lef, righ, op, and boom are specified a he deph. Le s ry some saniy checks: (righ lef ) x lef 2 righ lef lef righ lef x z x righ x z 2 righ (righ lef ) righ lef righ lef
NDC Perspecive Marix his can be accomplished wih a clever composiion of ransforms wih our projecion marix. wx wy wz w righ 2 lef (righ lef ) righ lef (op boom) op 2 boom op boom far far 2 far far x y z he values of lef, righ, op, and boom are specified a he deph. Le s ry some saniy checks: 2 far far far far z far z far far ( far ) far far far z z far 2 far far ( far ) far far 2/4/25 Lecure 9 3 Perspecive in OpenGL OpenGL provides he following funcion o define perspecive ransformaions: void glfrusum(double lef, double righ, double boom, double op, double, double far); Some hink ha using glfrusum( ) is noninuiive. So OpenGL provides a uiliy funcion wih simpler, bu less general capabiliies. void gluperspecive(double verfov, double aspec, double, double far); 2/4/25 Lecure 9 4 gluperspecive() he following figure illusraes he parameers of gluperspecive(): Subsiuing he exens ino glfrusum() Simple camera-like model Can only specify symmeric frusums. Skewed Frusums here are many cases when a skewed frusum is he only way o ge he job done Sereo viewing on a single muliplexed display (non HMD) racked viewer (even for mono viewing) Fixed viewpor moving viewer lef righ far wx wy wz w verfov CO( ) 2 aspec CO( verfov 2 ) far far 2 far far x y z
Exercise: A rackball Inerface A common UI for manipulaing objecs Virual rackball 2 degree of freedom device However, is differenial behavior provides a inuiive roaion specificaion A Virual rackball Imagine he viewpor as floaing above, and jus ouching an acual rackball. You receive he coordinaes in screen space of he MouseDown() and MouseMove() evens. Wha is he axis of roaion? Wha is he angle of roaion? 2/4/25 Lecure 9 7 2/4/25 Lecure 9 8 Compuing he Roaion Consruc a vecor a v from he cener of roaion of he virual rackball o he poin of he MouseDown() even. Consruc a 2 nd vecor b v from he cener of roaion for a given MouseMove() even. Normalize â a v v a, and bˆ b v v, and hen compue axis â bˆ b hen find he angle Arc sin( â bˆ ) and consruc axis R Roae(angle, ) axis a v b v axis Where o Roae? Where do you inser i in rendering process so as o have he desired inerface? c& w& w& camera mod el ( ) w& c & camera 4243 V c& c& V V R mod el p& mod el p& mod el c& VR p& 23 mod el
he Proof is in he Code And he Display Rouine def onmousebuon(buon, sae, x, y): global oldx, oldy if (sae GLU_DOWN): oldx, oldy x, y def onmousedrag(x, y): global oldx, oldy, deph if (mode r ): v Vecor(oldX -.5*widh,.5*heigh - oldy,.5*widh).normalize() v Vecor(x -.5*widh,.5*heigh - y,.5*widh).normalize() axis v.cross(v) angle mah.asin(axis.lengh()) axis axis.normalize() glpushmarix() glloadideniy() glroaed(angle*8/mah.pi, axis.x, axis.y, axis.z) glmulmarixd(obj2wld.marix()) obj2wld.se(glgefloav(gl_modelview_marix)) glpopmarix() oldx, oldy x, y def display(): glclear(gl_color_buffer_bi GL_DEPH_BUFFER_BI) glpushmarix() glulooka(,,24,,,,,,) glpushmarix() glmulmarixd(obj2wld.marix()) drawframe(5) obj.draw() glpopmarix() drawbackdrop() glflush() glpopmarix() gluswapbuffers() Wha would happen if I ook ou hese pushes and pops? 2/4/25 Lecure 9 2 2/4/25 Lecure 9 22 ransformaion Hierarchies Many models are composed of independen moving pars Each par defined in i s own coordinae sysem Compose ransforms o posiion and orien he model pars A Simple One-chain Example Using Graphs o Model Hierarchies Model pars are nodes ransforms are edges Wha ransform is applied o he Head par o ge i ino coordinaes? 4 w& head Suppose ha you d like o roae he Neck join a he poin where i mees he Body. hen wha is he Head s ransform o space? 3 2 R head w& R 4 Base Body Neck Head w& 2 3 2 4 3 head
Code Example ( s ry) Code Example (2 nd ry) public override void Draw() { glclear(gl_color_buffer_bi GL_DEPH_BUFFER_BI); glloadideniy(); glulooka(,,-6,,,,,,); // -o-camera ransform glcolor3d(,,); glroaed(-9,,, ); // -o- ransform mom.draw(lamp.base); mom.draw(lamp.body); mom.draw(lamp.neck); mom.draw(lamp.head); glflush(); } public override void Draw() { glclear(gl_color_buffer_bi GL_DEPH_BUFFER_BI); glloadideniy(); glranslaed(.,., -6.); // -o-view ransform glcolor3d(,,); glroaed(-9,,, ); // -o- ransform mom.draw(lamp.base); glranslaed(,,2.5); // -o- ransform mom.draw(lamp.body); glranslaed(2,,); // -o- ransform mom.draw(lamp.neck); glranslaed(2,,); // head-o- ransform mom.draw(lamp.head); glflush(); } 2/4/25 Lecure 9 25 2/4/25 Lecure 9 26 Code Example (3 rd ry) Demo public override void Draw() { glclear(gl_color_buffer_bi GL_DEPH_BUFFER_BI); glloadideniy(); glranslaed(., -2., -6.); // -o-view ransform glcolor3d(,,); glroaed(-9,,, ); // -o- ransform mom.draw(lamp.base); glranslaed(,,2.5); // -o- ransform glroaed(-3,,, ); // roae a pivo mom.draw(lamp.body); glranslaed(2,,); // -o- ransform glroaed(-5,,, ); // roae a pivo mom.draw(lamp.neck); glranslaed(2,,); // head-o- ransform glroaed(8,,, ); // roae head a pivo mom.draw(lamp.head); glflush(); }
Skeleon Code: Your Nex Projec Kinemaics Kinemaics describes he moions of bodies (pars) wihou considering he forces required o produce and mainain he moion. More abou geomeric CONSRAINS han PHYSICS. An ariculaed model wih pars, bu only 6 Models Here s where glpushmarix() and glpopmarix() earn heir keep Rs Rf head runk R L Ls Lf Head runk Rc Lc Rs Ls Rf R L Lf Rc Lc 2/4/25 Lecure 9 29 2/4/25 Lecure 9 3 Nex ime As well as Picking & Selecion