iOS extracts: CGAffineTransformInvert


extracts from 《Beginning iPhone Games Development》

Let’s tell Quartz 2D to put our canvas back in the default or (0,0) position. We do this byasking for the current transformation, a mathematical matrix describing how the canvaswas moved from its original location, orientation, and scale. The canvas could be in anystate. We then calculate the exact opposite motion, which in mathematics is called theinverse matrix. Finally, we ask Quartz 2D to apply the inverse matrix to the currenttransformation. Since the transformations are affine, and since all affine transformationsare reversible, this will place our canvas back to the default location.

We need three lines of code:

CGAffineTransform t0 = CGContextGetCTM(context);
t0 = CGAffineTransformInvert(t0);
CGContextConcatCTM(context,t0);

CGContextGetCTMreturns the graphic context’s transformation matrix orCTM, as a matrixdata structure. We callCGAffineTransformInvertto create the inverse matrix. We thencallCGContextConcatCTM, which will concatenate our new matrixt0with the existingmatrix.Concatenationis the act of multiplying the matrix you supply (t0in this case) withthe current drawing matrix. When any matrix is multiplied by its inverse, we get theidentity matrix. The identity matrix restores the canvas to its original, native state, asthough no transformations were performed. 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值