Slide 1

Slide 1 text

Transforms @qcl 2015.02.12

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Transform ● Affine Transforms ○ CGAffineTransform ○ view.layer.affineTransform ● 3D Transforms ○ CATransform3D ○ view.layer.transfrom ○ view.layer.sublayerTransform

Slide 4

Slide 4 text

Affine Transforms ● Math behind the matrix ○ https://developer.apple. com/library/mac/documentation/GraphicsImaging/Co nceptual/drawingwithquartz2d/dq_affine/dq_affine. html#//apple_ref/doc/uid/TP30001066-CH204-

Slide 5

Slide 5 text

Affine Transforms ● Rotation ○ CGAffineTransformMakeRotation(CGFloat angle) ● Scale ○ CGAffineTransformMakeScale(CGFloat sx, CGFloat sy) ● Translation ○ CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty)

Slide 6

Slide 6 text

Combining Transforms ● CGAffineTransformIdentity ○ A 3x3 Identity matrix ● Rotation ○ CGAffineTransformRotate(CGAffineTransform t, CGFloat angle) ● Scale ○ CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy) ● Translation ○ CGAffineTransformTranslate(CGAffineTransform t, CGFloat tx, CGFloat ty) ● The order you apply transforms is important! ○ 矩陣乘法沒有交換律

Slide 7

Slide 7 text

Customized Affine Transform ● You can set the fileds of a CGAffineTransform directly. ○ a ○ b ○ c ○ d ○ t x ○ t y

Slide 8

Slide 8 text

3D Transforms

Slide 9

Slide 9 text

3D Transforms ● Left hand coordinate system

Slide 10

Slide 10 text

3D Transforms ● Rotation ○ CATransform3DMakeRotatation(CGFloat angle, CGFloat x, CGFloat y, CGFloat z) ● Scale ○ CATransform3DMakeScale(CGFloat sx, CGFloat sy, CGFloat sz) ● Translation ○ CATransform3DMakeTranslation(CGFloat tx, CGFloat ty, CGFloat tz)

Slide 11

Slide 11 text

3D Transforms Combination ● CATransform3DIdentity ○ A 4x4 identity matrix ● Rotation ○ CATransform3DRotate(CATransform3D t, CGFloat angle, CGFloat x, CGFloat y, CGFloat z) ● Scale ○ CATransform3DScale(CATransform3D t, CGFloat sx, CGFloat sy, CGFloat sz) ● Translation ○ CATransform3DTranslate(CATransform3D t, CGFloat tx, CGFloat ty, CGFloat tz)

Slide 12

Slide 12 text

Perspective Projection ● Prespective transform sometimes called Z transform

Slide 13

Slide 13 text

Perspective Projection ● m34 of CATransform3D ● -1 / d ● More: ○ http://en.wikipedia. org/wiki/3D_projection#Perspective_projection

Slide 14

Slide 14 text

Vanishing Point ● anchorPoint

Slide 15

Slide 15 text

sublayerTransform ● Apply to sublayer but not affect itself. ● The vanishing point is the anchorPoint of itself, not sublayer’s anchorPoint

Slide 16

Slide 16 text

Backfaces ● view.layer.doubleSided

Slide 17

Slide 17 text

Layer Flattening ● Expected result is wrong. ● The layers don’t exist in the same 3D space. ● The 3D sence in each layer is flattened.