Home > other >  Rookie sister for help! Unity3D the coordinates of the problem, why different pixels to world coordi
Rookie sister for help! Unity3D the coordinates of the problem, why different pixels to world coordi

Time:09-17

Background:
In android application development AR (combined with qualcomm), camera yes the projection is orthographic mode, calculate according to the size 1920 * 1080 size is 5.4 (don't know this information is useful, I shall be written)

I the debug information is as follows:
DebugConsole. Log (" 0 f (0.0 f, f 0.0, 0.0) : "+ ca. ScreenToWorldPoint (new Vector3 (0.0 f, f 0.0, 0.0 f)));
DebugConsole. Log (" 1 (10.0 f, f 0.0, 0.0 f) : "+ ca. ScreenToWorldPoint (new Vector3 (10.0 f, f 0.0, 0.0 f)));
DebugConsole. Log (2 "(0.0 0.0 f, 10.0 f, f) :" + ca. ScreenToWorldPoint (new Vector3 (0.0 f, f 10.0, 0.0 f)));
DebugConsole. Log (" 3 (0.0 f, f 0.0, 10.0 f) : "+ ca. ScreenToWorldPoint (new Vector3 (0.0 f, f 0.0, 10.0 f)));

Output:
0 (0.0 f, f, 0.0 0.0 f) : (18.8, 223.4, 28.0)
1 (10.0 f, f, 0.0 0.0 f) : (18.8, 223.4, 28.0)
2 (0.0 f, f, 10.0 0.0 f) : (18.8, 223.4, 28.0)
3 (0.0 f, f, 0.0 10.0 f) : (13.9, 214.2, 21.9)

Can see 0,1,2,3 is different pixels (no mount object), but the point 1, 2, 3 after ScreenToWorldPoint output result is the same, is this why?



Although contact unity for a while, but still has a lot of all don't know, beset by the question for a long time,
Thank you for help and see what's the problem, very thank you!!!!!!!!!!

CodePudding user response:

Their top first, in the hope that more people can see

CodePudding user response:

You change the camera to try,

CodePudding user response:

He that is related to the position of the camera, meaning is to convert the coordinates of the screen to world coordinates, you how to screen is 1920 * 1080
You can set a vector3 pos=new vector3 (960540, Z="casual, is the object to the distance of the camera")
Then create a cube,
Runtime execution
Cube. The transform. The position=ca. ScreenToWorldPoint (pos);
You can see your cube at the center of the screen!

CodePudding user response:

As for your 0,1,2,3 are different pixels (no mount object), but the point 1, 2, 3 after ScreenToWorldPoint output result is the same,
Should be converted accuracy problem, you can see only one decimal point after transformation, system to do the processing precision, two pixels are too small in three-dimensional space in the same position

CodePudding user response:

With the 4th floor, I also tried to be accuracy, and could you test the projection of the camera is not orthographic mode, I just use your code in empty scene test, if not orthographic mode, the first three pixel coordinates is the same, if converted to orthographic mode, pixels have a fraction of deviation.

CodePudding user response:

Related to the position of the camera, you need to use the code realization of coordinate transformation

CodePudding user response:

Conversion process influence factors include:

1, the real influence of the Z value is set, different Z value represents different projection plane in the observation system, observe the coordinate system is a pyramid, so the computing time is related to and the file of the Angle of view,

2, the ratio of high to width of Screen when the canvas and set values and perference pixels per unit has a relationship (i.e. resolution, but here is the unit of pixel/m (units) of the unity),
UGUI can be observed directly took the Position is the location of the 3 d coordinates, can put the objects on the Canvas as Z coordinate of 0 3 d objects;
To compute the position of the UI, you should consider two factors 1 and 2,

CodePudding user response:

RectTransformUtility. ScreenPointToLocalPointInRectangle (canvas. GetComponent (), the transform. The position, null, out vector2);
The Debug Log (the transform. The position);
The Debug Log (Camera. Main. WorldToScreenPoint (transform. The position));
The Debug Log (vector2);
Card. AnchoredPosition=vector2;
I am so easy to use, used in the Screen position of the UI, the vector2 coordinates based on the center of the Canvas in the form of (0, 0), specific set according to the transform of anchor point set;

CodePudding user response:

The first three output are the camera position, when the camera Perspective model (the default camera is here on the Z axis), from a distance from the camera to zero distance, cut out of the plane is a point, namely the position of the camera,
  • Related