[Basic knowledge of Android] view animation article 2, camera 3D effect

Source: Internet
Author: User
In the previous article, I introduced how to customize view animation in Android, which uses a matrix transformation method for animation processing. For details, refer to my previous article:
[Basic Android knowledge] creating your own animation Effects


Through the transformation matrix introduced in this article, we can achieve most of the animation effects. However, most of this method implements a 2D effect, what are the methods to achieve the effect of 3D space? Next we will introduce the camera class, which means cameras in Chinese. Of course, this is not the camera used for photography on our mobile phone. This is a logical concept, compare the screen of our mobile phone to the camera window. Through this window, we can see what is displayed in it (that is, the interface of our application). Of course, if we look at the objects on the screen from different angles, naturally, there will be a three-dimensional effect. What does it mean from different angles? For example, if there is a cup on the table, we can see it on the front, from the end, we can see that it is another one.

This concept should not be hard to understand, and the camera class is used to do this. Let's take a look at the following code:

  1. Private camera = new camera ();
  2. .......
  3. Protected void applytransformation (float interpolatedtime, transformation T ){

  4. Final matrix = T. getmatrix ();

  5. Camera. Save ();
  6. Camera. Translate (0.0f, 0.0f, (3000-3000.0f * interpolatedtime ));
  7. Camera. rotateys (360 * interpolatedtime );

  8. Camera. getmatrix (matrix );

  9. Matrix. pretranslate (-halfwidth,-halfheight );
  10. Matrix. posttranslate (halfwidth, halfheight );

  11. Camera. Restore ();
  12. }

Copy code

The following explains the basic concepts of my previous article. If you need to know the pre-knowledge, refer to the previous article.


Similar to the previous article, we first got a transformation matrix, camera. save () saves the current camera position so that the camera can be restored to the original position after the transformation is completed. Next, call camera. translate. This method accepts three parameters, x, y, and z. Here we only offset the Z axis, and the starting offset is 3000, over time, this offset will become smaller and smaller. This will produce such an effect. Our view is moving from a very long distance to us, getting closer and closer, and finally moving to the top of our window ~

The camera. rotatey (360 * interpolatedtime) clause adds a rotation effect to our view. During the moving process, the view also shifts the Y axis to the center for rotation.

The following camera. getmatrix (matrix), which applies a series of transformations we just defined to the transformation matrix. After calling this sentence, we can restore the location of camera, for the next use. The next call has been introduced in the previous article, so I will not repeat it again ~, After this code is completed, we can see the 3D animation effect ~


Previous:

Animdemo.zip

29.69 kb, downloads: 525, download points: ecoins-1 RMB

Sample Code

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.