17
Lecture 6 3D Transformations 1

Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

Embed Size (px)

Citation preview

Page 1: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

Lecture 63D Transformations

1

Page 2: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations to view our 3D models effectively. • Let us look into 3D transformations in more detail.

2

Page 3: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

Just as 2D transformations can be represented by 3 x 3 matrices using homogenous coordinates.

3D transformations can be represented by 4 x 4 matrices. 3D homogenous coordinates are represented as a quadruplet (x, y,

z, W). We discuss the representation of the three most commonly used

transformations: translation, scaling, and rotation.

3

Page 4: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

1-Translation

• The translation matrix T(Tx, Ty, Tz) is defined as:

• so any vertex point:

4

Page 5: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

5

Page 6: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

2- Scalling

• Scaling is similarly extended to be defined as:

6

Page 7: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

Recall from Lecture 3 that scaling occurs about a point. This point is called the pivot point. The scaling matrix defined above scales about the origin.

You can define models to have different pivot points by setting the transformation stack appropriately.

7

Page 8: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

3-Rotation

• Rotation matrices are defined uniquely based on the axis of rotation and the pivot point.

• The axis of rotation is a normalized vector defining the axis in 3D space along which the rotation will occur.

8

Page 9: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• (A 3D vector will simply be the triplet (x, y, z) defining the direction of the axis). The 2D rotation we saw earlier is a 3D rotation about the z-axis (the vector (0,0,1)), and the world origin (0,0,0) and is defined as:

9

Page 10: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• Similarly the rotation matrix about the x-axis is defined to be:

• and about the y-axis as:

10

Page 11: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• Just as with 2D transforms, 3D transforms can be composed together to provide desired effects.• The order in which the transforms are applied is important.• Recall from our previous section that the OpenGL commands for

matrix operations

11

Page 12: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• sets the current matrix to be the 4 x 4 identity matrix.

• sets the matrix passed in to be the current transformation matrix.

• multiplies the current matrix by the matrix passed in as the argument.

12

Page 13: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• Additionally, OpenGL provides three utility functions for the most commonly used transformations.

• multiplies the current transformation matrix by the matrix to move an object by (Tx, Ty, Tz) units

13

Page 14: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• multiplies the current transformation matrix by a matrix that rotates an object in a counterclockwise direction by theta degrees about the axis defined by the vector (x, y, z).

• multiplies the current transformation matrix by a matrix that scales an object by the factors, (Sx, Sy, Sz).

14

Page 15: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• All three commands are equivalent to producing an appropriate translation, rotation, or scaling matrix and then calling glMultMatrixf0 with that matrix as the argument.

• For example, Let us apply some transformations to the famous pyramid that we created earlier.

15

Page 16: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

• We rotate the pyramid about the y-axis and use double buffering to display the rotation as an animation.

16

Page 17: Lecture 6 3D Transformations 1. We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations

In lecture 3, we saw how to map a two-dimensional world onto the two dimensional screen.

The process was a simple mapping of 2D world coordinates onto the 2D viewport of the window.

Model positions are first clipped against the 2D world coordinates and then mapped into the viewport of the window for display.

17