@cvp
Looks like @cvp came to the rescue with my untested code. But here is the original, marked up with the intent. You can do google search for iOS headers CATransform3D, and get the c header files describing the various structure and functions, then just have to manually translate. The way CFUNCTION wrappers work, the doll contains the symbol, but you have to manually set return type (restype) and argument types argtypes.
The low level stuff is slightly trickier to work it’s compared to actual ObjC. When converting objc code, you usually don’t need to mess with any of that, because the method encodings define everything, and are built into the runtime. But when passing structures instead of objects, you often have to override restypes. Rubicon handles this cleaner than the current objc_util…
from objc_util import *
from ctypes import *
import ui
import math, copy
'''we need to wrap the CATransform structure
struct CATransform3D
{
CGFloat m11, m12, m13, m14;
CGFloat m21, m22, m23, m24;
CGFloat m31, m32, m33, m34;
CGFloat m41, m42, m43, m44;
};
this could also have been done with a pack
'''
class CATransform3D(Structure):
_fields_ = [('m11', CGFloat),('m12', CGFloat),('m13', CGFloat),('m14', CGFloat),
('m21', CGFloat),('m22', CGFloat),('m23', CGFloat),('m24', CGFloat),
('m31', CGFloat),('m32', CGFloat),('m33', CGFloat),('m34', CGFloat),
('m41', CGFloat),('m42', CGFloat),('m43', CGFloat),('m44', CGFloat),
]
'''
note, c is a variable imported in objc_util, which is the cDLL for the static library.
'''
'''
/* Returns a transform that translates by '(tx, ty, tz)':
* t' = [1 0 0 0; 0 1 0 0; 0 0 1 0; tx ty tz 1]. */
CA_EXTERN CATransform3D CATransform3DMakeTranslation (CGFloat tx,
CGFloat ty, CGFloat tz)
'''
CATransform3DMakeTranslation = c.CATransform3DMakeTranslation
CATransform3DMakeTranslation.argtypes = [CGFloat, CGFloat, CGFloat]
CATransform3DMakeTranslation.restype = CATransform3D
'''
/* Rotate 't' by 'angle' radians about the vector '(x, y, z)' and return
* the result. If the vector has zero length the behavior is undefined:
* t' = rotation(angle, x, y, z) * t. */
CA_EXTERN CATransform3D CATransform3DRotate (CATransform3D t, CGFloat angle,
CGFloat x, CGFloat y, CGFloat z)
'''
CATransform3DRotate = c.CATransform3DRotate
CATransform3DRotate.restype = CATransform3D
CATransform3DRotate.argtypes = [CATransform3D, CGFloat, CGFloat, CGFloat, CGFloat]
''' named const can often be retrieved using in_dll. however, we need a mutable copy, so we dont wat to use this as identity'''
CATransform3DIdentity=CATransform3D.in_dll(c,'CATransform3DIdentity')
identity=copy.deepcopy(CATransform3DIdentity)
'''other ways to get identity:
identity = CATransform3D()
identity.m11=1
identity.m22=1
identity.m33=1
identity.m44=1
or
identity=CATransform3DMakeTranslation(0,0,0)
note, we cant use CATransformMake because that is a c macro, not an exported function
'''
v=ui.View(frame=(0,0,500,500))
v.bg_color='white'
sv=ui.ImageView()
sv.image=ui.Image.named('card:Clubs3')
sv.size_to_fit()
v.add_subview(sv)
v.present('sheet')
layer = sv.objc_instance.layer()
#another way to get current transrorm
#identity=layer.transform(argtypes=[],restype=CATransform3D)
identity.m34 = -1/500 #sets perspective
#rotate
rot = CATransform3DRotate(identity, math.radians(55), 0,1,0)
layer.setTransform_(rot,argtypes=[CATransform3D],restype=None)