CSE528 Computer Graphics: Theor, Algorithms, and Applications Hong Qin State Universit of New York at Ston Brook (Ston Brook Universit) Ston Brook, New York 794--44 Tel: (63)632-845; Fa: (63)632-8334 qin@cs.sunsb.edu http://www.cs.sunsb.edu/~qin
Transformation and Viewing
Cartesian Coordinate Sstem Left Handed +Y +Y +Z -Z -X +X -X +X +Z -Y -Z -Y Right Handed CSE53, SUNYSB-CS SPRING, 2
Euclidean Space Scalars Points: P = (,,) Vectors: V = [,,] Magnitude or distance V = ( 2 + 2 + 2 ) Direction No position Position vector Think of as magnitude and distance relative to a point, usuall the origin of the coordinate sstem CSE528, SUNYSB-CS
Review of Common Vector Operations in 3D Addition of vectors V +V 2 = [,, ] + [ 2, 2, 2 ] = [ + 2, + 2, + 2 ] Multipl a scalar times a vector sv = s[,,] = [s,s,s] Dot Product V V 2 = [,, ][ 2, 2, 2 ] = [ 2 + 2 + 2 ] V V 2 = V v 2 cos where is the angle between V and V 2 Cross Product of two vectors V V 2 = [,, ][ 2, 2, 2 ] = [ 2-2, 2-2, 2-2 ] = - V 2 V Results in a vector that is orthogonal to the plane defined b V and V 2 CSE528, SUNYSB-CS
2D Geometric Transformations Translation Rotation Scaling Shear Homogenous Coordinates Matri Representations Composite Transformations
Translation =+t =+t (, ) ' ' t t (,)
Rotation = cos - sin = sin + cos ' ' cos sin sin cos (, ) (,)
Scaling =S =S (, ) ' ' S S (,)
Shear = + h = ' ' h
Homogenous Coordinates Each position (, ) is represented as (,, ). All transformations can be represented as matri multiplication. Composite transformation becomes easier.
Translation in Homogenous Coordinates =+t =+t P = (,) P = (, ) ' ' t t P = T(t, t ) P
Rotation in Homogenous Coordinates = cos - sin = sin + cos ' ' cos sin sin cos P = (, ) P = (,) P = R( ) P
=s =s (,) (, ) ' ' s s Scaling in Homogenous Coordinates P = S(s, s ) P
= + h = ' ' h Shear in Homogenous Coordinates P = SH P
2D Geometric Transformations Translation Rotation Scaling Shear Homogenous Coordinates Composite Transformations
2D Geometric Transformations Translation Rotation Scaling Shear Homogenous Coordinates Composite Transformations Rotation about a fied point
Rotation About a Fied Point. Translate the object to the origin. ( r, r ) 2. Rotate around the origin. 3. Translate the object back.
Rotation About a Fied Point ( r, r ). Translate the object to the origin
Rotation About a Fied Point 2. Rotate about origin
Rotation About a Fied Point ( r, r ) 3. Translate the object back
Rotation About a Fied Point. Translate the object to the origin. 2. Rotate around the origin. 3. Translate the object back. cos sin sin cos r r r r ( r, r ) P = T( r, r ) R( ) T(- r, - r ) P T( r, r ) R( ) T(- r, - r )
3D Geometric Transformations Basic 3D Transformations Translation Rotation Scaling Shear Composite 3D Transformations Change of Coordinate sstems
Translation (,, ) (,, ) ' ' ' t t t P = T P
Rotation about -ais cos sin sin cos ' ' ' P = R () P
Rotation about -ais cos sin sin cos ' ' ' P = R () P
Rotation about -ais cos sin sin cos ' ' ' P = R () P
Rotation About a Fied Point. Translate the object to the origin. 2. Rotate about the three ais, respectivel. 3. Translate the object back. P = T ( r, r,, r ) R * R2 * R3 T (- r, - r,, - r ) P Ri = R (,i ) R (,i ) R (,i )
Rotation with Arbitrar Direction. We will have to translate an arbitrar vector so that its starting point starts from the origin 2. We will have to rotate w.r.t. -ais so that this vector stas on - plane 3. We will then rotate w.r.t. -ais so that this vector aligns with -ais 4. We will then rotate w.r.t. -ais 5. Reverse (3), (2), and ()
Scaling (,, ) (,, ) ' ' ' s s s P = S P
' ' ' h h Shear P = SH P
Change in Coordinate Sstems P = M P M can be a combination of translation, rotation and scaling.
Taking a Picture with a Camera Geometric Coordinate Sstems: Local, World, Viewing Graphics Rendering Pipeline ModelView Matri operations on models World coordinates to Viewing coordinates Matri operations (models or cameras) Projection with a camera
Viewing in 3D Planar Geometric Projections Parallel Orthographic Projections Perspective Projections Projections in OpenGL Clipping
Planar Geometric Projections Maps points from camera coordinate sstem to the screen (image plane of the virtual camera). Planar Geometric Projections Parallel Perspective Oblique Orthographic Image Plane Image Plane Center of Projection (COP)
Parallel Orthographic Projection Preserves X and Y coordinates. Preserves both distances and angles. Image Plane
Parallel Orthographic Projection p p p (,, ) p = p = p = ( p, p, ) =
Perspective Projection Onl preserves parallel lines that are parallel to the image plane. Line segments are shorten b distance. Image Plane Center of Projection (COP)
Perspective Projection (,, ) ( p, p, p ) = d
Perspective Projection p = d p = ( d) / ( p, d) (, ) = d
Perspective Projection p = d p = ( d) / ( p, d) (, ) = d
Perspective Projection p = ( d) / =/(/ d) p = ( d) / =/(/ d) p = d =/(/ d) / d h h h h h h h h h h h h p p p / / / /
Viewing in 3D Planar Geometric Projections Parallel Orthographic Projections Perspective Projections Projections in OpenGL
Viewing in 3D Planar Geometric Projections Parallel Orthographic Projections Perspective Projections Projections in OpenGL Positioning of the Camera Define the view volume
Positioning the Camera B default, the camera is placed at the origin pointing towards the negative -ais.
Positioning the Camera OpenGL Look-At Function glulookat(ee, ee, ee, at, at, at, up, up, up) View-reference point (VRP) View-plane normal (VPN) View-up vector (VUP) (up, up, up) (at, at, at) (ee, ee, ee)
Defining the Perspective View Volume glfrustum(left, right, bottom, top, near, far) ( ma, ma, -far) ( min, min, -near)
Defining the Perspective View Volume gluperspective(fov, aspect, near, far) w h fov
Defining the Parallel View Volume glortho(min, ma, min, ma, near, far) ( ma, ma, -far) ( min, min, -near) View Volume