Coordinate systems in the U3D

Source: Internet
Author: User

The transform (Transform) values in the viewer (Inspector) of any child game object (gameobject) are displayed relative to the transformation (Transform) value of the parent (parented). These values are also referred to as local coordinates (the local coordinate)

So. The coordinates that are set on the U3d interface are their local coordinates.

Convert small icon Toggle (Transform Gizmo Toggles)--affects the scene view to display the icon only for easy operation when rotating and moving the position. Pivot Center Point is the center point of the parent object itself ...  Center in the parent object's central point of the entire container ... Global is the universal coordinate system ... Local is a native coordinate system (after rotation, the coordinate direction is changed)

    1. World Space: We add objects (such as Cube) to the scene, and they are all displayed in world coordinates in the scene. The location coordinates can be obtained by the transform.position.
    2. Screen Space: defined in pixels, in the lower-left corner of the screen (0,0), the upper-right corner (Screen.width,screen.height), and the position of z is measured in the camera's world unit. Note: The mouse position coordinates belong to the screen coordinates, Input.mouseposition can obtain the position coordinates, the finger touch screen is also the screen coordinates, Input.gettouch (0). Position can get a single finger to touch the screen coordinates.

    3. ViewPort Space (viewport coordinates): viewport coordinates are standard and relative to the camera. The lower-left corner of the camera is (0,0), the upper-right corner is (the) point, and the position of z is measured in the camera's world unit. (use not much, anyway I did not use ~ hehe ~)

    4. Draw the coordinate system of the GUI interface: This coordinate system is similar to the screen coordinate system, which is different from the upper-left corner of the screen (0,0) and the lower-right corner (screen.width,screen.height).

  • World coordinates → screen coordinates: camera. Worldtoscreenpoint (transform.position) so that you can convert world coordinates to screen coordinates. Where camera is the camera object in the scene.

  • screen coordinates → viewport coordinates: camera. Screentoviewportpoint (Input.gettouch (0). position) so that you can convert screen coordinates to viewport coordinates. Where camera is the camera object in the scene.

  • viewport coordinates → screen coordinates: camera. Viewporttoscreenpoint ();

  • viewport coordinates → World coordinates: camera. Viewporttoworldpoint ();
  • Case study draw a picture on the location of the mouse click (about drawing the relationship between the GUI interface coordinate system and the screen coordinate system).[CSharp]View Plaincopy
    1. Using Unityengine;
    2. using System.Collections;
    3. public class Test:monobehaviour {
    4. //Picture
    5. Public Texture img;
    6. //store position coordinates of mouse
    7. private Vector2 Pos;
    8. void Ongui ()
    9. {
    10. //left mouse click to get the current mouse position
    11. if (Input.getmousebutton (0))
    12. {
    13. pos = input.mouseposition;
    14. }
    15. //Draw pictures
    16. Gui.         Drawtexture (new Rect (POS.X,SCREEN.HEIGHT-POS.Y,100,100), IMG);
    17. }
    18. }
  • Case 2--coordinate display and coordinate transformation (this is the touch aspect.) If you don't have a touchscreen, then remove that if!)[CSharp]View Plaincopy
    1. Using Unityengine;
    2. Using System.Collections;
    3. Public class Test:monobehaviour {
    4. //Scene of the camera, drag and drop in
    5. Public camera camera;
    6. //Scene of the object
    7. private Gameobject obj;
    8. void Start ()
    9. {
    10. //Initialize
    11. obj = Gameobject.find ("Plane");
    12. }
    13. void Update ()
    14. {
    15. //have touch
    16. if (Input.touchcount > 0)
    17. {
    18. Print ("World coordinates" + obj.transform.position);
    19. Print ("screen coordinates" + input.gettouch (0). position);
    20. Print (world coordinates → screen coordinates + camera.                    Worldtoscreenpoint (obj.transform.position));
    21. Print (screen coordinates → viewport coordinates + camera.                   Screentoviewportpoint (Input.gettouch (0). position));
    22. Print (world coordinates → viewport coordinates + camera.               Worldtoviewportpoint (obj.transform.position));
    23. }
    24. }
    25. }

Coordinate systems in the U3D

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.