1. 2D效果 CGAffineTransform? ( view.transform )
transform自定義方法 有6個參數(shù)
CGAffineTransformMake ( CGFloat a, CGFloat b, CGFloat c, CGFloat d, CGFloat tx, CGFloat ty );
x : a*x0 + c*y0 +? tx; (像素點寬)
y : b*x0 + d*y0 + ty; (像素點高)
原畫
旋轉(zhuǎn);
x : cos(θ)*x0 - sin(θ)*y0;
y : sin(θ)*x0 + cos(θ)*y0;
//偏轉(zhuǎn)加傾斜
CGFloatjd = -M_PI_4;
CGFloat scaleX = 0.5;
CGFloat scaleY = 1;
self.imageView.transform=CGAffineTransformMake(scaleX*cosf(jd),scaleY*sinf(jd),scaleX*-sinf(jd),scaleY*cosf(jd),0,0);
2. 3D效果 CATransform3D? ( view.layer.transform )
structCATransform3D
{
CGFloatm11, m12, m13, m14;
CGFloatm21, m22, m23, m24;
CGFloatm31, m32, m33, m34;
CGFloatm41, m42, m43, m44;
};
我找了一張課件的截圖
CATransform3D doctorTran = CATransform3DIdentity;
CGFloat jd = M_PI_4;
(1)旋轉(zhuǎn) rotate
繞Z軸
{?
cos(θ) ?,-sin(θ) ?狞贱,0 ?,0
sin(θ) ? 蜀涨, cos(θ) ?瞎嬉,0 ?,0
?0 ? ? ? ?厚柳,0 ? ? ? ? ?氧枣, 1 ?,0
?0 ? ? ? ?草娜,0 ? ? ? ? ?挑胸,0 ? 痒筒,1
}
doctorTran.m11 = cosf(jd);
doctorTran.m12 = -sinf(jd);
doctorTran.m21 = sinf(jd);
doctorTran.m22 = cosf(jd);
繞Y軸
{
cos(θ) ?宰闰,0 ?,sin(θ) ?簿透,0
0 ? ? ? ? 移袍,1 ?,0 ? ? ? ? 老充,0
-sin(θ) 葡盗,0 ?,cos(θ) ?啡浊,0
0 ? ? ? ? 觅够,0 ?胶背,0 ? ? ? ? ?,1
}
doctorTran.m11=cosf(jd);
doctorTran.m13=sinf(jd);
doctorTran.m31= -sinf(jd);
doctorTran.m33=cosf(jd);
繞X軸
{
1 ?喘先,0 ? ? ? ? ?钳吟,0 ? ? ? ? ,0
0 ?窘拯,cos(θ) ?红且,-sin(θ) ?,0
0 ?涤姊,sin(θ) ? 暇番,cos(θ) ?,0
0 ?思喊,0 ? ? ? ? 壁酬, 0 ? ? ? ? ,1
}
doctorTran.m22=cosf(jd);
doctorTran.m23= -sinf(jd);
doctorTran.m32=sinf(jd);
doctorTran.m33=cosf(jd);
(2)切變 shear
沿X軸
{
1 ?恨课,k ?厨喂,0 ?,0
0 ?庄呈,1 ?蜕煌,0 ?,0
0 ?诬留,0 ?斜纪,1 ?,0
0 ?文兑,0 ?盒刚,0 ?,1
}
doctorTran.m12=1;
沿Y軸
{
1 ?,0 ?扣猫,0 ?淹魄,0
k ?,1 ?涡上,0 ?,0
0 ?拒名,0 ?吩愧,1 ?,0
0 ?增显,0 ?雁佳,0 ?,1
}
doctorTran.m21=1;
(3)鏡像
基于Y-X平面
{
1 ?,0 ?糖权,0 ?堵腹,0
0 ?,1 ?星澳,0 ?秸滴,0
0 ?,0 ?募判,-1 荡含,0?
0 ?,0 ?届垫,0 ?释液,1
}
基于X-Z平面
{
1 ?,0 ?装处,0 ? 误债,0?
0 ?,-1 ?妄迁,0 ?寝蹈,0
0 ?,0 ?登淘,1 ? 箫老,0
0 ?,0 ?黔州,0 ? 耍鬓,1
}
基于Z-Y平面
{
-1 ?,0 ?流妻,0 ?牲蜀,0
0 ?,1 ? 绅这,0 ?涣达,0
0 ?,0 ? 证薇,1 ?度苔,0
0 ?,0 ? 棕叫,0 ?林螃,1
}
doctorTran.m11= -1;
(4)透視投影
m34 = -1/d;
d值決定了觀察點的位置,d為正無窮大的時候俺泣,觀察點在無窮遠(yuǎn)處,此時投影線垂直于投影平面,CATransform3D中m34的默認(rèn)值為0伏钠,即觀察點在無窮遠(yuǎn)處横漏。m14,m24同理。
- (CATransform3D) get3DTransform {
CATransform3D?transform?=?CATransform3DIdentity;
transform.m34?=?1.0?/?-2000;
return?transform;
}
旋轉(zhuǎn)Y軸時 錨點默認(rèn)(0.5熟掂,0.5)
//doctorTran.m14 = 1.0/-300.0;//x
?doctorTran.m24 = 1.0/-300.0;//y
//doctorTran.m34 = 1.0/-300.0;
doctorTran.m11=cosf(jd);
doctorTran.m13=sinf(jd);
doctorTran.m31= -sinf(jd);
doctorTran.m33=cosf(jd);
旋轉(zhuǎn)Z軸時 讓視角離得更近
//doctorTran.m14 = 1.0/-300.0;//x
doctorTran.m24=1.0/-100.0;//y
//doctorTran.m34 = 1.0/-300.0;
doctorTran.m11=cosf(jd);
doctorTran.m12= -sinf(jd);
doctorTran.m21=sinf(jd);
doctorTran.m22=cosf(jd);