How to get Ngui objects on top of a 3D model

Source: Internet
Author: User

Suppose there are two cameras in the scene, one is a Ngui camera and the other is a projection camera.

The projection camera looks at the 3D model, depth is larger than the Ngui camera, and the Clear flags set depth only.

Now you want to clip the 3D model between the two Ngui controls.

Try it: Set the depth and set the Rendererqueue to no use.

Have no, had to put to 3D model above the Uisprite also use 3D camera to see forget.

Now the question is, how to let the original position in the Ngui has been adjusted to the size of the thing, when it is viewed by a 3D camera is still the same?

If there is a Ngui object Msprite, Ngui's camera is camera2d, and the 3D camera is camera3d.

Note: The msprite position has been adjusted in Ngui, but it is behind the 3D model.

Get the screen coordinates of Msprite first
Screenpos = Camera2d.worldoscreenpoint (mSprite.transform.position);
Calculate the distance from the 3D camera
float distance = 1.0f/mathf.tan (Camera3d.fieldofview * 0.5f * Mathf.deg2rad);
The distance between the Msprite and the 3D camera is based on the screen coordinates of the msprite. To figure out where msprite should be.

Vector3 pos = m_3dcamera.screentoworldpoint (New Vector3 (Screenpos. x, Screenpos. Y, distance));
MSprite.transform.position = pos;

  

How to get Ngui objects on top of a 3D model

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.