矩阵的变换
矩阵的平移
直接平移
posOS.xyz += vector.xyz (posOS对象空间顶点 vector类型属性)
利用矩阵平移
代码
float4x4 moveMatrix = float4x4(
1,0,0,_MoveUv.x,
0,1,0,_MoveUv.y,
0,0,1,_MoveUv.z,
0,0,0,1
);
v.posOS = mul(moveMatrix,v.posOS);
缩放矩阵
直接缩放
posOS.xyz *= vector.xyz (posOS对象空间顶点 vector类型属性)
矩阵缩放
矩阵的旋转
公式推导
X值推导
y值推导
公式
//(仅沿z轴方向 进行旋转)
float2x2 angleMatrix = float2x2(
cos(_Angle), sin(_Angle),
-sin(_Angle), cos(_Angle)
);
v.posOS.xy = mul(angleMatrix, v.posOS.xy);
沿X轴旋转(使用矩阵)
//(仅沿x轴方向 对三维坐标 旋转矩阵)
float4x4 angleMatrixX = float4x4(
1,0,0,0,
0,cos(_Rotation.x),sin(_Rotation.x),0,
0,-sin(_Rotation.x),cos(_Rotation.x),0,
0,0,0,1
);
v.posOS = mul(angleMatrixX,v.posOS);
沿Y轴旋转(使用矩阵)
//(仅沿y轴方向 对三维坐标 旋转矩阵)
float4x4 angleMatrixY = float4x4(
cos(_Rotation.y), 0, sin(_Rotation.y), 0,
0, 1, 0, 0,
-sin(_Rotation.y), 0, cos(_Rotation.y), 0,
0, 0, 0, 1
);
v.posOS = mul(angleMatrixY, v.posOS);
沿Y轴旋转(使用矩阵)
//(仅沿z轴方向 对三维坐标 旋转矩阵)
float4x4 angleMatrixZ = float4x4(
cos(_Rotation.z), sin(_Rotation.z),0, 0,
-sin(_Rotation.z), cos(_Rotation.z),0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
v.posOS = mul(angleMatrixZ, v.posOS);
111