在Flutter中在X上旋转3D [英] rotate 3D on X in Flutter

查看:360
本文介绍了在Flutter中在X上旋转3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在进行Flutter旋转,

I've been working with Flutter rotation,

new Matrix4.identity() ..rotateX(degrees * 3.1415927 / 180),

new Matrix4.identity() ..rotateX(degrees * 3.1415927 / 180),

但是,问题是,我希望它类似于下图. Flutter如何在x轴上实现类似3D的旋转?

but, the problem, I want it to be similar to the diagram below. can I achieve a 3D-like rotation on the x-axis with Flutter?

即使存在从3D到2D的映射或其他选择 那会得到相同的结果. 预先感谢.

even if there is a mapping from 3D to 2D or there are alternatives that would get the same result. thanks in advance.

OpenCV中的示例图片:如何计算透视图从旋转角度转换成OpenCV?

Example image in OpenCV: How to calculate perspective transform for OpenCV from rotation angles?

推荐答案

感谢此讨论此存储库,并经过一天多的时间寻找答案,

thanks to this discussion, and this repo, and after more than a day seeking the answer,

static Matrix4 _pmat(num pv) {
    return new Matrix4(
      1.0, 0.0, 0.0, 0.0, //
      0.0, 1.0, 0.0, 0.0, //
      0.0, 0.0, 1.0, pv * 0.001, //
      0.0, 0.0, 0.0, 1.0,
    );
}

Matrix4 perspective = _pmat(1.0);


// then use it

new Center(
      child: new Transform(
        child: new FittedBox(
          fit: BoxFit.fill,
          child: LogoWidget(),
        ),
        alignment: FractionalOffset.center,
        transform: perspective.scaled(1.0, 1.0, 1.0)
          ..rotateX(math.pi - degrees * math.pi / 180)
          ..rotateY(0.0)
          ..rotateZ(0.0)
      ),
    );

这是结果图片

请阅读 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆