CSC. Computer Graphics Lecture 4 P T P t, t t P,, P T t P P T Kasun@dscs.sjp.ac.lk Department o Computer Science Universit o Sri Jaewardanepura Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP r r, otation in angle about a pivot (rotation) point r, r. r r cos r sin r r sin r cos B origin B actor m = m = m, r r, P Pr P Pr cos sin sin cos Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 3 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 4, S S s, s s s P S P Scaling about a ied point, s s s s P P S P - S Parallel to ais B actor a = +a = Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 5 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 6
Use to change the location, orientation, and sie o an object Scale otate Translate Shear Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 7 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 8 Translation can not be represented using D matri. Wh? otate and then displace a point P : P = M P + M M : rotation matri. M : displacement vector. Displacement is unortunatel a non linear operation. Make displacement linear with Homoheneous Coordinates.,,,. Transormations turn into 33 matrices. Ver big advantage. All transormations are concatenated b matri multiplication. Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 9 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP D Translation t t, P Tt, t P D otation cos sin sin cos, P P D Scaling S S, P SS, S P Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP
Inverse transormations: t cos sin S T t, sin cos, S S Composite transormations: P M M P M M P MP Composite otations: P P P P P t, t t, t t, t t, t P T T P T T P t t t t Composite translations: t t t t t, t t, t t t, t t T T T Composite Scaling: S S S S S S S S S, S S, S S S, S S S S S Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 3 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 4 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 5 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 6 r, r Move to origin otate Move back, Move to origin Scale Move back r cos sin r r sin cos r cos sin r cos rsin sin cos rcos rsin Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 7 S S S S S S Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 8 3
S SS, S S S cos S sin S S cos sin S S cos sin S sin S cos S S 45 O Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 9 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP Ver similar to D. Using 44 matrices rather than 33. Translation t t t,,,, t t t Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP.Translate the object such that rotation ais passes through the origin..otate the object such that rotation ais coincides with one o Cartesian aes. 3.Perorm speciied rotation about the Cartesian ais. 4.Appl inverse rotation to return rotation ais to original direction. 5.Appl inverse translation to return rotation ais to original position. P P P P P P P P P P P P Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 3 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 4 4
The vector rom P to P is: V P P,, Unit rotation vector: u V V abc,, a b c V V V a b c T u abc,, otating u to coincide with ais First rotate u around ais to la in plane. Equivqlent to rotation u 's projection on plane around ais. cos c b c c d, sin b d. We obtained a unit vector w a,, b c d in plane. c d b d b d c d u u abc,, Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 5 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 6 otate w counterclockwise around ais. w is a unit vector whose component is a, component is, hence component is b c d. cos d, sin a d a a d u abc,, w a,, d T T cos sin sin cos T T M cos cos cos sin cos sin cos sin cos cos cos sin cos sin cos sin cos cos a ab c ac b ba c b bc a ca b cb a c Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 7 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 8 Quaternions are etensions o comple numbers to 4-dimension. v v q s ia jb kc s, s : real a, b, c : imaginar i j k, ij ji k, jk kj i, ki ik j Addition: q q s s, v v Multiplication: q q s s v v, s v + s v v v q s v v, q s,, qq q q, q v u otate a point position p,, about the unit vector u. Quarternion representation: otation: q cos, usin Position: P, p, p,, otation o P is carried out with the quarternion operation: P qpq, s p vpv s vp vvp This can be calculated b eicient HW or ast 3D rotations when man rotation operations are involved. Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 9 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 3 5
Scaling with respect to a ied point (not necessaril o object) S S S Enlarging object also moves it rom origin S S P SP S,,,,,,,, S S S S TST S S Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 3 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 3 glpushmatri (); gltranslate(.,.,.); glotate(6,.,.,.); glscale(.,.,.); glcolor3 (,, ); glutwirecube(.); glpopmatri (); Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 33 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 34 Kasun@dscs.sjp.ac.lk - Facult o Applied Sciences o USJP 35 6