Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.

Similar presentations


Presentation on theme: "CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations."— Presentation transcript:

1 CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University
Transformations

2 Outline 3D transformations Concatenation of transformations
Transformations in OpenGL Anatomy of a simple OpenGL program

3 Coordinate systems Each point and vector is defined in reference to a coordinate system Once we fix the origin of the coordinate system, we can represent all points unambiguously The same point may have different 3D coordinates in different coordinate systems Remember that part of the job of 3D graphics pipeline is to convert vertices from model space to 2D window space Each vertex with go through several coordinate systems along the pipeline

4 Coordinate systems A 3D coordinate system is defined by its three base vectors (x, y, and z axis) Get familiar with OpenGL’s coordinate system

5 Geometric transformation
In 3D graphics, animation is achieved by transforming geometric objects in the virtual world Transforming geometric objects means transforming points (vertices) and vectors Transformation of points and vectors can be conveniently achieved by matrix multiplications Introduced by Larry Roberts in 1966

6 Linear Algebra Review Matrix: An array of elements
Vectors: A n x 1 matrix is called a column vector In computer graphics, vertex coordinates and vectors (directed line segments) and are represented by column vectors.

7 Linear Algebra Review Matrix-column vector multiplication

8 Linear Algebra Review Matrix-matrix multiplication V1 V2 V3

9 Linear Algebra Review Homogeneous representation
A vertex coordinate representation has 1 as the 4th component. OpenGL uses homogeneous coordinates for all vertices. (x, y, z) => (x, y, z, 1) Why use homogeneous coordinates? So that all transformations can be defined by matrix multiplication.

10 Affine Matrix An affine matrix is a 4x4 matrix with last low [0 0 0 1]
Why include the bottom row of (0,0,0,1)? It’ll be useful in perspective transforms. Affine matrix is used to define affine transformation.

11 Affine Transformation
Any transformation preserving collinearity (i.e., all points lying on a line initially still lie on a line after transformation) ratios of distances (e.g., the midpoint of a line segment remains the midpoint after transformation). Affine transformations preserve parallel lines. We can transform vertices with affine transformation. Affine transformations are what we use all the time in computer graphics.

12 Other Transformations
Isometry (preserves distance) Similarity (preserves angles) Collineation (lines remains lines) Perspective projections Non-linear (lines become curves) Twists, bends, etc. Can be used for deformation.

13 Elementary Affine Transformations
Four elementary affine transformations Translation Scaling Rotation (about an axis) Shear Translation, scaling and rotation are the most commonly used transformations.

14 Translation Translation P’ P d x y

15 Scaling Scaling

16 Rotation Rotation about the origin
Counter-clock wise rotation by 90 degree.

17 2D Transformation Summary
Translation Scaling Rotation

18 Composition of Affine Transforms
Most of the time we want to apply more than one transformation. Example: Translate by vector t Rotate by r degree about the origin This can be represented by multiple matrix multiplications:

19 Composition of Affine Transforms
Matrix multiplication is associative: We can group the combined transformation as The affine matrices are applied right side first. We can also apply all the transformations to form a single matrix This called composing or concatenation of transforms. The result is another affine transformation.

20 Composition of Affine Transforms
It is important to always remember that matrix multiplication is not commutative The order of transforms DOES matter E.g. scaling then rotating is usually different than rotating then scaling Keep this in mind when you write OpenGL program – you need to know in which order your OpenGL transform calls are executed

21 Decomposition of Affine Transforms
Any affine transform can be decomposed into the product of a rotation, a scale, and a rotation.

22 Coordinate Transformations
We have discussed how to use transformation matrices to move points around We can also think of them as simply changing the coordinate system in which the point is presented The origin of the coordinate system is transformed but the relative position of the point is unchanged In different contexts, either interpretation may be more suitable.

23 Why use matrix formalisms?
Can’t I just hardcode transforms rather than use the matrix multiplication? Yes. But it’s harder to derive, harder to debug, and not any more efficient All current graphics APIs use this matrix formalism Must understand this to use OpenGL or other graphics libraries

24 3D Affine Transformations
3D affine transformations are an extension of the 2D transformations. Use 4x4 matrices instead of 3x3 matrices in 2D transformations. For example 3D scaling

25 3D Translation 3D translation matrix
OpenGL function: glTranslatef(tx, ty, tz)

26 3D Scaling 3D scaling matrix OpenGL Function: glScalef(Sx, Sy, Sz)

27 3D Rotation About the Origin
3D rotation is more complicated than 2D rotation. Rotation about X axis Rotation about Y axis Rotation about Z axis

28 Arbitrary 3D Rotations Normal practice is to decompose an arbitrary 3D rotation into rotations about x, y, z axes. Create a single transformation matrix by composing.

29 Rotation in OpenGL (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
Equivalent to multiplying the following matrix

30 Rotation in OpenGL Rotations are specified by a rotation axis and an angle Normal practice is to decompose an arbitrary 3D rotation into rotations about x, y, z axes Achieved by 3 glRotatef() calls

31 Rotation About a Fixed Point
The order is important: Translate to the origin Rotate about the origin Translate back Example: To rotate by r about z around

32 Quaternions A quaternion is a 4-tuple of real numbers [s,x,y,z] or [s,v], s is a scalar and v is a three-dimensional vector. Quaternions provide an alternative for describing and manipulating rotations. Quaternions are more efficient than rotation matrices Can be interpolated to obtain smooth sequence of rotations for animation You can convert between a transformation matrix and a quaternion

33 Multiple 3D Transformations
By combining a scaling, rotation, and a translation matrix we get a single transformation matrix. Notice that in the single matrix, translation is separated from scaling and rotation part. We can think of an affine matrix as having a scaling-rotation part and a translation part. If a transformation consists of only translations and rotations, then it’s called a rigid-body transformation.

34 Transformations in OpenGL
Internally each vertex in OpenGL is represented as homogeneous points i.e. a column vector with 1 as the last item. However you don’t need to specify the 1 in your program Each vertex is transformed by the modelview matrix. There is always a current modelview matrix that is applied to all vertices.

35 Model-view Matrix

36 Transformation in OpenGL
It is important to understand the relationship among Current modelview matrix, Vertices of 3D Object So you can understand why OpenGL code has to be arranged in certain way

37 What happens inside OpenGL during transformation?
Final modelview matrix Matrices are often created dynamically by the OpenGL program. Matrix multiplications are performed in vertex shaders. Vertex coordinates before transformation Vertex coordinates after transformation

38 Summary Affine transformations are used for transforming 3D objects.
Three elementary affine transformations: Translation Scaling Rotation 3D rotation is the most complicated among the three. If we use homogeneous coordinates, then all affine transformations can be represented by affine matrix multiplication. Notice the pattern of transformation in OpenGL programming.

39 OpenGL Tutorial Programs
Download OpenGL transformation tutorial program from


Download ppt "CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations."

Similar presentations


Ads by Google