Coordiate Sstems There are 3 coordiate sstems that a compter graphics programmer is most cocered with: the Object Coordiate Sstem (OCS), the World Coordiate Sstem (WCS), ad the Camera Coordiate Sstem (CCS). Each plas a importat role. OCS: Objects are most easil modeled i a coordiate sstem with the origi at its ceter ad the coordiate aes aliged i some atral wa with the object. For eample, the sides of a cbe wold be aliged with the coordiate aes. Each object will hae its ow OCS. WCS: I order for objects to iteract, we eed to place all objects withi a sigle coordiate sstem, called the WCS, so their relatioship with ca be epressed. We thik of the WCS as represetig the eiromet i which eerthig eists. Commol, the WCS origi establishes the leel of the grod ad the ais poitig p. The WCS is tpicall cosidered fied i positio oer time (objects ad camera moe withi the WCS). The model matri, M, coerts a object s ertices epressed i OCS to the WCS. Each object will hae its ow M. We se the cocept of scee graphs to geerate the model matri M i order to place ad moe comple objects withi the WCS. CCS: The camera represets the locatio & orietatio of the iewer. Oer time, the iewer geerall moes arod the WCS ad so the relatioship betwee the CCS ad WCS is ot costat. The process of rederig a image reqires that a 3D scee (i.e. the ertices) be projected dow oto a 2D scree (the image), where the locatio ad orietatio of the scree is defied b the camera. The projectio is simple to do if the ertices are epressed i the camera coordiates, i.e. with the camera at the origi ad lookig dow the egatie ais (as is the case for the CCS), the the projectio will be oto to the plae so that the projectio is simpl (,,) (, ). Ths, we trasform ertices from the WCS to the CCS i order to simplif the projectio calclatio. Thigs to thik abot: Whe specifig the coordiates of a positio, it is importat to make it clear which coordiates sstem is beig sed. Cosider the poit (,,) T. This will mea somethig differet depedig o which coordiate sstem oe is i. For eample, i the OCS, the (,,) T geerall correspods to the ceter of the object. I the WCS, (,,) T correspods to the origi of the world, ad i CCS, (,,) T correspods to the locatio of the camera. Similarl, the ector (,,) T correspods to the ais. The ais i the WCS is ot i the same directio as the ais i the CCS. I geeral, a poit P ca be epressed i a of the coordiate sstems. This will be discssed more later.
Trasformig OCS WCS Cosider a cbe which might be modeled i the OCS as i Figre. Figre : A cbe i OCS. Figre 2: A cbe as it appears i OCS ad WCS Let P be a poit o a cbe sch as the erte at coordiates (.5,.5,.5) T i OCS. Now sppose we wat to place it ito the world as show i Figre 2. To do this, we eed to trasform the coordiates sig a matri we call the Model Matri, M. P WCS = ' ' = M P OCS = M ' Where M is determied sig the scee graph techiqes. WCS CCS Gie the cbe i WCS, we ca ow trasform it ito the CCS as show i Figre 3. All three coordiate sstems are show i Figre 4. Figre 3: A cbe as it appears i WCS ad CCS Figre 4: A cbe i relatio to OCS, WCS, ad CCS Notice that i the CCS the camera alwas looks dow the camera s egatie ais ad the ector poits perpediclarl p from the camera. To determie the coordiates i the CCS, we eed to trasform it from WCS to CCS sig a matri trasform which we call the View Matri, V. '' ' P CCS = '' = V P WCS = V ' = V M P OCS = V M '' '
Note: For eample, the poit P=(.5,.5,.5) T o the cbe as epressed i CCS is.5 P CCS = V P WCS = V M P OCS = V M.5..5 Relatioship betwee Trasformig Poits ad Trasformig Coordiate Sstems Before discssig how to calclate V, we eed to discss trasformatios of coordiate sstems. Note that it is ot possible to distigish betwee traslatig a poit P i a coordiate sstem erss keepig the poit fied bt moig the coordiate aes as show i Figre 5 below. We preset the cocepts here i 2D, howeer, the reslts eted to 3D. Figre 5: Moig the coordiate sstem (left) s moig the poit (right) The relatioship betwee P ad Q (o left) is the same as the relatioship betwee P ad Q (o right): O the left, the poit P has coordiates (,3) i Q. We traslate the coordiate aes i Q b (4,3) to obtai Q. Epressed i Q, P ow has coordiates (-3,). O the right, we keep Q fied bt traslate P=(,3) b (-4,-3) to that it is ow sittig at P =(-3,). Either wa, P eds p at (-3,) ad the trasformatio that mst be applied to the poit (o right) is the ierse of that applied to the coordiate sstem (o left). I smmar, traslatig a poit b a traslatio T, is eqialet to traslatig the coordiate sstem b T - = ierse of T. Figre 5: Rotatig the coordiate sstem (left) s rotatig the poit (right)
Similarl, it ca be show that rotatig a poit b the rotatio R, is eqialet to rotatig the coordiate sstem b R - = ierse of R. I geeral, a trasformatio A applied to the coordiate aes is eqialet to applig the trasformatio A - to the ertices. For eample, sppose we appl both a rotatio ad traslatio to the coordiate aes: A=TR. This is eqialet to trasformig the ertices b A - = (TR) - = R - T -. We will make se of this reslt i the et sectio. Calclatig V Recall that V is the matri which trasforms ertices i WCS to ertices i CCS. To calclate V, will first cosider the trasformatios ecessar to do the eqialet trasform of the coordiates aes. Namel, we wat to fid the matri trasform, TR, cosistig of a traslatio T ad rotatio R, which will moe the WCS to the CCS. Followig the reslt of the preios sectio, V will the be the ierse of this, amel, V = R - T -. Sppose the camera s positio i the WCS is gie b the ee ector ee ee = ee. ee The camera s orietatio ca be defied b the three orthogoal it ectors,, ad defied i the WCS, where the camera looks i the directio of, ad where is perpediclarl p ad is to the camera s right. Note: If the WCS ad CCS were eactl aliged, the wold correspod to the ais, wold correspod to the ais, ad wold correspod to the ais. The locatio ad orietatio of the camera is completel determied b ee,,, ad. We se these to determie the trasforms TR which moe the WCS to the CCS. We first appl the rotatio, ad the the traslatio. Figre 6: Trasformig the aes.
I Figre 6, we begi with the WCS ad CCS aliged as o the left. We first rotate b R (middle) ad the traslate b T (right). It is eas to see that T = ee ee ee R is less obios. Whateer R is, it mst satisf the eqatios (see middle of Figre 6): = R, = R, ad = R I homogeeos coordiates, we hae =, =, =, =, =, = Note, the 4 th compoet of each is becase these are ectors ad ot poits! So the aboe eqatios become = = R, = = R, ad = = R The ol matri R which satisfies all three of these eqatios is the matri whose colms are,, (we are relig o the fact that,, ad are orthoormal ectors): R = Gie R ad T, we ca ow calclate V: V = R - T - = R T T - = ee ee ee = ee ee ee ee ee ee ee ee ee I the code, we store the positio of the ee = (ee, ee,ee,)
Ad the iew rotatio matri V rot = R -. Order of Trasformatios: Thigs to Thik Abot We ow kow how to calclate V ad ths how to trasform poits from OCC to WCS to CCS. P CCS = V P WCS = V M P OCS Thik abot the followig Do the make sese to o? P OCS = (,,,) T correspods to the ceter of the object P WCS = (,,,) T correspods to the ceter of the world P CCS = (,,,) T correspods to the ceter of the camera V (,,,) T gies the locatio of the world origi i the camera coordiate sstem V M (,,,) T gies the locatio of the object s ceter i the camera coordiate sstem M (,,,) T gies the locatio of the object s eter i the world coordiate sstem Now sppose we hae the stadard rotatio matri R abot the -ais, that is cosθ siθ R = siθ cosθ The order i which R is applied has a big differece o what happes, as follows: V M R P OCS V R M P OCS R V M P OCS rotates a erte P OCS abot the object s ais rotates a erte P OCS abot the world s ais rotates a erte P OCS abot the camera s ais Tmble The tmble trasformatio chages the iew trasform V as follows: We specif a P c = ceter of iterest. This ca be awhere bt i the code we limit it to be either the WCS origi or a poit a fied distace i frot of the camera. Moig the mose left ad right will rotate the camera abot the lie which goes throgh P c ad is parallel to the WCS -ais Moig the mose p ad dow will rotate the camera abot the lie which goes throgh P c ad is parallel to the camera s ais Defie the followig matrices: The matri A rotates alog the lie which goes throgh a poit P ad is parallel to the -ais A = T(P) R T(-P)
where we se the otatio T(P) to idicate a traslatio b a amot P. We wat A to be applied i the WCS so it mst mltipl V o the right. The poit P correspods to the poit of iterest P c which is epressed i WCS. The matri B rotates alog the lie which goes throgh a poit P ad is parallel to the -ais. B = T(P) R T(-P) We wat B applied i the CCS so we mst mltipl V b B o the left. The poit P correspods to the poit of iterest P c which ow mst be epressed i CCS, i.e. P c = V old P c Ths, to tmble the camera, we hae the ew iew matri to be V ew = B V old A = T(P c ) R T(-P c ) V old T(P c ) R T(-P c ), where P c = V old P c I the code, we do ot store V bt rather the V rot = rotatioal part of V, ad ee = the camera positio. Ths, we eed to etract these from V ew. Recall from earlier we had V ew = V rot,ew T(-ee ew ) = ee ee ee, ew, ew, ew (eqatio ) = ee ee ee, ew, ew, ew ee ee ee, ew, ew, ew ee, ee, ee ew ew, ew (eqatio 2) Comparig eqatios ad 2, it is eas to see that V rot,ew = Howeer, it is ot so eas to etract ee ew becase the last colm i eqatio 2 is ot ee ew. Howeer, if we kew the ierse of V rot,ew, the we cold obtai T(-ee ew ) = (V - rot,ew V rot,ew ) T(-ee ew ) - = V rot,ew ( V rot,ew T(-ee ew ) ) = V - rot,ew V ew Sice the ierse of a pre rotatio is jst its traspose, we ca easil obtai V rot,ew -, so that we ca calclate T(-ee ew ) = V rot,ew -T V ew.
Oce we hae T(-ee ew ): T(-ee ew ) = ee ee ee, ew, ew, ew we see that ee ew ca be obtaied b pllig ot the last colm of T(-ee ew ), egatig the first three compoets to obtai ee ew = (ee,ew, ee,ew, ee,ew, ).