Android camera gets the study of matrix acting on canvas

Source: Internet
Author: User

On the Internet to check the relevant articles, think that they understand, but the actual test and online said is not the same (later research found that the person wrote is wrong!!!) , therefore, remind everyone to be bold in questioning and ask questions.

First, the camera class, this class is located under the package Android.graphics, for the image 3D transformation, through rotation, offset, and so on, finally through the Getmatrix (matrix) method to get the matrix, for the canvas, Make the picture appear stereoscopic effect.

Camera's source code is nothing to see, here is the main way to enumerate him:

    public native void Save ();    Public native void Restore ();    public native void translate (float x, float y, float z);    public native void Rotatex (float deg);    public native void Rotatey (float deg);    public native void Rotatez (float deg);    public native void rotate (float x, float y, float z);    Public native float Getlocationx ();    Public native float Getlocationy ();    Public native float Getlocationz ();    public native void setlocation (float x, float y, float z);    public void Getmatrix (Matrix matrix) {        Nativegetmatrix (matrix.native_instance);    }    public void Applytocanvas (canvas canvas) {        Nativeapplytocanvas (Canvas.mnativecanvas);    }    Public native float Dotwithnormal (float dx, float dy, float dz);

These methods do not seem to be difficult to understand, through the literal meaning can be roughly understood, the last of the methods have not been studied, the later study on the complement.


Then we look at several axis coordinates of the camera transformation, the figure is a bit ugly ha.


This is the correct x, y, z coordinate, and the other is the left-hand coordinate of the article, which, after my verification, was written by the author is wrong.

camera at coordinate point O Point (0,0,0), which is the upper-left corner of the diagram

Rotate

Then we look at how to rotate, we assume we can rotate the coordinate system in the diagram, we rotate the coordinate system so that the x-axis is pointing in the direction of us, that is, we see that the point A and O are coincident (can you understand?) Do not understand to take a block of things to turn their own view). Then, it rotates clockwise, and then we look at it from the screen of the phone, and we see the change.

Let's look at one more example: Camera.rotatey (45)

He meant to rotate 45 degrees clockwise around the y-axis. If the middle and y axes of the object coincide, the clockwise rotation around the y-axis is 45 degrees, which means the right half of the object flips inward and the left half is flipped outward;

Camera.rotatex (45) means rotating 45 degrees clockwise around the x-axis. For example, if an object's middle and x-axis coincide, a 45-degree clockwise rotation around the x-axis means that the upper half of the object flips inward and the lower half flips outward;

Camera.translate (40, 30, 30) means, in the picture is to move the object to the right 40, move down 30, to the positive z-axis shift 20 (that is, the object away from the screen, the object will become smaller);


Let's look at a few graphs to deepen our understanding:

First, the original:


To transform: Camera.rotatex (60);


To transform: Camera.rotatey (60);


To transform: Camera.rotatez (-60); (Here is-60 ha)


The translate is similar to the canvas's offset and is no longer indicative.

Android camera gets the study of matrix acting on canvas

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.