Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get CATransform3D from Projection and ModelView matrices?
    primarykey
    data
    text
    <p>all,<br><br> I've got an iphone project that draws a 3D model using OpenGL-ES for a given model view matrix and given projection matrix. I needed to replace 3D model with CALayer, so I put values of model view matrix into CATransform3D structure and assigned it to <code>layer.transform</code>. It worked well, layer was visible and moved on the screen as expected, but after some time I realized that my layers behavior is not precise enough and I should take projection matrix into account. And then a problem appeared: when I simply concatenate two matrices my layer looks odd (it is very small, about 2 pixels, while it is supposed to be about 300, as it is far far away) or is not visible at all. How can I solve it?</p> <p>Here is the piece of code:</p> <pre><code>- (void)adjustImageObjectWithUserInfo:(NSDictionary *)userInfo { NSNumber *objectID = [userInfo objectForKey:kObjectIDKey]; CALayer *layer = [self.imageLayers objectForKey:objectID]; if (!layer) { return; } CATransform3D transform = CATransform3DIdentity; NSArray *modelViewMatrix = [userInfo objectForKey:kModelViewMatrixKey]; // Get raw model view matrix; CGFloat *p = (CGFloat *)&amp;transform; for (int i = 0; i &lt; 16; ++i) { *p = [[modelViewMatrix objectAtIndex:i] floatValue]; ++p; } // Rotate around +z for Pi/2 transform = CATransform3DConcat(transform, CATransform3DMakeRotation(M_PI_2, 0, 0, 1)); // Project with projection matrix transform = CATransform3DConcat(transform, _projectionMatrix); layer.transform = transform; } </code></pre> <p>Any help will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload