Image:CocoaNav icon.png

PARMANOIR

Projected coordinates of a 3D CALayer

There's no explicit method to get projected coordinates of a 3D CALayer, but you can use convertRect:fromLayer to almost get them. Thanks to Simon Fraser on the Quartz ML for that.

Suppose you have layers setup like that :

rootLayer
  layerHavingA3DTransform
    layer1
    layer2
    layer3

layer1, layer2, layer3 will be transformed by layerHavingA3DTransform and will appear 3D. To get their projected coordinates, use

CGRect projectedRect = [layer1 convertRect:localRect toLayer:[self layer]];

This will transform localRect, a rect in layer1 coordinates to root layer coordinates. If you want the layer extent, that's -bounds.width/2, -bounds.height/2, bounds.width, bounds.height for the default anchorPoint of (0.5, 0.5). Note that projectedRect is in layer coordinates, not in NSView coordinates. For this case I had manually centered layerHavingA3DTransform in the view and got coordinates reflecting that, going from -size to +size.

I only tested axis aligned layers. If you want coordinates from a rotated layer, you might try convertPoint:fromLayer to convert each layer point.

2008 07 25Where in build phases is that file ?
2008 07 192Imagine clickable error messages
2008 07 18Succulent Stormhoek
2008 07 173Loving the for
2008 07 12(Parmanoir) Feed now validates
2008 07 108Telling classes from instances
2008 07 08Comma Trick
2008 07 06Using libffi
2008 07 04BridgeSupport's type and type64
2008 07 042Clickable Disabled MenuItems
2008 07 026Less bugs through compiler optimizations
2008 06 251CocoaNav JS, a light CocoaNav for Safari
2008 06 232NSWindow goodies : bottomCornerRounded, usesLightBottomGradient
2008 06 222Inspecting NSUndoManager's undo stack
2008 06 16Cocoa Regular Expressions via JavascriptCore
2008 06 15Crossing the WebKit bridge
2008 06 08Double and Triple Click
2008 06 05Photoshop-like compositing with Core Animation
2008 06 052One way binding to NSSlider
2008 05 30Threaded Core Animation, Part Deux
Image:rss.png
Image:rss.png

Powered by MediaWiki

Hi ! I'm learning Cocoa to (hopefully !) become an indie developer.

I've written software all my professional life, in C++, PHP, Javascript. I've designed websites and web interfaces. My last venture went into flames as clients were happy but didn't like paying very much.

I've had little luck in the B2B world, I'm hoping for a better future writing Mac applications.

Planet Cocoa