Coordinate Transformation of self-made 45-degree 2D Engine

Source: Internet
Author: User
This is an example of self-made oblique 45-degree coordinate conversion. We divide the coordinates into four conversion systems: the plane series, the inclined series, the rotation series, and the screen series. These are all coordinate systems with the O as the origin. During the conversion, except for the screen series, it needs to be converted in order. In reverse conversion, reverse conversion is also required. However, when you need to display the effect of a coordinate system

This is an example of self-made oblique 45-degree coordinate conversion. We divide the coordinates into four conversion systems: the plane series, the inclined series, the rotation series, and the screen series. These are all coordinate systems with the O as the origin. During the conversion, except for the screen series, it needs to be converted in order. In reverse conversion, reverse conversion is also required. However, when you need to display the effect of a coordinate system

This is an example of self-made oblique 45-degree coordinate conversion. We divide coordinates into four conversion systems:

Plane Series

Inclined Series

Rotating Series

Screen Series

These systems are coordinate systems with O as the origin. In the conversion process, except for the screen system, they need to be converted in order. In reverse conversion, they also need to be converted in reverse order.

However, when you need to display the effect of a coordinate system, you can directly convert the coordinate point of this system to the point of the screen system.

Plane System (xOfy): Like the god's perspective, this system indicates the position of an object on the plane. It is the most common and intuitive coordinate system. Because it is intuitive and easy to calculate,

Therefore, the search and sorting of objects are implemented by the flat system.

Inclined series (xOly): the inclined series are converted from the plane series, which can be seen as a piece of paper formed from the vertical down to a certain angle. This system is a quasi-45

Degree plane, you can see that the paper is a parallelogram.

Rotation System (xOry): formed by a certain angle of rotation of the inclined series, a piece of paper in the inclined series not only falls down, but also rotates around the O point. In this way, the point originally on the X axis is in the inclined line.

It is still on the X axis, but it is no longer on the X axis in the rotation system.

Screen System (xOsy): the screen system defines the screen size (red box in the figure) and the Direction vector of the screen relative to the origin O. In addition, the screen coordinate is opposite to the Y axis of other coordinate systems.

The point on the screen is the point needed for final plotting, while the point on the plane is the point required by background computing,Generally, the conversion between the two coordinate systems is used.

1. The conversion from the plane to the inclined series: (the formula is written on the diagram because the format is messy)

2. inclined series to rotation series conversion:

3. Conversion from other series to screen series:

You need to create a screen offset Origin O vector. during conversion, the coordinates of other systems are subtracted from the vector, and then the y direction is reversed.

X' = x-vect.x;

Y' = scrn. y-(y-vext.y );

4. Test

The following figure shows a red figure with a diamond falling from the plane to the screen. The four dots are

(300,300 );
(400,200 );
(400,400 );
(500,300 );

A blue image is the shape that is converted to the rotation system and then to the screen system. The line drawn from the upper left corner is the test point, the blue is the point where the mouse is located, and the red is the point for real-time conversion, which indicates that the conversion is correct.

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.