What's the meaning of m34 of the structure CATransform3D, I only know it can change the perspective, but what's the meaning when the value is -0.001 and 0.001?
Asked
Active
Viewed 1.1k times
19
-
1m34 means "The entry at position 3,4 in the matrix." https://developer.apple.com/documentation/quartzcore/catransform3d/1436566-m34 – Koen. Sep 21 '20 at 07:56
2 Answers
21
You can find the full details here. Note that Apple uses the reversed multiplication order for projection (relative to the given link) so all matrix multiplications are reversed and all matrices are transposed.
A short description of the meaning:
- m34 = 1/z distance to projection plane (the 1/ez term in the reference link)
- + for the z axis is towards the viewer, resulting in a "looking in the mirror" feel when using -
- projection center is (0,0,0) plus any translations you set up
![](../../users/profiles/757408.webp)
Mihai Timar
- 1,133
- 13
- 21
-
What is ``1/z``? I still don't get your explanation. What means m34? What does changes do? – confile Jun 04 '15 at 00:51
-
1z is the distance to your projection plane, m43 = 1/z. I've updated the answer to make this point a bit clearer. Changes change the distance and make the perspective look different on the same scene. – Mihai Timar Jun 05 '15 at 11:06
2
I read some articles including this one: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW13
My solutions is here:
Entities:
eye
- distance from screen to eyescale
- visual scale of transformed objectdistance
- distance to transformed object
Connecting formulas:
scale = eye / (eye + distance)
distance = eye * (1.0/scale - scale)
eye = distance / (1.0/scale - scale)
Example of computing z-distance for desized scale of selected eye distance:
CATransform3D transformByScaleAndEye(CGFloat scale, CGFloat eye) {
CATransform3D t = CATransform3DIdentity;
t.m34 = -1.0 / eye;
CGFloat distance = -eye*(1.0/scale - scale);
return CATransform3DTranslate(t, 0, 0, distance);
}
![](../../users/profiles/440168.webp)
k06a
- 14,368
- 10
- 57
- 97