Coordinate system in unity--screen to world coordinates

Source: Internet
Author: User

Camera.screentoworldpoint
Vector3 Screentoworldpoint (Vector3 position);

Converts screen coordinates to world coordinates.

How to convert? Given a so-called screen coordinate (x, y, z), how do you convert it to world coordinates?

First, we need to understand how the camera renders the object:

The camera's rendering range for the game world is a flat-truncated body, and the rendering boundary is a rectangle that intercepts the flat-truncated body with a plane parallel to near Clippingplane or far clippingplane, and can obtain countless parallel rectangular faces, the screen rectangle we see. The farther away from the camera, the larger the rectangle, the closer the camera is to the smaller the rectangle. So, objects of the same size, as they get farther away from the camera, tend to look smaller and smaller relative to the corresponding screen rectangles.

On the screen, the position of a pixel relative to the screen rectangle can correspond to the position of a point in the game world relative to a section, and the key is the section on which the point is located, that is, how far this section is from the camera!

In Screentoworldpoint this method, the parameter is a three-dimensional coordinate, in fact, the screen coordinates can only be two-dimensional coordinates. The z-coordinate in the parameter is used to indicate the distance from the camera to the above plane.

In other words, given a coordinate (x, y, z),

First, we intercept a plane p that is perpendicular to the z axis of the camera, and the distance is Z, so that regardless of how X, y changes, the returned points are only on this plane;

Then, X, y represents pixel coordinates and, depending on the location of the (x, y) relative to the screen, gets the position of the point in the game world in relation to the section P, and we also convert the screen coordinates to world coordinates.

The statement in the official website document:

Camera.screentoworldpoint

Vector3 Screentoworldpoint (Vector3 position);
Description
Transforms position from the screen space to the world space.

Screenspace is defined in pixels. The bottom-left of the screen is (0,0); The Right-top is (pixelwidth,pixelheight). The z position is on world units from the camera.

  transferred from: http://blog.csdn.net/czlilove/article/details/21173669

Coordinate system in unity--screen to world coordinates

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.