Core Animation is right handed

Right handed ? Count to 3 on your left and right hands. Align your fingers so that each finger is perpendicular to the other two. One, two, three gives the axes : X, Y, Z. Line up your hands so that X goes left and Y goes up. Now each hand's Z goes opposite the other's. Your right hand is your Core Animation frame, same as OpenGL.

For some reason I thought CA was left handed — I had my layers set with a positive Z value. The layers showed up where I was expecting them, but visually it was a mess : the far layers were drawn on top of the near layers ! Using a negative Z value fixed the glitch.

Perspective in CA, using 3D CALayers and a perspective transform :

your eye     layers are closer (bigger) here         layers have same size as in 2D        layers are farther (smaller) here

------------------ positive Z value ------------------------- zero Z value ----------------------- negative Z value---------

2008 05 01

Not to be a dick, but there is this thing called the "right hand rule" for 3-spaces.

Patrick Geiller
2008 05 01

Ah thanks, I didn't know the official name, just "* handed".

Anyway if you come from DirectX and code in Core Animation, hands are reversed. In a 3D engine, setting a badly signed Z value on layers would make them invisible. CA did draw them, inversely sorted.

2008 05 04

Pour être précis, cette "règle de la main droite" signifie géométriquement qu'on choisit une base orthonormée directe de l'espace de dimension 3, alors qu'utiliser la main gauche conduirait au choix d'une base indirecte de l'espace ... ce qu'on fait moins souvent dans la pratique, pour des raisons de convention: sinon, il faudrait par exemple changer l'expression matricielle des rotations en dimension 3, etc. etc. Enfin, tant que c'est de la 2d augmentée, il faut juste savoir que l'axe des Z pointe vers le codeur et non pas l'écran !

Patrick Geiller
2008 05 04

Merci pour l'explication mathématique :)

2023 02 25

I don't think this is correct. X right, Y up and Z out of screen is right-handed. But CoreAnimation is not Y up, it is Y down. So it is actually left-handed, but with Z out of screen.

Follow me on Twitter
Planet Cocoa

2011 02 22Distance field
2010 07 202Binding through NSApp
2010 05 122Forwarding invocations
2010 02 272Core Image black fringes
2010 02 21Quickest Way to Shell
2010 02 08Who's calling ?
2009 09 2138 ways to use Blocks in Snow Leopard
2009 08 182Bracket Mess
2009 08 124Taming JavascriptCore within and without WebView
2009 04 15Debugging with Activity Monitor
2009 03 25How Core Image Color Tracking works
2009 03 1510Custom NSThemeFrame
2009 03 10Which framework is running ?
2009 03 074CoreUI can paint pretty big
2009 02 18Localization with functions
2009 01 30Did you forget to nest alloc and init?
2009 01 16JSCocoa on the iPhone
2009 01 11Mixing WebView and JavascriptCore
2009 01 09Badge overflow
2009 01 09Find your Garbage Collection leaks with Instruments

Powered by MediaWiki