【发布时间】:2017-11-26 05:26:54
【问题描述】:
我正在阅读this article,它解释了如何使用MatrixMath 在本机反应中进行旋转变换。我正在尝试为对象的比例设置动画,而不是旋转,我希望它使用对象左上角的原点而不是中心进行缩放。谁能解释一下如何做到这一点?
旋转矩阵的相关代码位是:
const matrix = transformUtil.rotateX(dx);
transformUtil.origin(matrix, { x: 0, y, z: 0 });
const perspective = this.props.perspective || rootDefaultProps.perspective;
ref.setNativeProps({
style: {
transform: [
{ perspective },
{ matrix },
],
},
});
并且,从 transformUtil:
import MatrixMath from 'react-native/Libraries/Utilities/MatrixMath';
function transformOrigin(matrix, origin) {
const { x, y, z } = origin;
const translate = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate3dCommand(translate, x, y, z);
MatrixMath.multiplyInto(matrix, translate, matrix);
const untranslate = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate3dCommand(untranslate, -x, -y, -z);
MatrixMath.multiplyInto(matrix, matrix, untranslate);
}
function rotateX(deg) {
const rad = (Math.PI / 180) * deg;
const cos = Math.cos(rad);
const sin = Math.sitransfn(rad);
return [
1, 0, 0, 0,
0, cos, -sin, 0,
0, sin, cos, 0,
0, 0, 0, 1,
];
}
export default {
rotateX,
origin: transformOrigin,
};
【问题讨论】:
标签: javascript react-native matrix transform