Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rotate 3D on X in Flutter

I've been working with Flutter rotation,

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

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?

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

rotate3d diagram

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

like image 654
AbdulMomen عبدالمؤمن Avatar asked May 21 '18 23:05

AbdulMomen عبدالمؤمن


People also ask

How do I rotate my widgets 90 degrees in flutter?

Rotate Widget with RotatedBox():Pass -1 for 90o or -2 for 180o or -3 for 270o.


1 Answers

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)
      ),
    );

here is the result image

mobile flutter rotation 3d perspective

please read a little theory about this subject.

like image 200
AbdulMomen عبدالمؤمن Avatar answered Oct 29 '22 12:10

AbdulMomen عبدالمؤمن