Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CATransform3D vs. CGAffineTransform?

Tags:

Whats the difference between the two?

I'm sure they have pros and cons, and situations they are better performers in.

Any resources that compare the two?

Is one better for animation (I imagine the CATransform3D)? Why?

Also I think I read somewhere that text clarity can be an issue, is one better at scaling text?

like image 399
Corey Floyd Avatar asked Feb 20 '09 00:02

Corey Floyd


2 Answers

As MSN said, they are used in different cases. CGAffineTransform is used for 2-D manipulation of NSViews, UIViews, and other 2-D Core Graphics elements.

CATransform3D is a Core Animation structure that can do more complex 3-D manipulations of CALayers. CATransform3D has the same internal structure as an OpenGL model view matrix, which makes sense when you realize that Core Animation is built on OpenGL (CALayers are wrappers for OpenGL textures, etc.). I've found that this similarity of internal structure, combined with some nice helper functions that Apple provides, can let you do some neat OpenGL optimizations, as I post here.

When it comes down to choosing which do use, ask yourself if you're going to work with views directly in a 2-D space (CGAffineTransform) or with the underlying Core Animation layers in 3-D (CATransform3D). I use CATransform3D more frequently, but that's because I spend a lot of time with Core Animation.

like image 199
Brad Larson Avatar answered Sep 28 '22 00:09

Brad Larson


One is for linear 2d transformations, the other is for three dimensional projected transformations. At least that's what I could glean from the documentation.

If you don't need to render 3d projected onto the screen, use the affine transform. Otherwise, use the 3d transform. The 3d transform is essentially a 4x4 matrix, while the 2d affine one is 3x2.

like image 30
MSN Avatar answered Sep 28 '22 01:09

MSN