1

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?

Community
  • 1
  • 1
Holden
  • 53
  • 6

1 Answers1

1

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);
Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • I hope you do realise you went after bad example. Even the answer on your link is said to be faulted. If this code works for you now (it should actually) it might not work after next update as any of the matrix' structure might be changed. – Matic Oblak May 29 '14 at 08:58
  • Thanks!!I know I have to improve some skills.but the 3D world is so complicated for me now,I have to depend on other's codes to complete my work,and you help me to solve my problem about GLFloat and CGFloat. – Holden May 29 '14 at 09:26