3D projection in Flash

Source: Internet
Author: User

Original address:www.bit-101.com/tutorials/perspective.html
Original Author: Keith Peters
PS: The first translation, wrong please point out.

Here I have a simple interpretation of 3D projection, first of all, we look at 3D perfect use of the site:http://www.voxangelica.net

In the new Masters of Flash 2002 annual read his published article and learned a lot, I now try to analyze this 3D effect:
------
The most basic 3D projection formula is:
scale=fl/(FL+Z);
Here I understand scale for projection proportions
FL is the focus distance (i.e. the distance from the eye to the screen)
Z is the depth of the object in the screen;
---------------
Look at the section below:

You can know the focal length F1 and (Z+F1);
scale=fl/(FL+Z);
here defines f1=150;
If z=0, you can draw:
Scale = 150/(150+0);

And look at the following:
If z=100, you can draw:
Scale = 150/(150+100);
The projection scale will be 0.6.
If z=500 (far away from the screen ...) )
Scale = 150/(150+500);
The projection ratio will be about 0.23;

From the above you can see that when you increase the z, the projection ratio scale will be smaller and closer to 0, when Z is just 0 or just on the screen, the projection ratio will be 1.

But how to use the projection ratio? You will see from the illustration above that when the distance from the screen becomes larger, there are two things that are reduced:
1. The size of the object;
2. The closer the month to the midpoint or vanishing point;
But in the flash language only and _xscale and _yscale and _x and _y.
Below you will learn how to use it, first you want to define your x,y and Z values, you can write this:

scale=fl/(FL+Z);
_x=x*scale;
_y=y*scale;
_xscale = _yscale = scale*100;

You can see that the horizon or vanishing point is at (0,0) point. In general, when objects are farther away from you, they will be close to vanishing Point (0,0), and in Flash, the point in the upper-left corner of the main stage, if you want to put your object in the middle of the screen, you can write as follows:

xcenter=275;
ycenter=200;
scale=fl/(FL+Z);
_x=x*scale+xcenter;
_y=y*scale+ycenter;
_xscale = _yscale = scale*100;

Now you have to understand that the left side of the center is the negative direction of the x-axis, the positive direction is the right side of the center point, the negative direction of the Y axis is above your line of sight, and the square of the Y axis is below.

I hope you can understand and use what I say and constantly make it evolve more interesting; If you succeed, please be sure to tell me if you have any comments or a deep analysis of the final conclusions, please send me a copy of the reference, thank you.

Download source files



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.