I want to convert GLKMatrix4
and CATransform3D
,and I use this method:
CATransform3D t;
GLKMatrix4 t2 = *((GLKMatrix4 *)&t);
t = *((CATransform3D *)&t2);
form: (Convert GLKMatrix4 and CATransform3D).
it work well at 32bit,but can't work in 64bit equipments,and I found the reason is that,GLKMatrix4
is using Float and CATransform3D
is using CGFloat
,as we know,they are treated different in different bit machines,so this codes can't work in 64bit equipments,here someone can convert it?
GLMatrix4
code:
GLKQuaternion _rotationEnd;
GLKVector2 _translationEnd;
float _depth;
float _scaleEnd;
GLKMatrix4 modelViewMatrix = GLKMatrix4Identity;
GLKMatrix4 quaternionMatrix = GLKMatrix4MakeWithQuaternion(_rotationEnd);
modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, _translationEnd.x, _translationEnd.y, -_depth);
modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, quaternionMatrix);
modelViewMatrix = GLKMatrix4Scale(modelViewMatrix, _scaleEnd, _scaleEnd, _scaleEnd);
How I fix it using CATransform3D
?
To solve this generally I suggest you crate the 2 buffers and iterate through them. Try something like this:
GLKMatrix4 input;
CATransform3D output;
GLfloat glMatrix[16];
CGFloat caMatrix[16];
memcpy(glMatrix, input, sizeof(glMatrix)); //insert GL matrix data to the buffer
for(int i=0; i<16; i++) caMatrix[i] = glMatrix[i]; //this will do the typecast if needed
output = *((CATransform3D *)caMatrix);