c# - AR Foundation - 在屏幕上放置 2 次触控的预制件
问题描述
我正在为建筑行业开发增强现实应用程序,需要以 1:1 的比例放置模型。我知道如何一键放置,但我想知道是否可以设置 2 个点来锚定我的模型。
提前致谢!!!
解决方案
您可以使用if (Input.touchCount == 1)
(同时)检测不止一个手指轻敲。然后,您可以根据两指触摸放置对象。
// 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)
);
推荐阅读
- r - R- merging two data sets within time duration/intervals
- javascript - 使用javascript替换文本中的关键字
- php - 从 SQL for PHP 网页获取列名
- r - 在更大的 data.table 中处理分组的 data.tables
- flutter - 无法从 Cloud Firestore 归档处于初始状态的单个数据
- node.js - 尝试在 Cipher.update 中添加处于不受支持状态的数据
- android - 如何使用opencv检测白色背景上的白皮书
- php - Laravel - 从表单输入设置会话
- git - 推到分离的头上,没有显示我的推或提交
- sql-server - 存储过程、视图和表的访问权限(sql server)