Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

c# - AR Foundation - Place a prefab with 2 touches on screen

I'm developing an augmented reality app for construction industry and need to place a model in 1:1 scale. I know how to place with one touch, but I would like to know if it is possible to set 2 points to anchor my model.

Thanks in advance!!!

question from:https://stackoverflow.com/questions/65903342/ar-foundation-place-a-prefab-with-2-touches-on-screen

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use if (Input.touchCount == 1) to detect more than just one finger tap (at the same time). Then you can place your object based on the two-finger touch.

            // Store both touches.
            Touch touchZero = Input.GetTouch(0);
            Touch touchOne = Input.GetTouch(1);
            // Calculate previous position
            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
            // Find the magnitude of the vector (the distance) between the touches in each frame.
            float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
            // Find the difference in the distances between each frame.
            float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
            float pinchAmount = deltaMagnitudeDiff * 0.02f * Time.deltaTime;
            spawnedObject.transform.localScale -= new Vector3(pinchAmount, pinchAmount, pinchAmount);
            // Clamp scale
            float Min = 0.005f;
            float Max = 3f;
            spawnedObject.transform.localScale = new Vector3(
                Mathf.Clamp(spawnedObject.transform.localScale.x, Min, Max),
                Mathf.Clamp(spawnedObject.transform.localScale.y, Min, Max),
                Mathf.Clamp(spawnedObject.transform.localScale.z, Min, Max)
            );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...