Download presentation
Presentation is loading. Please wait.
Published byIris Craig Modified over 9 years ago
1
3D Coordinate Systems o3D computer graphics involves the additional dimension of depth, allowing more realistic representations of 3D objects in the real world oThere are two possible ways of “attaching” the Z-axis, which gives rise to a left-handed or a right-handed system
2
3D Transformation oThe translation, scaling and rotation transformations used for 2D can be extended to three dimensions oIn 3D, each transformation is represented by a 4x4 matrix oUsing homogeneous coordinates it is possible to represent each type of transformation in a matrix form and integrate transformations into one matrix oTo apply transformations, simply multiply matrices, also easier in hardware and software implementation oHomogeneous coordinates can represent directions oHomogeneous coordinates also allow for non-affine transformations, e.g., perspective projection
3
Homogeneous Coordinates oIn 2D, use three numbers to represent a point o(x,y) = (wx,wy,w) for any constant w 0 oTo go backwards, divide by w, (x,y) becomes (x,y,1) oTransformation can now be done with matrix multiplication
4
Basic 2D Transformations oTranslation: oScaling: oRotation:
5
Translation and Scalling Matrice oThe translation and scaling transformations may be represented in 3D as follows: 1 0 0tr X 0 1 0tr Y 0 0 1 tr Z 0 0 01 ( ) S X 0 00 0 S Y 00 0 0 S Z 0 0 0 01 ( ) Translation matrix Scaling matrix
6
Translation translation along y, or V = (0, k, 0) original V=(ai + bj +ck) == (a, b, c)
7
Scaling Originalscale all axes scale Y axisoffset from origin
8
3D Shearing Shearing: The change in each coordinate is a linear combination of all three Transforms a cube into a general parallelepiped
9
Rotation oIn 2D, rotation is about a point oIn 3D, rotation is about a vector, which can be done through rotations about x, y or z axes oPositive rotations are anti-clockwise, negative rotations are clockwise, when looking down a positive axis towards the origin x y z x y z x y z
10
Major Axis Rotation Matrices oabout X axis oabout Y axis oabout Z axis Rotations are orthogonal matrices, preserving distances and angles.
11
Rotation rotation of 45 o about the Z axis offset from origin translation then rotate about Z axis
12
Rotation Axis oIn general rotation vector does not pass through origin
13
Rotation about an Arbitrary Axis oRotation about an Arbitrary Axis Basic Idea 1.Translate (x 1, y 1, z 1 ) to the origin 2.Rotate (x’ 2, y’ 2, z’ 2 ) on to the z axis 3.Rotate the object around the z-axis 4.Rotate the axis to the original orientation 5.Translate the rotation axis to the original position Basic Idea 1.Translate (x 1, y 1, z 1 ) to the origin 2.Rotate (x’ 2, y’ 2, z’ 2 ) on to the z axis 3.Rotate the object around the z-axis 4.Rotate the axis to the original orientation 5.Translate the rotation axis to the original position (x 2,y 2,z 2 ) (x 1,y 1,z 1 ) x z y R -1 T -1 R R T T
14
Rotation about an Arbitrary Axis oStep 1. Translation (x 2,y 2,z 2 ) (x 1,y 1,z 1 ) x z y
15
Rotation about an Arbitrary Axis oStep 2. Establish (a,b,c) (0,b,c) Projected Point Rotated Point x y z
16
Rotation about an Arbitrary Axis oStep 3. Rotate about y axis by (a,b,c) (a,0,d) l d x y Projected Point z Rotated Point
17
Rotation about an Arbitrary Axis oStep 4. Rotate about z axis by the desired angle l y x z
18
Rotation about an Arbitrary Axis oStep 5. Apply the reverse transformation to place the axis back in its initial position x y l l z
19
Rotation about an Arbitrary Axis Find the new coordinates of a unit cube 90º-rotated about an axis defined by its endpoints A(2,1,0) and B(3,3,1).
20
Rotation about an Arbitrary Axis oStep1. Translate point A (2,1,0) to the origin A’(0,0,0) x z y B’(1,2,1)
21
Rotation about an Arbitrary Axis x z y l B’(1,2,1) Projected point (0,2,1) B”(1,0, 5) oStep 2. Rotate axis A’B’ about the x axis by and angle , until it lies on the xz plane.
22
Rotation about an Arbitrary Axis x z y l B”(1,0, 5) (0,0, 6) oStep 3. Rotate axis A’B’’ about the y axis by and angle , until it coincides with the z axis.
23
Rotation about an Arbitrary Axis Finally, the concatenated rotation matrix about the arbitrary axis AB becomes, oStep 4. Rotate the cube 90° about the z axis
24
Rotation about an Arbitrary Axis
25
oMultiplying [T R ] AB by the point matrix of the original cube
26
Rotation about an Arbitrary Axis oReflection Relative to the xy Plane oZ-axis Shear x z y x z y
27
Q1 - Translate by oA translation by an offset (tx, ty, tz) is achieved using the following matrix: oSo to translate by a vector (1, 1, 1), the matrix is simply:
28
Q2- Rotate by 45 degrees about x axis oSo to rotate by 45 degrees about the x-axis, we use the following matrix:
29
Q3 - Rotate by 45 about axis oSo a rotation by 45 degrees about can be achieved by a few succesive rotations about the major axes. Which can be represented as a single composite transformation n x = 1 n y = 1 n z = 1 SO
30
Q3 - Arbitrary Axis Rotation oThe composite transformation can then be obtained as follows: = ?? xyzxyz
31
Directions vs. Points oWe have looked at transforming points oDirections are also important in graphics oViewing directions oNormal vectors oRay directions oDirections are represented by vectors, like points, and can be transformed, but not like points oSay we define a direction as the difference of two points: d=a–b. This represents the direction of the line between two points oNow we translate the points by the same amount: a’=a+t, b’=b+t oHave we transformed d? (1,1)(-2,-1)
32
Homogeneous Directions oTranslation does not affect directions! oHomogeneous coordinates give us a clear way of handling this, e.g., direction (x,y) becomes homogeneous direction (x,y,0), and remains the same after translation: o(x, y, 0) is a vector, (x,y,1) is a point. oThe same applies to rotation and scaling, e.g., scaling changes the length of vector, but not direction oNormal vectors are slightly different though (can’t always use the matrix for points to transform the normal vector)
33
Alternative Rotations oSpecify the rotation axis and the angle (OpenGL method) oEuler angles: Specify how much to rotate about X, then how much about Y, then how much about oThese are hard to think about, and hard to compose oQuaternions o4-vector related to axis and angle, unit magnitude, e.g., rotation about axis (nx,ny,nz) by angle : oOnly normalized quaternions represent rotations, but you can normalize them just like vectors, so it isn’t a problem oBut we don’t want to learn all the maths about quaternions in this module, because we have to learn how to create a basic application before trying to make rotation faster
34
OpenGL Transformations oOpenGL internally stores two matrices that control viewing of the scene oThe GL_MODELVIEW matrix for modelling and world to view transformations oThe GL_PROJECTION matrix captures the view to canonical conversion oMapping from canonical view volume into window space is through a glViewport function call oMatrix calls, such as glRotate, glTranslate, glScale right multiply the transformation matrix M with the current matrix C (e.g., identity matrix initially), resulting in CM - the last one is the first applied
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.